Update uWS, pass Autobahn with pubsub SSL/non-SSL
This commit is contained in:
parent
317aaf3b75
commit
6b5f7c40a9
5 changed files with 82 additions and 7 deletions
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);
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue