Skip to content

Commit

Permalink
ISSUE #542 - detect if SSL is in use, and adjust the websocket URL to…
Browse files Browse the repository at this point in the history
… 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".
  • Loading branch information
thebracket committed Aug 5, 2024
1 parent cc6958e commit 26c3249
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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));
}
Expand Down
10 changes: 9 additions & 1 deletion src/rust/lqosd/src/node_manager/js_build/src/pubsub/ws.js
Original file line number Diff line number Diff line change
@@ -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<channels.length; i++) {
ws.send("{ \"channel\" : \"" + channels[i] + "\"}");
Expand Down

0 comments on commit 26c3249

Please sign in to comment.