3 input#modalInfo.modal(type="checkbox")
6 data-checkbox="modalInfo"
9 label.modal-close(for="modalInfo")
10 p(v-html="infoMessage")
11 input#modalAccept.modal(type="checkbox")
12 div#acceptDiv(role="dialog")
15 span.variantName {{ curChallToAccept.vname }}
16 span {{ curChallToAccept.cadence }}
17 span {{ st.tr["with"] + " " + curChallToAccept.from.name }}
18 .diagram(v-html="tchallDiag")
19 .button-group#buttonsTchall
20 button.acceptBtn(@click="decisionChallenge(true)") {{ st.tr["Accept challenge?"] }}
21 button.refuseBtn(@click="decisionChallenge(false)") {{ st.tr["Refuse"] }}
22 input#modalNewgame.modal(
24 @change="cadenceFocusIfOpened($event)"
28 data-checkbox="modalNewgame"
31 label#closeNewgame.modal-close(for="modalNewgame")
32 div(@keyup.enter="newChallenge()")
34 label(for="selectVariant") {{ st.tr["Variant"] }} *
36 @change="loadNewchallVariant(trySetNewchallDiag)"
37 v-model="newchallenge.vid"
40 v-for="v in st.variants"
42 :selected="newchallenge.vid==v.id"
46 label(for="cadence") {{ st.tr["Cadence"] }} *
47 div#predefinedCadences
48 button(type="button") 15+5
49 button(type="button") 45+30
50 button(type="button") 3d
51 button(type="button") 7d
54 v-model="newchallenge.cadence"
55 placeholder="5+0, 1h+30s, 5d ..."
58 label(for="selectRandomLevel") {{ st.tr["Randomness"] }} *
59 select#selectRandomLevel(v-model="newchallenge.randomness")
60 option(value="0") {{ st.tr["Deterministic"] }}
61 option(value="1") {{ st.tr["Symmetric random"] }}
62 option(value="2") {{ st.tr["Asymmetric random"] }}
63 fieldset(v-if="st.user.id > 0")
64 label(for="selectPlayers") {{ st.tr["Play with?"] }}
67 v-model="newchallenge.to"
69 fieldset(v-if="st.user.id > 0 && newchallenge.to.length > 0")
72 @input="trySetNewchallDiag()"
74 v-model="newchallenge.fen"
76 .diagram(v-html="newchallenge.diag")
77 button(@click="newChallenge()") {{ st.tr["Send challenge"] }}
78 input#modalPeople.modal(
80 @click="resetSocialColor()"
84 data-checkbox="modalPeople"
87 label.modal-close(for="modalPeople")
91 v-for="sid in Object.keys(people)"
92 v-if="people[sid].name"
94 span {{ people[sid].name }}
97 @click="watchGame(sid)"
99 | {{ st.tr["Observe"] }}
100 button.player-action(
101 v-else-if="st.user.id > 0 && sid!=st.user.sid"
102 @click="challenge(sid)"
104 | {{ st.tr["Challenge"] }}
105 p.anonymous @nonymous ({{ anonymousCount }})
109 @mychat="processChat"
114 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
116 button#peopleBtn(onClick="window.doClick('modalPeople')")
117 | {{ st.tr["Who's there?"] }}
118 button(onClick="window.doClick('modalNewgame')")
119 | {{ st.tr["New game"] }}
121 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
124 button.tabbtn#btnClive(@click="setDisplay('c','live',$event)")
125 | {{ st.tr["Live challenges"] }}
126 button.tabbtn#btnCcorr(@click="setDisplay('c','corr',$event)")
127 | {{ st.tr["Correspondance challenges"] }}
129 v-show="cdisplay=='live'"
130 :challenges="filterChallenges('live')"
131 @click-challenge="clickChallenge"
134 v-show="cdisplay=='corr'"
135 :challenges="filterChallenges('corr')"
136 @click-challenge="clickChallenge"
140 button.tabbtn#btnGlive(@click="setDisplay('g','live',$event)")
141 | {{ st.tr["Live games"] }}
142 button.tabbtn#btnGcorr(@click="setDisplay('g','corr',$event)")
143 | {{ st.tr["Correspondance games"] }}
145 v-show="gdisplay=='live'"
146 :games="filterGames('live')"
148 @show-game="showGame"
151 v-show="gdisplay=='corr'"
152 :games="filterGames('corr')"
154 @show-game="showGame"
159 import { store } from "@/store";
160 import { checkChallenge } from "@/data/challengeCheck";
161 import { ArrayFun } from "@/utils/array";
162 import { ajax } from "@/utils/ajax";
163 import params from "@/parameters";
164 import { getRandString, shuffle } from "@/utils/alea";
165 import { getDiagram } from "@/utils/printDiagram";
166 import Chat from "@/components/Chat.vue";
167 import GameList from "@/components/GameList.vue";
168 import ChallengeList from "@/components/ChallengeList.vue";
169 import { GameStorage } from "@/utils/gameStorage";
170 import { processModalClick } from "@/utils/modalClick";
181 cdisplay: "live", //or corr
189 vid: parseInt(localStorage.getItem("vid")) || 0,
190 to: "", //name of challenged player (if any)
191 cadence: localStorage.getItem("cadence") || "",
192 randomness: parseInt(localStorage.getItem("randomness")) || 2,
193 // VariantRules object, stored to not interfere with
194 // diagrams of targetted challenges:
197 diag: "" //visualizing FEN
200 curChallToAccept: {from: {}},
204 // Related to (killing of) self multi-connects:
210 // st.variants changes only once, at loading from [] to [...]
211 "st.variants": function() {
212 // Set potential challenges and games variant names:
213 this.challenges.concat(this.games).forEach(o => {
214 if (o.vname == "") o.vname = this.getVname(o.vid);
216 if (!this.newchallenge.V && this.newchallenge.vid > 0)
217 this.loadNewchallVariant();
221 anonymousCount: function() {
223 Object.values(this.people).forEach(p => {
224 // Do not cound people who did not send their identity yet:
225 count += (!p.name && p.id === 0) ? 1 : 0;
230 created: function() {
231 if (this.st.variants.length > 0 && this.newchallenge.vid > 0)
232 this.loadNewchallVariant();
233 const my = this.st.user;
234 this.$set(this.people, my.sid, { id: my.id, name: my.name, pages: ["/"] });
235 // Ask server for current corr games (all but mines)
239 { uid: this.st.user.id, excluded: true },
241 this.games = this.games.concat(
242 response.games.map(g => {
243 const type = this.classifyObject(g);
244 const vname = this.getVname(g.vid);
245 return Object.assign({}, g, { type: type, vname: vname });
250 // Also ask for corr challenges (open + sent by/to me)
251 ajax("/challenges", "GET", { uid: this.st.user.id }, response => {
252 // Gather all senders names, and then retrieve full identity:
253 // (TODO [perf]: some might be online...)
255 response.challenges.forEach(c => {
256 if (c.uid != this.st.user.id) names[c.uid] = "";
257 else if (!!c.target && c.target != this.st.user.id)
258 names[c.target] = "";
260 const addChallenges = () => {
261 names[this.st.user.id] = this.st.user.name; //in case of
262 this.challenges = this.challenges.concat(
263 response.challenges.map(c => {
264 const from = { name: names[c.uid], id: c.uid }; //or just name
265 const type = this.classifyObject(c);
266 const vname = this.getVname(c.vid);
267 return Object.assign(
273 to: c.target ? names[c.target] : ""
280 if (Object.keys(names).length > 0) {
284 { ids: Object.keys(names).join(",") },
286 response2.users.forEach(u => {
287 names[u.id] = u.name;
292 } else addChallenges();
294 const connectAndPoll = () => {
295 this.send("connect");
296 this.send("pollclientsandgamers");
298 // Initialize connection
299 this.connexionString =
306 encodeURIComponent(this.$route.path);
307 this.conn = new WebSocket(this.connexionString);
308 this.conn.onopen = connectAndPoll;
309 this.conn.onmessage = this.socketMessageListener;
310 this.conn.onclose = this.socketCloseListener;
312 mounted: function() {
313 ["peopleWrap", "infoDiv", "newgameDiv"].forEach(eltName => {
314 let elt = document.getElementById(eltName);
315 elt.addEventListener("click", processModalClick);
317 document.querySelectorAll("#predefinedCadences > button").forEach(b => {
318 b.addEventListener("click", () => {
319 this.newchallenge.cadence = b.innerHTML;
322 const dispCorr = this.$route.query["disp"];
324 dispCorr || localStorage.getItem("type-challenges") || "live";
326 dispCorr || localStorage.getItem("type-games") || "live";
327 this.setDisplay("c", showCtype);
328 this.setDisplay("g", showGtype);
330 beforeDestroy: function() {
331 this.send("disconnect");
335 cadenceFocusIfOpened: function() {
336 if (event.target.checked)
337 document.getElementById("cadence").focus();
339 send: function(code, obj) {
341 this.conn.send(JSON.stringify(Object.assign({ code: code }, obj)));
344 getVname: function(vid) {
345 const variant = this.st.variants.find(v => v.id == vid);
346 // this.st.variants might be uninitialized (variant == null)
347 return variant ? variant.name : "";
349 filterChallenges: function(type) {
350 return this.challenges.filter(c => c.type == type);
352 filterGames: function(type) {
353 return this.games.filter(g => g.type == type);
355 classifyObject: function(o) {
357 return o.cadence.indexOf("d") === -1 ? "live" : "corr";
359 setDisplay: function(letter, type, e) {
360 this[letter + "display"] = type;
361 localStorage.setItem(
362 "type-" + (letter == "c" ? "challenges" : "games"),
367 : document.getElementById("btn" + letter.toUpperCase() + type);
368 elt.classList.add("active");
369 elt.classList.remove("somethingnew"); //in case of
370 if (elt.previousElementSibling)
371 elt.previousElementSibling.classList.remove("active");
372 else elt.nextElementSibling.classList.remove("active");
374 isGamer: function(sid) {
375 return this.people[sid].pages.some(p => p.indexOf("/game/") >= 0);
377 challenge: function(sid) {
378 // Available, in Hall (only)
379 this.newchallenge.to = this.people[sid].name;
380 document.getElementById("modalPeople").checked = false;
381 window.doClick("modalNewgame");
383 watchGame: function(sid) {
384 // In some game, maybe playing maybe not: show a random one
386 this.people[sid].pages.forEach(p => {
387 const matchGid = p.match(/[a-zA-Z0-9]+$/);
388 if (matchGid) gids.push(matchGid[0]);
390 const gid = gids[Math.floor(Math.random() * gids.length)];
391 const game = this.games.find(g => g.id == gid);
392 if (game) this.showGame(game);
393 else this.$router.push("/game/" + gid); //game vs. me
395 showGame: function(g) {
396 // NOTE: we are an observer, since only games I don't play are shown here
397 // ==> Moves sent by connected remote player(s) if live game
398 let url = "/game/" + g.id;
399 if (g.type == "live")
400 url += "?rid=" + g.rids[Math.floor(Math.random() * g.rids.length)];
401 this.$router.push(url);
403 resetSocialColor: function() {
404 // TODO: this is called twice, once on opening an once on closing
405 document.getElementById("peopleBtn").classList.remove("somethingnew");
407 processChat: function(chat) {
408 this.send("newchat", { data: chat });
410 getOppsid: function(c) {
411 let oppsid = c.from.sid; //may not be defined if corr + offline opp
413 oppsid = Object.keys(this.people).find(
414 sid => this.people[sid].id == c.from.id
420 socketMessageListener: function(msg) {
421 if (!this.conn) return;
422 const data = JSON.parse(msg.data);
424 case "pollclientsandgamers": {
425 // Since people can be both in Hall and Game,
426 // need to track "askIdentity" requests:
427 let identityAsked = {};
428 data.sockIds.forEach(s => {
429 const page = s.page || "/";
430 if (s.sid != this.st.user.sid && !identityAsked[s.sid]) {
431 this.send("askidentity", { target: s.sid, page: page });
432 identityAsked[s.sid] = true;
434 if (!this.people[s.sid])
435 // Do not set name or id: identity unknown yet
436 this.$set(this.people, s.sid, { pages: [page] });
437 else if (this.people[s.sid].pages.indexOf(page) < 0)
438 this.people[s.sid].pages.push(page);
441 this.send("askchallenge", { target: s.sid });
443 else this.send("askgame", { target: s.sid, page: page });
449 const page = data.page || "/";
450 // NOTE: player could have been polled earlier, but might have logged in then
451 // So it's a good idea to ask identity if he was anonymous.
452 // But only ask game / challenge if currently disconnected.
453 if (!this.people[data.from]) {
454 this.$set(this.people, data.from, { pages: [page] });
455 if (data.code == "connect")
456 this.send("askchallenge", { target: data.from });
457 else this.send("askgame", { target: data.from, page: page });
459 // Append page if not already in list
460 if (this.people[data.from].pages.indexOf(page) < 0)
461 this.people[data.from].pages.push(page);
463 if (!this.people[data.from].name && this.people[data.from].id !== 0) {
464 // Identity not known yet
465 this.newConnect[data.from] = true; //for self multi-connects tests
466 this.send("askidentity", { target: data.from, page: page });
471 case "gdisconnect": {
472 // If the user reloads the page twice very quickly (experienced with Firefox),
473 // the first reload won't have time to connect but will trigger a "close" event anyway.
474 // ==> Next check is required.
475 if (!this.people[data.from]) return;
476 // Disconnect means no more tmpIds:
477 if (data.code == "disconnect") {
478 // Remove the live challenge sent by this player:
479 ArrayFun.remove(this.challenges, c => c.from.sid == data.from);
481 // Remove the matching live game if now unreachable
482 const gid = data.page.match(/[a-zA-Z0-9]+$/)[0];
483 const gidx = this.games.findIndex(g => g.id == gid);
485 const game = this.games[gidx];
487 game.type == "live" &&
488 game.rids.length == 1 &&
489 game.rids[0] == data.from
491 this.games.splice(gidx, 1);
495 const page = data.page || "/";
496 ArrayFun.remove(this.people[data.from].pages, p => p == page);
497 if (this.people[data.from].pages.length == 0)
498 this.$delete(this.people, data.from);
502 // I logged in elsewhere:
504 alert(this.st.tr["New connexion detected: tab now offline"]);
506 case "askidentity": {
507 // Request for identification (TODO: anonymous shouldn't need to reply)
509 // Decompose to avoid revealing email
510 name: this.st.user.name,
511 sid: this.st.user.sid,
514 this.send("identity", { data: me, target: data.from });
518 const user = data.data;
519 this.$set(this.people, user.sid, {
522 pages: this.people[user.sid].pages
525 // If I multi-connect, kill current connexion if no mark (I'm older)
527 this.newConnect[user.sid] &&
529 user.id == this.st.user.id &&
530 user.sid != this.st.user.sid
532 if (!this.killed[this.st.user.sid]) {
533 this.send("killme", { sid: this.st.user.sid });
534 this.killed[this.st.user.sid] = true;
538 delete this.newConnect[user.sid];
541 case "askchallenge": {
542 // Send my current live challenge (if any)
543 const cIdx = this.challenges.findIndex(
544 c => c.from.sid == this.st.user.sid && c.type == "live"
547 const c = this.challenges[cIdx];
548 // NOTE: in principle, should only send targeted challenge to the target.
549 // But we may not know yet the identity of the target (just name),
550 // so cannot decide if data.from is the target or not.
551 const myChallenge = {
553 from: this.st.user.sid,
555 randomness: c.randomness,
561 this.send("challenge", { data: myChallenge, target: data.from });
565 case "challenge": //after "askchallenge"
566 case "newchallenge": {
567 // NOTE about next condition: see "askchallenge" case.
568 const chall = data.data;
571 (this.people[chall.from].id > 0 &&
572 (chall.from == this.st.user.sid || chall.to == this.st.user.name))
574 let newChall = Object.assign({}, chall);
575 newChall.type = this.classifyObject(chall);
576 newChall.randomness = chall.randomness;
577 newChall.added = Date.now();
578 let fromValues = Object.assign({}, this.people[chall.from]);
579 delete fromValues["pages"]; //irrelevant in this context
580 newChall.from = Object.assign({ sid: chall.from }, fromValues);
581 newChall.vname = this.getVname(newChall.vid);
582 this.challenges.push(newChall);
584 (newChall.type == "live" && this.cdisplay == "corr") ||
585 (newChall.type == "corr" && this.cdisplay == "live")
588 .getElementById("btnC" + newChall.type)
589 .classList.add("somethingnew");
594 case "refusechallenge": {
595 const cid = data.data;
596 ArrayFun.remove(this.challenges, c => c.id == cid);
597 alert(this.st.tr["Challenge declined"]);
600 case "deletechallenge": {
601 // NOTE: the challenge may be already removed
602 const cid = data.data;
603 ArrayFun.remove(this.challenges, c => c.id == cid);
606 case "game": //individual request
608 // NOTE: it may be live or correspondance
609 const game = data.data;
610 // Ignore games where I play (corr games)
611 if (game.players.every(p =>
612 p.sid != this.st.user.sid || p.id != this.st.user.id))
614 let locGame = this.games.find(g => g.id == game.id);
617 newGame.type = this.classifyObject(game);
618 newGame.vname = this.getVname(game.vid);
620 //if new game from Hall
622 newGame.rids = [game.rid];
623 delete newGame["rid"];
624 this.games.push(newGame);
626 (newGame.type == "live" && this.gdisplay == "corr") ||
627 (newGame.type == "corr" && this.gdisplay == "live")
630 .getElementById("btnG" + newGame.type)
631 .classList.add("somethingnew");
634 // Append rid (if not already in list)
635 if (!locGame.rids.includes(game.rid)) locGame.rids.push(game.rid);
641 let g = this.games.find(g => g.id == data.gid);
642 if (g) g.score = data.score;
646 // New game just started: data contain all information
647 const gameInfo = data.data;
648 if (this.classifyObject(gameInfo) == "live")
649 this.startNewGame(gameInfo);
652 this.st.tr["New correspondance game:"] +
653 " <a href='#/game/" +
659 let modalBox = document.getElementById("modalInfo");
660 modalBox.checked = true;
665 this.newChat = data.data;
666 if (!document.getElementById("modalPeople").checked)
667 document.getElementById("peopleBtn").classList.add("somethingnew");
671 socketCloseListener: function() {
672 if (!this.conn) return;
673 this.conn = new WebSocket(this.connexionString);
674 this.conn.addEventListener("message", this.socketMessageListener);
675 this.conn.addEventListener("close", this.socketCloseListener);
677 // Challenge lifecycle:
678 loadNewchallVariant: async function(cb) {
679 const vname = this.getVname(this.newchallenge.vid);
680 const vModule = await import("@/variants/" + vname + ".js");
681 this.newchallenge.V = vModule.VariantRules;
682 this.newchallenge.vname = vname;
686 trySetNewchallDiag: function() {
687 if (!this.newchallenge.fen) {
688 this.newchallenge.diag = "";
691 // If vid > 0 then the variant is loaded (function above):
692 window.V = this.newchallenge.V;
694 this.newchallenge.vid > 0 &&
695 this.newchallenge.fen &&
696 V.IsGoodFen(this.newchallenge.fen)
698 const parsedFen = V.ParseFen(this.newchallenge.fen);
699 this.newchallenge.diag = getDiagram({
700 position: parsedFen.position,
701 orientation: V.GetOppCol(parsedFen.turn)
705 newChallenge: async function() {
706 if (this.newchallenge.cadence.match(/^[0-9]+$/))
707 this.newchallenge.cadence += "+0"; //assume minutes, no increment
708 const ctype = this.classifyObject(this.newchallenge);
709 // TODO: cadence still unchecked so ctype could be wrong...
711 if (!this.newchallenge.vid)
712 error = this.st.tr["Please select a variant"];
713 else if (ctype == "corr" && this.st.user.id <= 0)
714 error = this.st.tr["Please log in to play correspondance games"];
715 else if (this.newchallenge.to) {
716 if (this.newchallenge.to == this.st.user.name)
717 error = this.st.tr["Self-challenge is forbidden"];
720 Object.values(this.people).every(p => p.name != this.newchallenge.to)
722 error = this.newchallenge.to + " " + this.st.tr["is not online"];
728 window.V = this.newchallenge.V;
729 error = checkChallenge(this.newchallenge);
734 // NOTE: "from" information is not required here
735 let chall = Object.assign({}, this.newchallenge);
737 delete chall["diag"];
738 const finishAddChallenge = cid => {
739 chall.id = cid || "c" + getRandString();
740 // Remove old challenge if any (only one at a time of a given type):
741 const cIdx = this.challenges.findIndex(
743 (c.from.sid == this.st.user.sid || c.from.id == this.st.user.id) &&
747 // Delete current challenge (will be replaced now)
748 this.send("deletechallenge", { data: this.challenges[cIdx].id });
749 if (ctype == "corr") {
750 ajax("/challenges", "DELETE", { id: this.challenges[cIdx].id });
752 this.challenges.splice(cIdx, 1);
754 this.send("newchallenge", {
755 data: Object.assign({ from: this.st.user.sid }, chall)
757 // Add new challenge:
759 // Decompose to avoid revealing email
760 sid: this.st.user.sid,
762 name: this.st.user.name
764 chall.added = Date.now();
765 // NOTE: vname and type are redundant (can be deduced from cadence + vid)
767 chall.vname = this.newchallenge.vname;
768 this.challenges.push(chall);
769 // Remember cadence + vid for quicker further challenges:
770 localStorage.setItem("cadence", chall.cadence);
771 localStorage.setItem("vid", chall.vid);
772 localStorage.setItem("randomness", chall.randomness);
773 document.getElementById("modalNewgame").checked = false;
774 // Show the challenge if not on current display
776 (ctype == "live" && this.cdisplay == "corr") ||
777 (ctype == "corr" && this.cdisplay == "live")
779 this.setDisplay('c', ctype);
782 if (ctype == "live") {
783 // Live challenges have a random ID
784 finishAddChallenge(null);
786 // Correspondance game: send challenge to server
787 ajax("/challenges", "POST", { chall: chall }, response => {
788 finishAddChallenge(response.cid);
792 // Callback function after a diagram was showed to accept
793 // or refuse targetted challenge:
794 decisionChallenge: function(accepted) {
795 this.curChallToAccept.accepted = accepted;
796 this.finishProcessingChallenge(this.curChallToAccept);
797 document.getElementById("modalAccept").checked = false;
799 finishProcessingChallenge: function(c) {
802 // Again, avoid c.seat = st.user to not reveal email
803 sid: this.st.user.sid,
805 name: this.st.user.name
809 const oppsid = this.getOppsid(c);
811 this.send("refusechallenge", { data: c.id, target: oppsid });
813 this.send("deletechallenge", { data: c.id });
815 clickChallenge: async function(c) {
817 c.from.sid == this.st.user.sid || //live
818 (this.st.user.id > 0 && c.from.id == this.st.user.id); //corr
820 if (c.type == "corr" && this.st.user.id <= 0) {
821 alert(this.st.tr["Please log in to accept corr challenges"]);
825 const vModule = await import("@/variants/" + c.vname + ".js");
826 window.V = vModule.VariantRules;
828 // c.to == this.st.user.name (connected)
830 const parsedFen = V.ParseFen(c.fen);
831 c.mycolor = V.GetOppCol(parsedFen.turn);
832 this.tchallDiag = getDiagram({
833 position: parsedFen.position,
834 orientation: c.mycolor
836 this.curChallToAccept = c;
837 document.getElementById("modalAccept").checked = true;
840 if (!confirm(this.st.tr["Accept challenge?"]))
842 this.finishProcessingChallenge(c);
846 this.finishProcessingChallenge(c);
850 if (c.type == "corr") {
851 ajax("/challenges", "DELETE", { id: c.id });
853 this.send("deletechallenge", { data: c.id });
855 // In all cases, the challenge is consumed:
856 ArrayFun.remove(this.challenges, ch => ch.id == c.id);
858 // NOTE: when launching game, the challenge is already being deleted
859 launchGame: function(c) {
860 // These game informations will be shared
863 fen: c.fen || V.GenRandInitFen(c.randomness),
864 // White player index 0, black player index 1:
866 ? (c.mycolor == "w" ? [c.seat, c.from] : [c.from, c.seat])
867 : shuffle([c.from, c.seat]),
871 const notifyNewgame = () => {
872 const oppsid = this.getOppsid(c);
875 this.send("startgame", { data: gameInfo, target: oppsid });
876 // Send game info (only if live) to everyone except me in this tab
877 this.send("newgame", { data: gameInfo });
879 if (c.type == "live") {
881 this.startNewGame(gameInfo);
882 } //corr: game only on server
887 { gameInfo: gameInfo, cid: c.id }, //cid useful to delete challenge
889 gameInfo.id = response.gameId;
891 this.$router.push("/game/" + response.gameId);
896 // NOTE: for live games only (corr games start on the server)
897 startNewGame: function(gameInfo) {
898 const game = Object.assign({}, gameInfo, {
899 // (other) Game infos: constant
900 fenStart: gameInfo.fen,
901 vname: this.getVname(gameInfo.vid),
903 // Game state (including FEN): will be updated
905 clocks: [-1, -1], //-1 = unstarted
906 initime: [0, 0], //initialized later
909 GameStorage.add(game, (err) => {
910 // If an error occurred, game is not added: abort
912 if (this.st.settings.sound)
913 new Audio("/sounds/newgame.flac").play().catch(() => {});
914 this.$router.push("/game/" + gameInfo.id);
922 <style lang="sass" scoped>
930 #newgameDiv > .card, #acceptDiv > .card
934 div#peopleWrap > .card
937 @media screen and (min-width: 1281px)
938 div#peopleWrap > .card
941 @media screen and (max-width: 1280px)
942 div#peopleWrap > .card
945 @media screen and (max-width: 767px)
946 div#peopleWrap > .card
959 @media screen and (max-width: 767px)
978 background-color: #c5fefe !important
981 background-color: #f9faee
984 background-color: lightgreen
986 background-color: red
1003 @media screen and (max-width: 767px)