Update uWS, pass Autobahn with pubsub SSL/non-SSL

This commit is contained in:
Alex Hultman 2019-10-09 00:29:53 +02:00
parent 317aaf3b75
commit 6b5f7c40a9
5 changed files with 82 additions and 7 deletions

39
examples/Broadcast.js vendored Normal file
View 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);
}
});

View File

@ -38,7 +38,7 @@ struct WebSocketWrapper {
if (ws) {
NativeString topic(isolate, args[0]);
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
View File

@ -21,8 +21,17 @@ function listenWithSettings(settings) {
compression: settings.compression,
maxPayloadLength: 16 * 1024 * 1024,
idleTimeout: 60,
open: (ws, req) => {
if (settings.pubsub) {
ws.subscribe('broadcast');
}
},
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) => {
/* Shut down everything on this route */
@ -55,19 +64,38 @@ function listenWithSettings(settings) {
listenWithSettings({
port: 9001,
ssl: false,
compression: uWS.DISABLED
compression: uWS.DISABLED,
pubsub: false
});
/* SSL, shared compressor */
listenWithSettings({
port: 9002,
ssl: true,
compression: uWS.SHARED_COMPRESSOR
compression: uWS.SHARED_COMPRESSOR,
pubsub: false
});
/* non-SSL, dedicated compressor */
listenWithSettings({
port: 9003,
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
});

View File

@ -12,9 +12,17 @@
{
"url": "ws://localhost:9003",
"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": ["*.*"],
"exclude-cases": [],
"exclude-agent-cases": {}
}
}

@ -1 +1 @@
Subproject commit 4c4be6b2a2c227e06f1eca313cb595779a1ce3cf
Subproject commit 1707469cf8e89002ea1c0c7db2f5d96d37e8785d