Add support for websocket even over SSL and wait for websocket to be properly open before trying to ping

This commit is contained in:
Tissevert 2019-08-21 16:41:06 +02:00
parent ac114c16df
commit 0f685c0a98

View file

@ -1,5 +1,5 @@
function Messaging(screen) { 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 debug = getParameters().debug;
var doLog = debug != undefined && debug.match(/^(?:1|t(?:rue)?|v(?:rai)?)$/i); var doLog = debug != undefined && debug.match(/^(?:1|t(?:rue)?|v(?:rai)?)$/i);
var keepAlivePeriod = 20000; var keepAlivePeriod = 20000;
@ -66,9 +66,9 @@ function Messaging(screen) {
} }
function start() { function start() {
ping();
addEventListener(["Pong"], ping);
ws.addEventListener('message', messageListener); ws.addEventListener('message', messageListener);
ws.addEventListener('open', ping);
addEventListener(["Pong"], ping);
} }
function send(o) { function send(o) {