- // Game infos: constant
- gameId: gameInfo.gameId,
- vname: this.getVname(gameInfo.vid),
+ const opponent = this.people.find(p => p.id == c.from.id);
+ if (!!opponent)
+ target = opponent.sid
+ }
+ const tryNotifyOpponent = () => {
+ if (!!target) //opponent is online
+ {
+ this.st.conn.send(JSON.stringify({code:"newgame",
+ gameInfo:gameInfo, target:target, cid:c.id}));
+ }
+ };
+ if (c.type == "live")
+ {
+ tryNotifyOpponent();
+ this.startNewGame(gameInfo);
+ }
+ else //corr: game only on server
+ {
+ ajax(
+ "/games",
+ "POST",
+ {gameInfo: gameInfo, cid: c.id}, //cid useful to delete challenge
+ response => {
+ gameInfo.gameId = response.gameId;
+ tryNotifyOpponent();
+ this.$router.push("/game/" + response.gameId);
+ }
+ );
+ }
+ },
+ // NOTE: for live games only (corr games start on the server)
+ startNewGame: function(gameInfo) {
+ const game = Object.assign({}, gameInfo, {
+ // (other) Game infos: constant