From 47ef181043191aaabe69776df5094d3853825916 Mon Sep 17 00:00:00 2001 From: Oliver Giles Date: Sat, 23 Sep 2017 14:36:04 +0300 Subject: [PATCH] if https then use wss --- src/resources/js/app.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/resources/js/app.js b/src/resources/js/app.js index c4c3111..f774763 100644 --- a/src/resources/js/app.js +++ b/src/resources/js/app.js @@ -2,9 +2,13 @@ * frontend application for Laminar Continuous Integration * https://laminar.ohwg.net */ +const wsp = function(path) { + return new WebSocket((location.protocol === 'https:'?'wss://':'ws://') + + location.host + path); +} const WebsocketHandler = function() { function setupWebsocket(path, next) { - var ws = new WebSocket("ws://" + window.location.host + path); + var ws = wsp(path); ws.onmessage = function(msg) { msg = JSON.parse(msg.data); // "status" is the first message the websocket always delivers. @@ -406,7 +410,7 @@ const Run = function() { }, beforeRouteEnter(to, from, next) { next(vm => { - vm.logws = new WebSocket("ws://" + location.host + to.path + '/log'); + vm.logws = wsp(to.path + '/log'); vm.logws.onmessage = function(msg) { logHandler(vm, msg.data); } @@ -415,7 +419,7 @@ const Run = function() { beforeRouteUpdate(to, from, next) { var vm = this; vm.logws.close(); - vm.logws = new WebSocket("ws://" + location.host + to.path + '/log'); + vm.logws = wsp(to.path + '/log'); vm.logws.onmessage = function(msg) { logHandler(vm, msg.data); }