X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FHall.vue;h=b140e612d9d08c50eb2d08c9ca32c1d86e6e6233;hb=3cb412e96197807f2c991e61cad50626738a3b4f;hp=b6cac488562df6607e69cd938d957a6828e2536e;hpb=d9b86b16e70ba5acbeb09cf553e45e675667e1b1;p=vchess.git diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index b6cac488..b140e612 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -146,12 +146,13 @@ export default { ); } // 0.1] Ask server for room composition: - const socketOpenListener = () => { + const funcPollClients = () => { this.st.conn.send(JSON.stringify({code:"pollclients"})); }; - this.st.conn.onopen = socketOpenListener; - // TODO: is this required here? - this.oldOnmessage = this.st.conn.onmessage || Function.prototype; + if (!!this.st.conn && this.st.conn.readyState == 1) //1 == OPEN state + funcPollClients(); + else //socket not ready yet (initial loading) + this.st.conn.onopen = funcPollClients; this.st.conn.onmessage = this.socketMessageListener; const oldOnclose = this.st.conn.onclose; const socketCloseListener = () => { @@ -229,9 +230,6 @@ export default { }, // Messaging center: socketMessageListener: function(msg) { - // Save and call current st.conn.onmessage if one was already defined - // --> also needed in future Game.vue (also in Chat.vue component) - this.oldOnmessage(msg); const data = JSON.parse(msg.data); switch (data.code) { @@ -464,6 +462,8 @@ export default { cid: c.id, target: c.from.sid})); } } + else + localStorage.removeItem("challenge"); // In all cases, the challenge is consumed: ArrayFun.remove(this.challenges, ch => ch.id == c.id); // NOTE: deletechallenge event might be redundant (but it's easier this way)