};
},
created: function() {
+ const curMsgListener = this.st.conn.onmessage; //from Game or Hall
const socketMessageListener = msg => {
+ curMsgListener(msg);
const data = JSON.parse(msg.data);
if (data.code == "newchat") //only event at this level
{
case "identity":
{
let player = this.people.find(p => p.sid == data.user.sid);
+ // NOTE: sometimes player.id fails because player is undefined...
+ // Probably because the event was meant for Hall?
+ if (!player)
+ return;
player.id = data.user.id;
player.name = data.user.name;
// Sending last state only for live games: corr games are complete
// Ask identity, challenges and game(s)
this.st.conn.send(JSON.stringify({code:"askidentity", target:sid}));
this.st.conn.send(JSON.stringify({code:"askchallenge", target:sid}));
- this.st.conn.send(JSON.stringify({code:"askgame", target:sid}));
});
+ // Also ask current games to all playing peers (TODO: some design issue)
+ this.st.conn.send(JSON.stringify({code:"askgames"}));
break;
}
case "askidentity":
let obj = JSON.parse(objtxt);
if (!!obj.target && !clients[obj.target])
return; //receiver not connected, nothing we can do
-
-console.log(obj.code);
-
switch (obj.code)
{
case "pollclients":
clients[obj.target].sock.send(JSON.stringify(
{code:"askchallenge",from:sid}));
break;
- case "askgame":
+ case "askgames":
// Check all clients playing, and send them a "askgame" message
Object.keys(clients).forEach(k => {
if (k != sid && clients[k].page.indexOf("/game/") >= 0)
{code:"askgame", from: sid}));
}
});
- clients[obj.target].sock.send(JSON.stringify(
- {code:"askgame",from:sid}));
break;
case "identity":
clients[obj.target].sock.send(JSON.stringify(