using WSS protocol when on HTTPS instead of WS

This commit is contained in:
azivner 2017-12-03 10:12:16 -05:00
parent 15faefe8a3
commit 28bc443914

View file

@ -39,9 +39,11 @@ const messaging = (function() {
}
function connectWebSocket() {
const protocol = document.location.protocol === 'https:' ? 'wss' : 'ws';
// use wss for secure messaging
ws = new WebSocket("ws://" + location.host);
ws.onopen = function (event) {};
ws = new WebSocket(protocol + "://" + location.host);
ws.onopen = event => console.log("Connected to server with WebSocket");
ws.onmessage = messageHandler;
ws.onclose = function(){
// Try to reconnect in 5 seconds