Update uWS, pass Autobahn with pubsub SSL/non-SSL
This commit is contained in:
parent
317aaf3b75
commit
6b5f7c40a9
39
examples/Broadcast.js
vendored
Normal file
39
examples/Broadcast.js
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* Simple pub/sub broadcasting example */
|
||||||
|
|
||||||
|
const uWS = require('../dist/uws.js');
|
||||||
|
const port = 9001;
|
||||||
|
|
||||||
|
const app = uWS./*SSL*/App({
|
||||||
|
key_file_name: 'misc/key.pem',
|
||||||
|
cert_file_name: 'misc/cert.pem',
|
||||||
|
passphrase: '1234'
|
||||||
|
}).ws('/*', {
|
||||||
|
/* Options */
|
||||||
|
compression: 0,
|
||||||
|
maxPayloadLength: 16 * 1024 * 1024,
|
||||||
|
idleTimeout: 10,
|
||||||
|
|
||||||
|
/* Handlers */
|
||||||
|
open: (ws, req) => {
|
||||||
|
/* Let this client listen to topic "broadcast" */
|
||||||
|
ws.subscribe('broadcast');
|
||||||
|
},
|
||||||
|
message: (ws, message, isBinary) => {
|
||||||
|
/* Broadcast this message */
|
||||||
|
ws.publish('broadcast', message, isBinary);
|
||||||
|
},
|
||||||
|
drain: (ws) => {
|
||||||
|
|
||||||
|
},
|
||||||
|
close: (ws, code, message) => {
|
||||||
|
/* The library guarantees proper unsubscription at close */
|
||||||
|
}
|
||||||
|
}).any('/*', (res, req) => {
|
||||||
|
res.end('Nothing to see here!');
|
||||||
|
}).listen(port, (token) => {
|
||||||
|
if (token) {
|
||||||
|
console.log('Listening to port ' + port);
|
||||||
|
} else {
|
||||||
|
console.log('Failed to listen to port ' + port);
|
||||||
|
}
|
||||||
|
});
|
@ -38,7 +38,7 @@ struct WebSocketWrapper {
|
|||||||
if (ws) {
|
if (ws) {
|
||||||
NativeString topic(isolate, args[0]);
|
NativeString topic(isolate, args[0]);
|
||||||
NativeString message(isolate, args[1]);
|
NativeString message(isolate, args[1]);
|
||||||
ws->publish(topic.getString(), message.getString());
|
ws->publish(topic.getString(), message.getString(), args[2]->BooleanValue(isolate->GetCurrentContext()).ToChecked() ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[3]->BooleanValue(isolate->GetCurrentContext()).ToChecked());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
36
tests/Autobahn.js
vendored
36
tests/Autobahn.js
vendored
@ -21,8 +21,17 @@ function listenWithSettings(settings) {
|
|||||||
compression: settings.compression,
|
compression: settings.compression,
|
||||||
maxPayloadLength: 16 * 1024 * 1024,
|
maxPayloadLength: 16 * 1024 * 1024,
|
||||||
idleTimeout: 60,
|
idleTimeout: 60,
|
||||||
|
open: (ws, req) => {
|
||||||
|
if (settings.pubsub) {
|
||||||
|
ws.subscribe('broadcast');
|
||||||
|
}
|
||||||
|
},
|
||||||
message: (ws, message, isBinary) => {
|
message: (ws, message, isBinary) => {
|
||||||
ws.send(message, isBinary, true);
|
if (settings.pubsub) {
|
||||||
|
ws.publish('broadcast', message, isBinary);
|
||||||
|
} else {
|
||||||
|
ws.send(message, isBinary, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).any('/exit', (res, req) => {
|
}).any('/exit', (res, req) => {
|
||||||
/* Shut down everything on this route */
|
/* Shut down everything on this route */
|
||||||
@ -55,19 +64,38 @@ function listenWithSettings(settings) {
|
|||||||
listenWithSettings({
|
listenWithSettings({
|
||||||
port: 9001,
|
port: 9001,
|
||||||
ssl: false,
|
ssl: false,
|
||||||
compression: uWS.DISABLED
|
compression: uWS.DISABLED,
|
||||||
|
pubsub: false
|
||||||
});
|
});
|
||||||
|
|
||||||
/* SSL, shared compressor */
|
/* SSL, shared compressor */
|
||||||
listenWithSettings({
|
listenWithSettings({
|
||||||
port: 9002,
|
port: 9002,
|
||||||
ssl: true,
|
ssl: true,
|
||||||
compression: uWS.SHARED_COMPRESSOR
|
compression: uWS.SHARED_COMPRESSOR,
|
||||||
|
pubsub: false
|
||||||
});
|
});
|
||||||
|
|
||||||
/* non-SSL, dedicated compressor */
|
/* non-SSL, dedicated compressor */
|
||||||
listenWithSettings({
|
listenWithSettings({
|
||||||
port: 9003,
|
port: 9003,
|
||||||
ssl: false,
|
ssl: false,
|
||||||
compression: uWS.DEDICATED_COMPRESSOR
|
compression: uWS.DEDICATED_COMPRESSOR,
|
||||||
|
pubsub: false
|
||||||
|
});
|
||||||
|
|
||||||
|
/* pub/sub based, non-SSL, non-compression */
|
||||||
|
listenWithSettings({
|
||||||
|
port: 9004,
|
||||||
|
ssl: false,
|
||||||
|
compression: uWS.DISABLED,
|
||||||
|
pubsub: true
|
||||||
|
});
|
||||||
|
|
||||||
|
/* pub/sub based, SSL, non-compression */
|
||||||
|
listenWithSettings({
|
||||||
|
port: 9005,
|
||||||
|
ssl: true,
|
||||||
|
compression: uWS.DISABLED,
|
||||||
|
pubsub: true
|
||||||
});
|
});
|
||||||
|
@ -12,9 +12,17 @@
|
|||||||
{
|
{
|
||||||
"url": "ws://localhost:9003",
|
"url": "ws://localhost:9003",
|
||||||
"agent": "uWebSockets.js non-SSL, dedicated compressor"
|
"agent": "uWebSockets.js non-SSL, dedicated compressor"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "ws://localhost:9004",
|
||||||
|
"agent": "uWebSockets.js non-SSL, non-compression, pubsub based"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "wss://localhost:9005",
|
||||||
|
"agent": "uWebSockets.js SSL, non-compression, pubsub based"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"cases": ["*.*"],
|
"cases": ["*.*"],
|
||||||
"exclude-cases": [],
|
"exclude-cases": [],
|
||||||
"exclude-agent-cases": {}
|
"exclude-agent-cases": {}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 4c4be6b2a2c227e06f1eca313cb595779a1ce3cf
|
Subproject commit 1707469cf8e89002ea1c0c7db2f5d96d37e8785d
|
Loading…
Reference in New Issue
Block a user