let names = {};
response.challenges.forEach(c => {
if (c.uid != this.st.user.id) names[c.uid] = "";
- else if (!!c.target && c.target != this.st.user.id)
+ else if (c.target && c.target != this.st.user.id)
names[c.target] = "";
});
const addChallenges = () => {
processChat: function(chat) {
this.send("newchat", { data: chat });
},
+ getOppsid: function(c) {
+ let oppsid = c.from.sid; //may not be defined if corr + offline opp
+ if (!oppsid) {
+ oppsid = Object.keys(this.people).find(
+ sid => this.people[sid].id == c.from.id
+ );
+ }
+ return oppsid;
+ },
// Messaging center:
socketMessageListener: function(msg) {
if (!this.conn) return;
};
this.launchGame(c);
} else {
- this.send("refusechallenge", { data: c.id, target: c.from.sid });
+ const oppsid = this.getOppsid(c);
+ if (oppsid)
+ this.send("refusechallenge", { data: c.id, target: oppsid });
}
this.send("deletechallenge", { data: c.id });
},
vid: c.vid,
cadence: c.cadence
};
- let oppsid = c.from.sid; //may not be defined if corr + offline opp
- if (!oppsid) {
- oppsid = Object.keys(this.people).find(
- sid => this.people[sid].id == c.from.id
- );
- }
const notifyNewgame = () => {
+ const oppsid = this.getOppsid(c);
if (oppsid)
//opponent is online
this.send("startgame", { data: gameInfo, target: oppsid });