diff --git a/www/messaging.js b/www/messaging.js index a4409fd..5cb2c37 100644 --- a/www/messaging.js +++ b/www/messaging.js @@ -1,5 +1,5 @@ function Messaging(screen) { - var ws = new WebSocket('ws://' + window.location.hostname + '/play/'); + var ws = new WebSocket(window.location.origin.replace(/^http/, 'ws') + '/play/'); var debug = getParameters().debug; var doLog = debug != undefined && debug.match(/^(?:1|t(?:rue)?|v(?:rai)?)$/i); var keepAlivePeriod = 20000; @@ -66,9 +66,9 @@ function Messaging(screen) { } function start() { - ping(); - addEventListener(["Pong"], ping); ws.addEventListener('message', messageListener); + ws.addEventListener('open', ping); + addEventListener(["Pong"], ping); } function send(o) {