mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2024-11-21 15:57:24 -06:00
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".
This commit is contained in:
parent
cc6958e127
commit
26c324930e
@ -1,8 +1,10 @@
|
|||||||
|
import {ws_proto} from './ws.js';
|
||||||
|
|
||||||
export class DirectChannel {
|
export class DirectChannel {
|
||||||
constructor(subObject, handler) {
|
constructor(subObject, handler) {
|
||||||
this.ws = null;
|
this.ws = null;
|
||||||
this.handler = handler;
|
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.onopen = () => {
|
||||||
this.ws.send(JSON.stringify(subObject));
|
this.ws.send(JSON.stringify(subObject));
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,20 @@
|
|||||||
// Setup any WS feeds for this page
|
// Setup any WS feeds for this page
|
||||||
let ws = null;
|
let ws = null;
|
||||||
|
|
||||||
|
export function ws_proto() {
|
||||||
|
if (window.location.protocl === 'https') {
|
||||||
|
return "wss://";
|
||||||
|
} else {
|
||||||
|
return "ws://";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function subscribeWS(channels, handler) {
|
export function subscribeWS(channels, handler) {
|
||||||
if (ws) {
|
if (ws) {
|
||||||
ws.close();
|
ws.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
ws = new WebSocket('ws://' + window.location.host + '/websocket/ws');
|
ws = new WebSocket(ws_proto() + window.location.host + '/websocket/ws');
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
for (let i=0; i<channels.length; i++) {
|
for (let i=0; i<channels.length; i++) {
|
||||||
ws.send("{ \"channel\" : \"" + channels[i] + "\"}");
|
ws.send("{ \"channel\" : \"" + channels[i] + "\"}");
|
||||||
|
Loading…
Reference in New Issue
Block a user