- // TODO: ask server for current corr games (all but mines: names, ID, time control)
- // also ask for corr challenges
- if (!!this.st.conn)
- {
- this.st.conn.onmessage = this.socketMessageListener;
- this.st.conn.onclose = this.socketCloseListener;
- // Ask server for for room composition:
- this.st.conn.send(JSON.stringify({code:"askplayers"}));
- }
+ // Always add myself to players' list
+ this.players.push(this.st.user);
+ // Ask server for current corr games (all but mines)
+// ajax(
+// "",
+// "GET",
+// response => {
+//
+// }
+// );
+// // Also ask for corr challenges (all)
+// ajax(
+// "",
+// "GET",
+// response => {
+//
+// }
+// );
+ // 0.1] Ask server for for room composition:
+ const socketOpenListener = () => {
+ this.st.conn.send(JSON.stringify({code:"askclients"}));
+ };
+ this.st.conn.onopen = socketOpenListener;
+ this.oldOnmessage = this.st.conn.onmessage || Function.prototype; //TODO: required here?
+ this.st.conn.onmessage = this.socketMessageListener;
+ const oldOnclose = this.st.conn.onclose;
+ const socketCloseListener = () => {
+ oldOnclose(); //reinitialize connexion (in store.js)
+ this.st.conn.addEventListener('message', this.socketMessageListener);
+ this.st.conn.addEventListener('close', socketCloseListener);
+ };
+ this.st.conn.onclose = socketCloseListener;