From 26c324930ebd6ee10ea818142186a2edf58e0646 Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Sun, 4 Aug 2024 19:06:00 -0500 Subject: [PATCH] ISSUE #542 - detect if SSL is in use, and adjust the websocket URL to match (either `wss://` or `ws://` for non-TLS). The URLs to forward are: * /websocket/ws (the main "ticker") * /websocket/private_ws (for per-instance data feeds) - there's nothing actually "private" about it, it's "session local". --- .../js_build/src/pubsub/direct_channels.js | 4 +++- .../lqosd/src/node_manager/js_build/src/pubsub/ws.js | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/rust/lqosd/src/node_manager/js_build/src/pubsub/direct_channels.js b/src/rust/lqosd/src/node_manager/js_build/src/pubsub/direct_channels.js index 908f443b..707f38ae 100644 --- a/src/rust/lqosd/src/node_manager/js_build/src/pubsub/direct_channels.js +++ b/src/rust/lqosd/src/node_manager/js_build/src/pubsub/direct_channels.js @@ -1,8 +1,10 @@ +import {ws_proto} from './ws.js'; + export class DirectChannel { constructor(subObject, handler) { this.ws = null; this.handler = handler; - this.ws = new WebSocket('ws://' + window.location.host + '/websocket/private_ws'); + this.ws = new WebSocket(ws_proto() + window.location.host + '/websocket/private_ws'); this.ws.onopen = () => { this.ws.send(JSON.stringify(subObject)); } diff --git a/src/rust/lqosd/src/node_manager/js_build/src/pubsub/ws.js b/src/rust/lqosd/src/node_manager/js_build/src/pubsub/ws.js index 5af1f2ee..c780aa6a 100644 --- a/src/rust/lqosd/src/node_manager/js_build/src/pubsub/ws.js +++ b/src/rust/lqosd/src/node_manager/js_build/src/pubsub/ws.js @@ -1,12 +1,20 @@ // Setup any WS feeds for this page let ws = null; +export function ws_proto() { + if (window.location.protocl === 'https') { + return "wss://"; + } else { + return "ws://"; + } +} + export function subscribeWS(channels, handler) { if (ws) { ws.close(); } - ws = new WebSocket('ws://' + window.location.host + '/websocket/ws'); + ws = new WebSocket(ws_proto() + window.location.host + '/websocket/ws'); ws.onopen = () => { for (let i=0; i