diff --git a/static/socket.js b/static/socket.js index c36e384..8dbf5f0 100644 --- a/static/socket.js +++ b/static/socket.js @@ -163,12 +163,12 @@ function dial() { if (conn) { conn.close(1000); } - conn = new WebSocket(`ws://${location.host}/subscribe`, `${tableKey.name}.${tableKey.passcode}`); + const wsProto = location.protocol == "https:" ? "wss" : "ws"; + conn = new WebSocket(`${wsProto}://${location.host}/subscribe`, `${tableKey.name}.${tableKey.passcode}`); conn.addEventListener("close", e => { - if (e.code == 1006) { + if (e.code == 1006 && e.wasClean) { setErr("Table not found - check the name and passcode are correct"); } else if (e.code > 1001) { - // TODO: add message to let user know they are reconnecting setErr("Websocket error: trying to reconnect"); setTimeout(dial, 1000) } else { @@ -186,7 +186,7 @@ function dial() { } }); conn.addEventListener("open", e => { - // TODO: add message to let user know they are at the table + closeErr(); tabletop = document.getElementById("tabletop"); if (tabletop) { tabletop.style.display = "block";