summaryrefslogtreecommitdiffstats
path: root/testing/xpcshell/node-ws/examples/ssl.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/xpcshell/node-ws/examples/ssl.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--testing/xpcshell/node-ws/examples/ssl.js37
1 files changed, 37 insertions, 0 deletions
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!');
+ });
+});