First commit
This commit is contained in:
15
hGameTest/node_modules/sockjs/examples/echo/README.md
generated
vendored
Normal file
15
hGameTest/node_modules/sockjs/examples/echo/README.md
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
SockJS-node Echo example
|
||||
========================
|
||||
|
||||
To run this example, first install dependencies:
|
||||
|
||||
npm install
|
||||
|
||||
And run a server:
|
||||
|
||||
node server.js
|
||||
|
||||
|
||||
That will spawn an http server at http://127.0.0.1:9999/ which will
|
||||
serve both html (served from the current directory) and also SockJS
|
||||
server (under the [/echo](http://127.0.0.1:9999/echo) path).
|
||||
71
hGameTest/node_modules/sockjs/examples/echo/index.html
generated
vendored
Normal file
71
hGameTest/node_modules/sockjs/examples/echo/index.html
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
<!doctype html>
|
||||
<html><head>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||
<script src="http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"></script>
|
||||
<style>
|
||||
.box {
|
||||
width: 300px;
|
||||
float: left;
|
||||
margin: 0 20px 0 20px;
|
||||
}
|
||||
.box div, .box input {
|
||||
border: 1px solid;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
padding: 0px;
|
||||
margin: 5px;
|
||||
}
|
||||
.box div {
|
||||
border-color: grey;
|
||||
height: 300px;
|
||||
overflow: auto;
|
||||
}
|
||||
.box input {
|
||||
height: 30px;
|
||||
}
|
||||
h1 {
|
||||
margin-left: 30px;
|
||||
}
|
||||
body {
|
||||
background-color: #F0F0F0;
|
||||
font-family: "Arial";
|
||||
}
|
||||
</style>
|
||||
</head><body lang="en">
|
||||
<h1>SockJS Echo example</h1>
|
||||
|
||||
<div id="first" class="box">
|
||||
<div></div>
|
||||
<form><input autocomplete="off" value="Type here..."></input></form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var sockjs_url = '/echo';
|
||||
var sockjs = new SockJS(sockjs_url);
|
||||
$('#first input').focus();
|
||||
|
||||
var div = $('#first div');
|
||||
var inp = $('#first input');
|
||||
var form = $('#first form');
|
||||
|
||||
var print = function(m, p) {
|
||||
p = (p === undefined) ? '' : JSON.stringify(p);
|
||||
div.append($("<code>").text(m + ' ' + p));
|
||||
div.append($("<br>"));
|
||||
div.scrollTop(div.scrollTop()+10000);
|
||||
};
|
||||
|
||||
sockjs.onopen = function() {print('[*] open', sockjs.protocol);};
|
||||
sockjs.onmessage = function(e) {print('[.] message', e.data);};
|
||||
sockjs.onclose = function() {print('[*] close');};
|
||||
|
||||
form.submit(function() {
|
||||
print('[ ] sending', inp.val());
|
||||
sockjs.send(inp.val());
|
||||
inp.val('');
|
||||
return false;
|
||||
});
|
||||
|
||||
</script>
|
||||
</body></html>
|
||||
8
hGameTest/node_modules/sockjs/examples/echo/package.json
generated
vendored
Normal file
8
hGameTest/node_modules/sockjs/examples/echo/package.json
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "sockjs-echo",
|
||||
"version": "0.0.0-unreleasable",
|
||||
"dependencies": {
|
||||
"node-static": "0.5.9",
|
||||
"sockjs": "*"
|
||||
}
|
||||
}
|
||||
30
hGameTest/node_modules/sockjs/examples/echo/server.js
generated
vendored
Normal file
30
hGameTest/node_modules/sockjs/examples/echo/server.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
var http = require('http');
|
||||
var sockjs = require('sockjs');
|
||||
var node_static = require('node-static');
|
||||
|
||||
// 1. Echo sockjs server
|
||||
var sockjs_opts = {sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"};
|
||||
|
||||
var sockjs_echo = sockjs.createServer(sockjs_opts);
|
||||
sockjs_echo.on('connection', function(conn) {
|
||||
conn.on('data', function(message) {
|
||||
conn.write(message);
|
||||
});
|
||||
});
|
||||
|
||||
// 2. Static files server
|
||||
var static_directory = new node_static.Server(__dirname);
|
||||
|
||||
// 3. Usual http stuff
|
||||
var server = http.createServer();
|
||||
server.addListener('request', function(req, res) {
|
||||
static_directory.serve(req, res);
|
||||
});
|
||||
server.addListener('upgrade', function(req,res){
|
||||
res.end();
|
||||
});
|
||||
|
||||
sockjs_echo.installHandlers(server, {prefix:'/echo'});
|
||||
|
||||
console.log(' [*] Listening on 0.0.0.0:9999' );
|
||||
server.listen(9999, '0.0.0.0');
|
||||
71
hGameTest/node_modules/sockjs/examples/express-3.x/index.html
generated
vendored
Normal file
71
hGameTest/node_modules/sockjs/examples/express-3.x/index.html
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
<!doctype html>
|
||||
<html><head>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||
<script src="http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"></script>
|
||||
<style>
|
||||
.box {
|
||||
width: 300px;
|
||||
float: left;
|
||||
margin: 0 20px 0 20px;
|
||||
}
|
||||
.box div, .box input {
|
||||
border: 1px solid;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
padding: 0px;
|
||||
margin: 5px;
|
||||
}
|
||||
.box div {
|
||||
border-color: grey;
|
||||
height: 300px;
|
||||
overflow: auto;
|
||||
}
|
||||
.box input {
|
||||
height: 30px;
|
||||
}
|
||||
h1 {
|
||||
margin-left: 30px;
|
||||
}
|
||||
body {
|
||||
background-color: #F0F0F0;
|
||||
font-family: "Arial";
|
||||
}
|
||||
</style>
|
||||
</head><body lang="en">
|
||||
<h1>SockJS Express example</h1>
|
||||
|
||||
<div id="first" class="box">
|
||||
<div></div>
|
||||
<form><input autocomplete="off" value="Type here..."></input></form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var sockjs_url = '/echo';
|
||||
var sockjs = new SockJS(sockjs_url);
|
||||
$('#first input').focus();
|
||||
|
||||
var div = $('#first div');
|
||||
var inp = $('#first input');
|
||||
var form = $('#first form');
|
||||
|
||||
var print = function(m, p) {
|
||||
p = (p === undefined) ? '' : JSON.stringify(p);
|
||||
div.append($("<code>").text(m + ' ' + p));
|
||||
div.append($("<br>"));
|
||||
div.scrollTop(div.scrollTop()+10000);
|
||||
};
|
||||
|
||||
sockjs.onopen = function() {print('[*] open', sockjs.protocol);};
|
||||
sockjs.onmessage = function(e) {print('[.] message', e.data);};
|
||||
sockjs.onclose = function() {print('[*] close');};
|
||||
|
||||
form.submit(function() {
|
||||
print('[ ] sending', inp.val());
|
||||
sockjs.send(inp.val());
|
||||
inp.val('');
|
||||
return false;
|
||||
});
|
||||
|
||||
</script>
|
||||
</body></html>
|
||||
8
hGameTest/node_modules/sockjs/examples/express-3.x/package.json
generated
vendored
Normal file
8
hGameTest/node_modules/sockjs/examples/express-3.x/package.json
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "sockjs-express",
|
||||
"version": "0.0.0-unreleasable",
|
||||
"dependencies": {
|
||||
"express": "~3*",
|
||||
"sockjs": "*"
|
||||
}
|
||||
}
|
||||
26
hGameTest/node_modules/sockjs/examples/express-3.x/server.js
generated
vendored
Normal file
26
hGameTest/node_modules/sockjs/examples/express-3.x/server.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
var express = require('express');
|
||||
var sockjs = require('sockjs');
|
||||
var http = require('http');
|
||||
|
||||
// 1. Echo sockjs server
|
||||
var sockjs_opts = {sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"};
|
||||
|
||||
var sockjs_echo = sockjs.createServer(sockjs_opts);
|
||||
sockjs_echo.on('connection', function(conn) {
|
||||
conn.on('data', function(message) {
|
||||
conn.write(message);
|
||||
});
|
||||
});
|
||||
|
||||
// 2. Express server
|
||||
var app = express(); /* express.createServer will not work here */
|
||||
var server = http.createServer(app);
|
||||
|
||||
sockjs_echo.installHandlers(server, {prefix:'/echo'});
|
||||
|
||||
console.log(' [*] Listening on 0.0.0.0:9999' );
|
||||
server.listen(9999, '0.0.0.0');
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
res.sendfile(__dirname + '/index.html');
|
||||
});
|
||||
71
hGameTest/node_modules/sockjs/examples/express/index.html
generated
vendored
Normal file
71
hGameTest/node_modules/sockjs/examples/express/index.html
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
<!doctype html>
|
||||
<html><head>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||
<script src="http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"></script>
|
||||
<style>
|
||||
.box {
|
||||
width: 300px;
|
||||
float: left;
|
||||
margin: 0 20px 0 20px;
|
||||
}
|
||||
.box div, .box input {
|
||||
border: 1px solid;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
padding: 0px;
|
||||
margin: 5px;
|
||||
}
|
||||
.box div {
|
||||
border-color: grey;
|
||||
height: 300px;
|
||||
overflow: auto;
|
||||
}
|
||||
.box input {
|
||||
height: 30px;
|
||||
}
|
||||
h1 {
|
||||
margin-left: 30px;
|
||||
}
|
||||
body {
|
||||
background-color: #F0F0F0;
|
||||
font-family: "Arial";
|
||||
}
|
||||
</style>
|
||||
</head><body lang="en">
|
||||
<h1>SockJS Express example</h1>
|
||||
|
||||
<div id="first" class="box">
|
||||
<div></div>
|
||||
<form><input autocomplete="off" value="Type here..."></input></form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var sockjs_url = '/echo';
|
||||
var sockjs = new SockJS(sockjs_url);
|
||||
$('#first input').focus();
|
||||
|
||||
var div = $('#first div');
|
||||
var inp = $('#first input');
|
||||
var form = $('#first form');
|
||||
|
||||
var print = function(m, p) {
|
||||
p = (p === undefined) ? '' : JSON.stringify(p);
|
||||
div.append($("<code>").text(m + ' ' + p));
|
||||
div.append($("<br>"));
|
||||
div.scrollTop(div.scrollTop()+10000);
|
||||
};
|
||||
|
||||
sockjs.onopen = function() {print('[*] open', sockjs.protocol);};
|
||||
sockjs.onmessage = function(e) {print('[.] message', e.data);};
|
||||
sockjs.onclose = function() {print('[*] close');};
|
||||
|
||||
form.submit(function() {
|
||||
print('[ ] sending', inp.val());
|
||||
sockjs.send(inp.val());
|
||||
inp.val('');
|
||||
return false;
|
||||
});
|
||||
|
||||
</script>
|
||||
</body></html>
|
||||
8
hGameTest/node_modules/sockjs/examples/express/package.json
generated
vendored
Normal file
8
hGameTest/node_modules/sockjs/examples/express/package.json
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "sockjs-express",
|
||||
"version": "0.0.0-unreleasable",
|
||||
"dependencies": {
|
||||
"express": "<3",
|
||||
"sockjs": "*"
|
||||
}
|
||||
}
|
||||
23
hGameTest/node_modules/sockjs/examples/express/server.js
generated
vendored
Normal file
23
hGameTest/node_modules/sockjs/examples/express/server.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
var express = require('express');
|
||||
var sockjs = require('sockjs');
|
||||
|
||||
// 1. Echo sockjs server
|
||||
var sockjs_opts = {sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"};
|
||||
|
||||
var sockjs_echo = sockjs.createServer(sockjs_opts);
|
||||
sockjs_echo.on('connection', function(conn) {
|
||||
conn.on('data', function(message) {
|
||||
conn.write(message);
|
||||
});
|
||||
});
|
||||
|
||||
// 2. Express server
|
||||
var app = express.createServer();
|
||||
sockjs_echo.installHandlers(app, {prefix:'/echo'});
|
||||
|
||||
console.log(' [*] Listening on 0.0.0.0:9999' );
|
||||
app.listen(9999, '0.0.0.0');
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
res.sendfile(__dirname + '/index.html');
|
||||
});
|
||||
71
hGameTest/node_modules/sockjs/examples/hapi/html/index.html
generated
vendored
Normal file
71
hGameTest/node_modules/sockjs/examples/hapi/html/index.html
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
<!doctype html>
|
||||
<html><head>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||
<script src="http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"></script>
|
||||
<style>
|
||||
.box {
|
||||
width: 300px;
|
||||
float: left;
|
||||
margin: 0 20px 0 20px;
|
||||
}
|
||||
.box div, .box input {
|
||||
border: 1px solid;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
padding: 0px;
|
||||
margin: 5px;
|
||||
}
|
||||
.box div {
|
||||
border-color: grey;
|
||||
height: 300px;
|
||||
overflow: auto;
|
||||
}
|
||||
.box input {
|
||||
height: 30px;
|
||||
}
|
||||
h1 {
|
||||
margin-left: 30px;
|
||||
}
|
||||
body {
|
||||
background-color: #F0F0F0;
|
||||
font-family: "Arial";
|
||||
}
|
||||
</style>
|
||||
</head><body lang="en">
|
||||
<h1>SockJS Echo example</h1>
|
||||
|
||||
<div id="first" class="box">
|
||||
<div></div>
|
||||
<form><input autocomplete="off" value="Type here..."></input></form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var sockjs_url = '/echo';
|
||||
var sockjs = new SockJS(sockjs_url);
|
||||
$('#first input').focus();
|
||||
|
||||
var div = $('#first div');
|
||||
var inp = $('#first input');
|
||||
var form = $('#first form');
|
||||
|
||||
var print = function(m, p) {
|
||||
p = (p === undefined) ? '' : JSON.stringify(p);
|
||||
div.append($("<code>").text(m + ' ' + p));
|
||||
div.append($("<br>"));
|
||||
div.scrollTop(div.scrollTop()+10000);
|
||||
};
|
||||
|
||||
sockjs.onopen = function() {print('[*] open', sockjs.protocol);};
|
||||
sockjs.onmessage = function(e) {print('[.] message', e.data);};
|
||||
sockjs.onclose = function() {print('[*] close');};
|
||||
|
||||
form.submit(function() {
|
||||
print('[ ] sending', inp.val());
|
||||
sockjs.send(inp.val());
|
||||
inp.val('');
|
||||
return false;
|
||||
});
|
||||
|
||||
</script>
|
||||
</body></html>
|
||||
9
hGameTest/node_modules/sockjs/examples/hapi/package.json
generated
vendored
Normal file
9
hGameTest/node_modules/sockjs/examples/hapi/package.json
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "sockjs-hapi",
|
||||
"version": "0.0.0-unreleasable",
|
||||
"dependencies": {
|
||||
"hapi": "15.x.x",
|
||||
"inert": "4.x.x",
|
||||
"sockjs": "*"
|
||||
}
|
||||
}
|
||||
42
hGameTest/node_modules/sockjs/examples/hapi/server.js
generated
vendored
Normal file
42
hGameTest/node_modules/sockjs/examples/hapi/server.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Created by Tony on 11/1/13.
|
||||
*/
|
||||
var http = require('http');
|
||||
var sockjs = require('sockjs');
|
||||
var Hapi = require('hapi');
|
||||
|
||||
// 1. Echo sockjs server
|
||||
var sockjs_opts = {
|
||||
sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"
|
||||
};
|
||||
|
||||
var sockjs_echo = sockjs.createServer(sockjs_opts);
|
||||
sockjs_echo.on('connection', function(conn) {
|
||||
conn.on('data', function(message) {
|
||||
conn.write(message);
|
||||
});
|
||||
});
|
||||
|
||||
// Create a server and set port (default host 0.0.0.0)
|
||||
var hapi_server = new Hapi.Server();
|
||||
hapi_server.connection({
|
||||
port: 9999
|
||||
});
|
||||
|
||||
hapi_server.register(require('inert'), (err) => {
|
||||
hapi_server.route({
|
||||
method: 'GET',
|
||||
path: '/{path*}',
|
||||
handler: function(request, reply) {
|
||||
reply.file('./html/index.html');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//hapi_server.listener is the http listener hapi uses
|
||||
sockjs_echo.installHandlers(hapi_server.listener, {
|
||||
prefix: '/echo'
|
||||
});
|
||||
|
||||
console.log(' [*] Listening on 0.0.0.0:9999');
|
||||
hapi_server.start();
|
||||
42
hGameTest/node_modules/sockjs/examples/haproxy.cfg
generated
vendored
Normal file
42
hGameTest/node_modules/sockjs/examples/haproxy.cfg
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
# Requires recent Haproxy to work with websockets (for example 1.4.16).
|
||||
defaults
|
||||
mode http
|
||||
# Set timeouts to your needs
|
||||
timeout client 5s
|
||||
timeout connect 5s
|
||||
timeout server 5s
|
||||
|
||||
frontend all 0.0.0.0:8888
|
||||
mode http
|
||||
timeout client 120s
|
||||
|
||||
option forwardfor
|
||||
# Fake connection:close, required in this setup.
|
||||
option http-server-close
|
||||
option http-pretend-keepalive
|
||||
|
||||
acl is_sockjs path_beg /echo /broadcast /close
|
||||
acl is_stats path_beg /stats
|
||||
|
||||
use_backend sockjs if is_sockjs
|
||||
use_backend stats if is_stats
|
||||
default_backend static
|
||||
|
||||
|
||||
backend sockjs
|
||||
# Load-balance according to hash created from first two
|
||||
# directories in url path. For example requests going to /1/
|
||||
# should be handled by single server (assuming resource prefix is
|
||||
# one-level deep, like "/echo").
|
||||
balance uri depth 2
|
||||
timeout server 120s
|
||||
server srv_sockjs1 127.0.0.1:9999
|
||||
# server srv_sockjs2 127.0.0.1:9998
|
||||
|
||||
backend static
|
||||
balance roundrobin
|
||||
server srv_static 127.0.0.1:8000
|
||||
|
||||
backend stats
|
||||
stats uri /stats
|
||||
stats enable
|
||||
71
hGameTest/node_modules/sockjs/examples/koa/index.html
generated
vendored
Normal file
71
hGameTest/node_modules/sockjs/examples/koa/index.html
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
<!doctype html>
|
||||
<html><head>
|
||||
<script src="//cdn.jsdelivr.net/jquery/2.1.4/jquery.min.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"></script>
|
||||
<style>
|
||||
.box {
|
||||
width: 300px;
|
||||
float: left;
|
||||
margin: 0 20px 0 20px;
|
||||
}
|
||||
.box div, .box input {
|
||||
border: 1px solid;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
padding: 0px;
|
||||
margin: 5px;
|
||||
}
|
||||
.box div {
|
||||
border-color: grey;
|
||||
height: 300px;
|
||||
overflow: auto;
|
||||
}
|
||||
.box input {
|
||||
height: 30px;
|
||||
}
|
||||
h1 {
|
||||
margin-left: 30px;
|
||||
}
|
||||
body {
|
||||
background-color: #F0F0F0;
|
||||
font-family: "Arial";
|
||||
}
|
||||
</style>
|
||||
</head><body lang="en">
|
||||
<h1>SockJS Express example</h1>
|
||||
|
||||
<div id="first" class="box">
|
||||
<div></div>
|
||||
<form><input autocomplete="off" value="Type here..."></input></form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var sockjs_url = '/echo';
|
||||
var sockjs = new SockJS(sockjs_url);
|
||||
$('#first input').focus();
|
||||
|
||||
var div = $('#first div');
|
||||
var inp = $('#first input');
|
||||
var form = $('#first form');
|
||||
|
||||
var print = function(m, p) {
|
||||
p = (p === undefined) ? '' : JSON.stringify(p);
|
||||
div.append($("<code>").text(m + ' ' + p));
|
||||
div.append($("<br>"));
|
||||
div.scrollTop(div.scrollTop()+10000);
|
||||
};
|
||||
|
||||
sockjs.onopen = function() {print('[*] open', sockjs.protocol);};
|
||||
sockjs.onmessage = function(e) {print('[.] message', e.data);};
|
||||
sockjs.onclose = function() {print('[*] close');};
|
||||
|
||||
form.submit(function() {
|
||||
print('[ ] sending', inp.val());
|
||||
sockjs.send(inp.val());
|
||||
inp.val('');
|
||||
return false;
|
||||
});
|
||||
|
||||
</script>
|
||||
</body></html>
|
||||
8
hGameTest/node_modules/sockjs/examples/koa/package.json
generated
vendored
Normal file
8
hGameTest/node_modules/sockjs/examples/koa/package.json
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "sockjs-koa",
|
||||
"version": "0.0.0-unreleasable",
|
||||
"dependencies": {
|
||||
"koa": "^0.21.0",
|
||||
"sockjs": "*"
|
||||
}
|
||||
}
|
||||
29
hGameTest/node_modules/sockjs/examples/koa/server.js
generated
vendored
Normal file
29
hGameTest/node_modules/sockjs/examples/koa/server.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
var koa = require('koa');
|
||||
var sockjs = require('sockjs');
|
||||
var http = require('http');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
// 1. Echo sockjs server
|
||||
var sockjs_opts = {sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"};
|
||||
var sockjs_echo = sockjs.createServer(sockjs_opts);
|
||||
sockjs_echo.on('connection', function(conn) {
|
||||
conn.on('data', function(message) {
|
||||
conn.write(message);
|
||||
});
|
||||
});
|
||||
|
||||
// 2. koa server
|
||||
var app = koa();
|
||||
|
||||
app.use(function *() {
|
||||
var filePath = __dirname + '/index.html';
|
||||
this.type = path.extname(filePath);
|
||||
this.body = fs.createReadStream(filePath);
|
||||
});
|
||||
|
||||
var server = http.createServer(app.callback());
|
||||
sockjs_echo.installHandlers(server, {prefix:'/echo'});
|
||||
|
||||
server.listen(9999, '0.0.0.0');
|
||||
console.log(' [*] Listening on 0.0.0.0:9999' );
|
||||
26
hGameTest/node_modules/sockjs/examples/multiplex/README.md
generated
vendored
Normal file
26
hGameTest/node_modules/sockjs/examples/multiplex/README.md
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
WebSocket-multiplex SockJS example
|
||||
==================================
|
||||
|
||||
This example is a copy of example from
|
||||
[websocket-multiplex](https://github.com/sockjs/websocket-multiplex/)
|
||||
project:
|
||||
|
||||
* https://github.com/sockjs/websocket-multiplex/
|
||||
|
||||
|
||||
To run this example, first install dependencies:
|
||||
|
||||
npm install
|
||||
|
||||
And run a server:
|
||||
|
||||
node server.js
|
||||
|
||||
|
||||
That will spawn an http server at http://127.0.0.1:9999/ which will
|
||||
serve both html (served from the current directory) and also SockJS
|
||||
service (under the [/multiplex](http://127.0.0.1:9999/multiplex)
|
||||
path).
|
||||
|
||||
With that set up, WebSocket-multiplex is able to push three virtual
|
||||
connections over a single SockJS connection. See the code for details.
|
||||
96
hGameTest/node_modules/sockjs/examples/multiplex/index.html
generated
vendored
Normal file
96
hGameTest/node_modules/sockjs/examples/multiplex/index.html
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
<!doctype html>
|
||||
<html><head>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||
<script src="http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"></script>
|
||||
<script src="http://cdn.sockjs.org/websocket-multiplex-0.1.js"></script>
|
||||
<style>
|
||||
.box {
|
||||
width: 300px;
|
||||
float: left;
|
||||
margin: 0 20px 0 20px;
|
||||
}
|
||||
.box div, .box input {
|
||||
border: 1px solid;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
padding: 0px;
|
||||
margin: 5px;
|
||||
}
|
||||
.box div {
|
||||
border-color: grey;
|
||||
height: 300px;
|
||||
overflow: auto;
|
||||
}
|
||||
.box input {
|
||||
height: 30px;
|
||||
}
|
||||
h1 {
|
||||
margin-left: 75px;
|
||||
}
|
||||
body {
|
||||
background-color: #F0F0F0;
|
||||
font-family: "Arial";
|
||||
}
|
||||
</style>
|
||||
</head><body lang="en">
|
||||
<h1>SockJS Multiplex example</h1>
|
||||
|
||||
<div id="first" class="box">
|
||||
<div></div>
|
||||
<form><input autocomplete="off" value="Type here..."></input></form>
|
||||
</div>
|
||||
|
||||
<div id="second" class="box">
|
||||
<div></div>
|
||||
<form><input autocomplete="off"></input></form>
|
||||
</div>
|
||||
|
||||
<div id="third" class="box">
|
||||
<div></div>
|
||||
<form><input autocomplete="off"></input></form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Pipe - convenience wrapper to present data received from an
|
||||
// object supporting WebSocket API in an html element. And the other
|
||||
// direction: data typed into an input box shall be sent back.
|
||||
var pipe = function(ws, el_name) {
|
||||
var div = $(el_name + ' div');
|
||||
var inp = $(el_name + ' input');
|
||||
var form = $(el_name + ' form');
|
||||
|
||||
var print = function(m, p) {
|
||||
p = (p === undefined) ? '' : JSON.stringify(p);
|
||||
div.append($("<code>").text(m + ' ' + p));
|
||||
div.append($("<br>"));
|
||||
div.scrollTop(div.scrollTop() + 10000);
|
||||
};
|
||||
|
||||
ws.onopen = function() {print('[*] open', ws.protocol);};
|
||||
ws.onmessage = function(e) {print('[.] message', e.data);};
|
||||
ws.onclose = function() {print('[*] close');};
|
||||
|
||||
form.submit(function() {
|
||||
print('[ ] sending', inp.val());
|
||||
ws.send(inp.val());
|
||||
inp.val('');
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
var sockjs_url = '/multiplex';
|
||||
var sockjs = new SockJS(sockjs_url);
|
||||
|
||||
var multiplexer = new WebSocketMultiplex(sockjs);
|
||||
var ann = multiplexer.channel('ann');
|
||||
var bob = multiplexer.channel('bob');
|
||||
var carl = multiplexer.channel('carl');
|
||||
|
||||
pipe(ann, '#first');
|
||||
pipe(bob, '#second');
|
||||
pipe(carl, '#third');
|
||||
|
||||
$('#first input').focus();
|
||||
</script>
|
||||
</body></html>
|
||||
9
hGameTest/node_modules/sockjs/examples/multiplex/package.json
generated
vendored
Normal file
9
hGameTest/node_modules/sockjs/examples/multiplex/package.json
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "sockjs-multiplex",
|
||||
"version": "0.0.0-unreleasable",
|
||||
"dependencies": {
|
||||
"express": "2.5.8",
|
||||
"sockjs": "*",
|
||||
"websocket-multiplex" : "0.1.x"
|
||||
}
|
||||
}
|
||||
52
hGameTest/node_modules/sockjs/examples/multiplex/server.js
generated
vendored
Normal file
52
hGameTest/node_modules/sockjs/examples/multiplex/server.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
var express = require('express');
|
||||
var sockjs = require('sockjs');
|
||||
|
||||
var websocket_multiplex = require('websocket-multiplex');
|
||||
|
||||
|
||||
// 1. Setup SockJS server
|
||||
var sockjs_opts = {sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"};
|
||||
var service = sockjs.createServer(sockjs_opts);
|
||||
|
||||
|
||||
// 2. Setup multiplexing
|
||||
var multiplexer = new websocket_multiplex.MultiplexServer(service);
|
||||
|
||||
var ann = multiplexer.registerChannel('ann');
|
||||
ann.on('connection', function(conn) {
|
||||
conn.write('Ann says hi!');
|
||||
conn.on('data', function(data) {
|
||||
conn.write('Ann nods: ' + data);
|
||||
});
|
||||
});
|
||||
|
||||
var bob = multiplexer.registerChannel('bob');
|
||||
bob.on('connection', function(conn) {
|
||||
conn.write('Bob doesn\'t agree.');
|
||||
conn.on('data', function(data) {
|
||||
conn.write('Bob says no to: ' + data);
|
||||
});
|
||||
});
|
||||
|
||||
var carl = multiplexer.registerChannel('carl');
|
||||
carl.on('connection', function(conn) {
|
||||
conn.write('Carl says goodbye!');
|
||||
// Explicitly cancel connection
|
||||
conn.end();
|
||||
});
|
||||
|
||||
|
||||
// 3. Express server
|
||||
var app = express.createServer();
|
||||
service.installHandlers(app, {prefix:'/multiplex'});
|
||||
|
||||
console.log(' [*] Listening on 0.0.0.0:9999' );
|
||||
app.listen(9999, '0.0.0.0');
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
res.sendfile(__dirname + '/index.html');
|
||||
});
|
||||
|
||||
app.get('/multiplex.js', function (req, res) {
|
||||
res.sendfile(__dirname + '/multiplex.js');
|
||||
});
|
||||
Reference in New Issue
Block a user