+ socketMessageListener: function(msg) {
+ const data = JSON.parse(msg.data);
+ switch (data.code)
+ {
+ case "newgame":
+ // TODO: new game just started: data contain all informations
+ // (id, players, time control, fenStart ...)
+ break;
+ // TODO: also receive live games summaries (update)
+ // (just players names, time control, and ID + player ID)
+ case "acceptchallenge":
+ if (true) //TODO: if challenge is full
+ this.newGame(data.challenge, data.user); //user.id et user.name
+ break;
+ case "withdrawchallenge":
+ const cIdx = this.challenges.findIndex(c => c.id == data.cid);
+ let chall = this.challenges[cIdx]
+ ArrayFun.remove(chall.players, p => p.id == data.uid);
+ chall.players.push({id:0, name:""});
+ break;
+ case "cancelchallenge":
+ ArrayFun.remove(this.challenges, c => c.id == data.cid);
+ break;
+ case "hallconnect":
+ this.players.push({name:data.name, id:data.uid});
+ break;
+ case "halldisconnect":
+ ArrayFun.remove(this.players, p => p.id == data.uid);
+ break;
+ }
+ },
+ socketCloseListener: function() {
+ this.st.conn.addEventListener('message', socketMessageListener);
+ this.st.conn.addEventListener('close', socketCloseListener);
+ },
+ clickPlayer: function() {
+ //this.newgameInfo.players[0].name = clickPlayer.name;
+ //show modal;
+ },