From 7fdd4276bb1e7153573e58b9f0041a50c30be28a Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Fri, 24 Aug 2018 14:52:25 +0200 Subject: [PATCH] [enh] handle ws/wss --- static/js/app.js | 8 ++++++++ templates/index.html | 2 +- templates/job.html | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/static/js/app.js b/static/js/app.js index c2c014f..00956b1 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -1,3 +1,11 @@ +function websocketPrefix() { + if (window.location.protocol == "https:") { + return "wss" + } else { + return "ws" + } +} + /* ansi_up.js * author : Dru Nelson * license : MIT diff --git a/templates/index.html b/templates/index.html index e2dd163..4dc00d7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -45,7 +45,7 @@ } }) - ws = new WebSocket('ws://' + document.domain + ':' + location.port + '/index-ws'); + ws = new WebSocket(websocketPrefix() + '://' + document.domain + ':' + location.port + '/index-ws'); ws.onmessage = function (event) { var message = JSON.parse(event.data); diff --git a/templates/job.html b/templates/job.html index 3d8be0b..419eaa8 100644 --- a/templates/job.html +++ b/templates/job.html @@ -50,7 +50,7 @@ } }) - ws = new WebSocket('ws://' + document.domain + ':' + location.port + '/job-<{ job.id }>-ws'); + ws = new WebSocket(websocketPrefix() + '://' + document.domain + ':' + location.port + '/job-<{ job.id }>-ws'); ws.onmessage = function (event) { var message = JSON.parse(event.data);