08-27-周三_17-09-29

This commit is contained in:
2025-08-27 17:10:05 +08:00
commit 86df397d8f
12735 changed files with 1145479 additions and 0 deletions

15
node_modules/sockjs/examples/echo/README.md generated vendored Normal file
View 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
node_modules/sockjs/examples/echo/index.html generated vendored Normal file
View 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.sockjs.org/sockjs-0.3.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
node_modules/sockjs/examples/echo/package.json generated vendored Normal file
View File

@@ -0,0 +1,8 @@
{
"name": "sockjs-echo",
"version": "0.0.0-unreleasable",
"dependencies": {
"node-static": "0.5.9",
"sockjs": "*"
}
}

30
node_modules/sockjs/examples/echo/server.js generated vendored Normal file
View 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.sockjs.org/sockjs-0.3.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
node_modules/sockjs/examples/express-3.x/index.html generated vendored Normal file
View 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.sockjs.org/sockjs-0.3.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>

View File

@@ -0,0 +1,8 @@
{
"name": "sockjs-express",
"version": "0.0.0-unreleasable",
"dependencies": {
"express": "~3*",
"sockjs": "*"
}
}

26
node_modules/sockjs/examples/express-3.x/server.js generated vendored Normal file
View 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.sockjs.org/sockjs-0.3.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
node_modules/sockjs/examples/express/index.html generated vendored Normal file
View 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.sockjs.org/sockjs-0.3.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
node_modules/sockjs/examples/express/package.json generated vendored Normal file
View File

@@ -0,0 +1,8 @@
{
"name": "sockjs-express",
"version": "0.0.0-unreleasable",
"dependencies": {
"express": "<3",
"sockjs": "*"
}
}

23
node_modules/sockjs/examples/express/server.js generated vendored Normal file
View File

@@ -0,0 +1,23 @@
var express = require('express');
var sockjs = require('sockjs');
// 1. Echo sockjs server
var sockjs_opts = {sockjs_url: "http://cdn.sockjs.org/sockjs-0.3.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');
});

42
node_modules/sockjs/examples/haproxy.cfg generated vendored Normal file
View 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

26
node_modules/sockjs/examples/multiplex/README.md generated vendored Normal file
View 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
node_modules/sockjs/examples/multiplex/index.html generated vendored Normal file
View 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.sockjs.org/sockjs-0.3.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
node_modules/sockjs/examples/multiplex/package.json generated vendored Normal file
View 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
node_modules/sockjs/examples/multiplex/server.js generated vendored Normal file
View 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.sockjs.org/sockjs-0.3.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');
});

30
node_modules/sockjs/examples/test_server/README.md generated vendored Normal file
View File

@@ -0,0 +1,30 @@
SockJS test server
==================
In order to test sockjs server implementation the server needs to
provide a standarized sockjs endpoint that will can used by various
sockjs-related tests. For example by QUnit or
[Sockjs-protocol](https://github.com/sockjs/sockjs-protocol) tests.
This small code does exactly that - runs a simple server that supports
the following SockJS services:
* `/echo`
* `/disabled_websocket_echo`
* `/cookie_needed_echo`
* `/close`
* `/ticker`
* `/amplify`
* `/broadcast`
If you just want to quickly run it:
npm install
node server.js
If you want to run do development it's recommended to run `make
test_server` from the top `sockjs-node` directory:
cd ../..
make test_server

9
node_modules/sockjs/examples/test_server/config.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
exports.config = {
server_opts: {
sockjs_url: 'http://localhost:8080/lib/sockjs.js',
websocket: true
},
port: 8081,
host: '0.0.0.0'
};

View File

@@ -0,0 +1,7 @@
{
"name": "sockjs-test-server",
"version": "0.0.0-unreleasable",
"dependencies": {
"sockjs": "*"
}
}

19
node_modules/sockjs/examples/test_server/server.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
var http = require('http');
var config = require('./config').config;
var sockjs_app = require('./sockjs_app');
var server = http.createServer();
server.addListener('request', function(req, res) {
res.setHeader('content-type', 'text/plain');
res.writeHead(404);
res.end('404 - Nothing here (via sockjs-node test_server)');
});
server.addListener('upgrade', function(req, res){
res.end();
});
sockjs_app.install(config.server_opts, server);
console.log(" [*] Listening on", config.host + ':' + config.port);
server.listen(config.port, config.host);

85
node_modules/sockjs/examples/test_server/sockjs_app.js generated vendored Normal file
View File

@@ -0,0 +1,85 @@
var sockjs = require('sockjs');
exports.install = function(opts, server) {
var sjs_echo = sockjs.createServer(opts);
sjs_echo.on('connection', function(conn) {
console.log(' [+] echo open ' + conn);
conn.on('close', function() {
console.log(' [-] echo close ' + conn);
});
conn.on('data', function(m) {
var d = JSON.stringify(m);
console.log(' [ ] echo message ' + conn,
d.slice(0,64)+
((d.length > 64) ? '...' : ''));
conn.write(m);
});
});
var sjs_close = sockjs.createServer(opts);
sjs_close.on('connection', function(conn) {
console.log(' [+] clos open ' + conn);
conn.close(3000, "Go away!");
conn.on('close', function() {
console.log(' [-] clos close ' + conn);
});
});
var sjs_ticker = sockjs.createServer(opts);
sjs_ticker.on('connection', function(conn) {
console.log(' [+] ticker open ' + conn);
var tref;
var schedule = function() {
conn.write('tick!');
tref = setTimeout(schedule, 1000);
};
tref = setTimeout(schedule, 1000);
conn.on('close', function() {
clearTimeout(tref);
console.log(' [-] ticker close ' + conn);
});
});
var broadcast = {};
var sjs_broadcast = sockjs.createServer(opts);
sjs_broadcast.on('connection', function(conn) {
console.log(' [+] broadcast open ' + conn);
broadcast[conn.id] = conn;
conn.on('close', function() {
delete broadcast[conn.id];
console.log(' [-] broadcast close' + conn);
});
conn.on('data', function(m) {
console.log(' [-] broadcast message', m);
for(var id in broadcast) {
broadcast[id].write(m);
}
});
});
var sjs_amplify = sockjs.createServer(opts);
sjs_amplify.on('connection', function(conn) {
console.log(' [+] amp open ' + conn);
conn.on('close', function() {
console.log(' [-] amp close ' + conn);
});
conn.on('data', function(m) {
var n = Math.floor(Number(m));
n = (n > 0 && n < 19) ? n : 1;
console.log(' [ ] amp message: 2^' + n);
conn.write(Array(Math.pow(2, n)+1).join('x'));
});
});
sjs_echo.installHandlers(server, {prefix:'/echo',
response_limit: 4096}),
sjs_echo.installHandlers(server, {prefix:'/disabled_websocket_echo',
websocket: false});
sjs_echo.installHandlers(server, {prefix:'/cookie_needed_echo',
jsessionid: true});
sjs_close.installHandlers(server, {prefix:'/close'});
sjs_ticker.installHandlers(server, {prefix:'/ticker'});
sjs_amplify.installHandlers(server, {prefix:'/amplify'});
sjs_broadcast.installHandlers(server, {prefix:'/broadcast'});
};