From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- testing/xpcshell/node-ws/examples/ssl.js | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 testing/xpcshell/node-ws/examples/ssl.js (limited to 'testing/xpcshell/node-ws/examples/ssl.js') diff --git a/testing/xpcshell/node-ws/examples/ssl.js b/testing/xpcshell/node-ws/examples/ssl.js new file mode 100644 index 0000000000..a5e750b799 --- /dev/null +++ b/testing/xpcshell/node-ws/examples/ssl.js @@ -0,0 +1,37 @@ +'use strict'; + +const https = require('https'); +const fs = require('fs'); + +const { WebSocket, WebSocketServer } = require('..'); + +const server = https.createServer({ + cert: fs.readFileSync('../test/fixtures/certificate.pem'), + key: fs.readFileSync('../test/fixtures/key.pem') +}); + +const wss = new WebSocketServer({ server }); + +wss.on('connection', function connection(ws) { + ws.on('message', function message(msg) { + console.log(msg.toString()); + }); +}); + +server.listen(function listening() { + // + // If the `rejectUnauthorized` option is not `false`, the server certificate + // is verified against a list of well-known CAs. An 'error' event is emitted + // if verification fails. + // + // The certificate used in this example is self-signed so `rejectUnauthorized` + // is set to `false`. + // + const ws = new WebSocket(`wss://localhost:${server.address().port}`, { + rejectUnauthorized: false + }); + + ws.on('open', function open() { + ws.send('All glory to WebSockets!'); + }); +}); -- cgit v1.2.3