From a0ec553fb703f36e935ff616d8ace663664e21c8 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 9 Mar 2018 13:38:23 +0100 Subject: connect to the websocket on the same host using wss or ws Signed-off-by: Olivier Gayot --- usr/share/swiftstory/www/swiftstory-common.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'usr/share/swiftstory') diff --git a/usr/share/swiftstory/www/swiftstory-common.js b/usr/share/swiftstory/www/swiftstory-common.js index 174b473..5d19555 100644 --- a/usr/share/swiftstory/www/swiftstory-common.js +++ b/usr/share/swiftstory/www/swiftstory-common.js @@ -214,7 +214,13 @@ var SwiftStory = function() { /* }}} */ this.run = function() { - ws = new WebSocket('ws://' + document.location.hostname + ':1236'); + /* Use websockets over TLS only when the page is served over TLS. */ + var scheme = (document.location.protocol === 'https:') ? 'wss' : 'ws'; + + /* NOTE: We need to access the exact url (no redirection allowed). */ + var uri = scheme + '://' + document.location.host + '/ws/'; + + ws = new WebSocket(uri); ws.onopen = function() { console.log('connection established'); -- cgit v1.2.3