Skip to content

Commit 6b5f7c4

Browse files
committed
Update uWS, pass Autobahn with pubsub SSL/non-SSL
1 parent 317aaf3 commit 6b5f7c4

5 files changed

Lines changed: 82 additions & 7 deletions

File tree

‎examples/Broadcast.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Simple pub/sub broadcasting example */
2+
3+
const uWS = require('../dist/uws.js');
4+
const port = 9001;
5+
6+
const app = uWS./*SSL*/App({
7+
key_file_name: 'misc/key.pem',
8+
cert_file_name: 'misc/cert.pem',
9+
passphrase: '1234'
10+
}).ws('/*', {
11+
/* Options */
12+
compression: 0,
13+
maxPayloadLength: 16 * 1024 * 1024,
14+
idleTimeout: 10,
15+
16+
/* Handlers */
17+
open: (ws, req) => {
18+
/* Let this client listen to topic "broadcast" */
19+
ws.subscribe('broadcast');
20+
},
21+
message: (ws, message, isBinary) => {
22+
/* Broadcast this message */
23+
ws.publish('broadcast', message, isBinary);
24+
},
25+
drain: (ws) => {
26+
27+
},
28+
close: (ws, code, message) => {
29+
/* The library guarantees proper unsubscription at close */
30+
}
31+
}).any('/*', (res, req) => {
32+
res.end('Nothing to see here!');
33+
}).listen(port, (token) => {
34+
if (token) {
35+
console.log('Listening to port ' + port);
36+
} else {
37+
console.log('Failed to listen to port ' + port);
38+
}
39+
});

‎src/WebSocketWrapper.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct WebSocketWrapper {
3838
if (ws) {
3939
NativeString topic(isolate, args[0]);
4040
NativeString message(isolate, args[1]);
41-
ws->publish(topic.getString(), message.getString());
41+
ws->publish(topic.getString(), message.getString(), args[2]->BooleanValue(isolate->GetCurrentContext()).ToChecked() ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[3]->BooleanValue(isolate->GetCurrentContext()).ToChecked());
4242
}
4343
}
4444

‎tests/Autobahn.js‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@ function listenWithSettings(settings) {
2121
compression: settings.compression,
2222
maxPayloadLength: 16 * 1024 * 1024,
2323
idleTimeout: 60,
24+
open: (ws, req) => {
25+
if (settings.pubsub) {
26+
ws.subscribe('broadcast');
27+
}
28+
},
2429
message: (ws, message, isBinary) => {
25-
ws.send(message, isBinary, true);
30+
if (settings.pubsub) {
31+
ws.publish('broadcast', message, isBinary);
32+
} else {
33+
ws.send(message, isBinary, true);
34+
}
2635
}
2736
}).any('/exit', (res, req) => {
2837
/* Shut down everything on this route */
@@ -55,19 +64,38 @@ function listenWithSettings(settings) {
5564
listenWithSettings({
5665
port: 9001,
5766
ssl: false,
58-
compression: uWS.DISABLED
67+
compression: uWS.DISABLED,
68+
pubsub: false
5969
});
6070

6171
/* SSL, shared compressor */
6272
listenWithSettings({
6373
port: 9002,
6474
ssl: true,
65-
compression: uWS.SHARED_COMPRESSOR
75+
compression: uWS.SHARED_COMPRESSOR,
76+
pubsub: false
6677
});
6778

6879
/* non-SSL, dedicated compressor */
6980
listenWithSettings({
7081
port: 9003,
7182
ssl: false,
72-
compression: uWS.DEDICATED_COMPRESSOR
83+
compression: uWS.DEDICATED_COMPRESSOR,
84+
pubsub: false
85+
});
86+
87+
/* pub/sub based, non-SSL, non-compression */
88+
listenWithSettings({
89+
port: 9004,
90+
ssl: false,
91+
compression: uWS.DISABLED,
92+
pubsub: true
93+
});
94+
95+
/* pub/sub based, SSL, non-compression */
96+
listenWithSettings({
97+
port: 9005,
98+
ssl: true,
99+
compression: uWS.DISABLED,
100+
pubsub: true
73101
});

‎tests/fuzzingclient.json‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@
1212
{
1313
"url": "ws://localhost:9003",
1414
"agent": "uWebSockets.js non-SSL, dedicated compressor"
15+
},
16+
{
17+
"url": "ws://localhost:9004",
18+
"agent": "uWebSockets.js non-SSL, non-compression, pubsub based"
19+
},
20+
{
21+
"url": "wss://localhost:9005",
22+
"agent": "uWebSockets.js SSL, non-compression, pubsub based"
1523
}
1624
],
1725
"cases": ["*.*"],
1826
"exclude-cases": [],
1927
"exclude-agent-cases": {}
20-
}
28+
}

0 commit comments

Comments
 (0)