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)")
21 span {{ st.tr["Accept challenge?"] }}
22 button.refuseBtn(@click="decisionChallenge(false)")
23 span {{ st.tr["Refuse"] }}
24 input#modalNewgame.modal(
26 @change="cadenceFocusIfOpened($event)"
30 data-checkbox="modalNewgame"
33 label#closeNewgame.modal-close(for="modalNewgame")
34 div(@keyup.enter="newChallenge()")
36 label(for="selectVariant") {{ st.tr["Variant"] }} *
38 @change="loadNewchallVariant(trySetNewchallDiag)"
39 v-model="newchallenge.vid"
42 v-for="v in st.variants"
44 :selected="newchallenge.vid==v.id"
48 label(for="cadence") {{ st.tr["Cadence"] }} *
49 div#predefinedCadences
50 button(type="button") 15+5
51 button(type="button") 45+30
52 button(type="button") 3d
53 button(type="button") 7d
56 v-model="newchallenge.cadence"
57 placeholder="5+0, 1h+30s, 5d ..."
60 label(for="selectRandomLevel") {{ st.tr["Randomness"] }} *
61 select#selectRandomLevel(v-model="newchallenge.randomness")
62 option(value="0") {{ st.tr["Deterministic"] }}
63 option(value="1") {{ st.tr["Symmetric random"] }}
64 option(value="2") {{ st.tr["Asymmetric random"] }}
65 fieldset(v-if="st.user.id > 0")
66 label(for="selectPlayers") {{ st.tr["Play with?"] }}
69 v-model="newchallenge.to"
71 fieldset(v-if="st.user.id > 0 && newchallenge.to.length > 0")
74 @input="trySetNewchallDiag()"
76 v-model="newchallenge.fen"
78 .diagram(v-html="newchallenge.diag")
79 button(@click="newChallenge()") {{ st.tr["Send challenge"] }}
80 input#modalPeople.modal(
82 @click="resetSocialColor()"
86 data-checkbox="modalPeople"
89 label.modal-close(for="modalPeople")
93 v-for="sid in Object.keys(people)"
94 v-if="!!people[sid].name"
96 span {{ people[sid].name }}
99 @click="watchGame(sid)"
101 | {{ st.tr["Observe"] }}
102 button.player-action(
103 v-else-if="st.user.id > 0 && sid != st.user.sid"
104 @click="challenge(sid)"
106 | {{ st.tr["Challenge"] }}
107 p.anonymous @nonymous ({{ anonymousCount }})
111 @mychat="processChat"
116 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
118 button#peopleBtn(onClick="window.doClick('modalPeople')")
119 | {{ st.tr["Who's there?"] }}
120 button(onClick="window.doClick('modalNewgame')")
121 | {{ st.tr["New game"] }}
123 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
126 button.tabbtn#btnClive(@click="setDisplay('c','live',$event)")
127 | {{ st.tr["Live challenges"] }}
128 button.tabbtn#btnCcorr(@click="setDisplay('c','corr',$event)")
129 | {{ st.tr["Correspondance challenges"] }}
131 v-show="cdisplay=='live'"
132 :challenges="filterChallenges('live')"
133 @click-challenge="clickChallenge"
136 v-show="cdisplay=='corr'"
137 :challenges="filterChallenges('corr')"
138 @click-challenge="clickChallenge"
142 button.tabbtn#btnGlive(@click="setDisplay('g','live',$event)")
143 | {{ st.tr["Live games"] }}
144 button.tabbtn#btnGcorr(@click="setDisplay('g','corr',$event)")
145 | {{ st.tr["Correspondance games"] }}
147 v-show="gdisplay=='live'"
148 :games="filterGames('live')"
150 @show-game="showGame"
153 v-show="gdisplay=='corr'"
154 :games="filterGames('corr')"
156 @show-game="showGame"
161 import { store } from "@/store";
162 import { checkChallenge } from "@/data/challengeCheck";
163 import { ArrayFun } from "@/utils/array";
164 import { ajax } from "@/utils/ajax";
165 import params from "@/parameters";
166 import { getRandString, shuffle } from "@/utils/alea";
167 import { getDiagram } from "@/utils/printDiagram";
168 import Chat from "@/components/Chat.vue";
169 import GameList from "@/components/GameList.vue";
170 import ChallengeList from "@/components/ChallengeList.vue";
171 import { GameStorage } from "@/utils/gameStorage";
172 import { processModalClick } from "@/utils/modalClick";
183 cdisplay: "live", //or corr
191 vid: parseInt(localStorage.getItem("vid")) || 0,
192 to: "", //name of challenged player (if any)
193 cadence: localStorage.getItem("cadence") || "",
194 randomness: parseInt(localStorage.getItem("randomness")) || 2,
195 // VariantRules object, stored to not interfere with
196 // diagrams of targetted challenges:
199 diag: "" //visualizing FEN
202 curChallToAccept: {from: {}},
206 // Related to (killing of) self multi-connects:
212 // st.variants changes only once, at loading from [] to [...]
213 "st.variants": function() {
214 // Set potential challenges and games variant names:
215 this.challenges.concat(this.games).forEach(o => {
216 if (!o.vname) o.vname = this.getVname(o.vid);
218 if (!this.newchallenge.V && this.newchallenge.vid > 0)
219 this.loadNewchallVariant();
223 anonymousCount: function() {
225 Object.values(this.people).forEach(p => {
226 // Do not cound people who did not send their identity yet:
227 count += (!p.name && p.id === 0) ? 1 : 0;
232 created: function() {
233 if (this.st.variants.length > 0 && this.newchallenge.vid > 0)
234 this.loadNewchallVariant();
235 const my = this.st.user;
236 this.$set(this.people, my.sid, { id: my.id, name: my.name, pages: ["/"] });
237 // Ask server for current corr games (all but mines)
241 { uid: this.st.user.id, excluded: true },
243 this.games = this.games.concat(
244 response.games.map(g => {
245 const type = this.classifyObject(g);
246 const vname = this.getVname(g.vid);
247 return Object.assign({}, g, { type: type, vname: vname });
252 // Also ask for corr challenges (open + sent by/to me)
253 ajax("/challenges", "GET", { uid: this.st.user.id }, response => {
254 // Gather all senders names, and then retrieve full identity:
255 // (TODO [perf]: some might be online...)
257 response.challenges.forEach(c => {
258 if (c.uid != this.st.user.id) names[c.uid] = "";
259 else if (!!c.target && c.target != this.st.user.id)
260 names[c.target] = "";
262 const addChallenges = () => {
263 names[this.st.user.id] = this.st.user.name; //in case of
264 this.challenges = this.challenges.concat(
265 response.challenges.map(c => {
266 const from = { name: names[c.uid], id: c.uid }; //or just name
267 const type = this.classifyObject(c);
268 const vname = this.getVname(c.vid);
269 return Object.assign(
275 to: c.target ? names[c.target] : ""
282 if (Object.keys(names).length > 0) {
286 { ids: Object.keys(names).join(",") },
288 response2.users.forEach(u => {
289 names[u.id] = u.name;
294 } else addChallenges();
296 const connectAndPoll = () => {
297 this.send("connect");
298 this.send("pollclientsandgamers");
300 // Initialize connection
301 this.connexionString =
308 // Hall: path is "/" (could be hard-coded as well)
309 encodeURIComponent(this.$route.path);
310 this.conn = new WebSocket(this.connexionString);
311 this.conn.onopen = connectAndPoll;
312 this.conn.onmessage = this.socketMessageListener;
313 this.conn.onclose = this.socketCloseListener;
315 mounted: function() {
316 ["peopleWrap", "infoDiv", "newgameDiv"].forEach(eltName => {
317 let elt = document.getElementById(eltName);
318 elt.addEventListener("click", processModalClick);
320 document.querySelectorAll("#predefinedCadences > button").forEach(b => {
321 b.addEventListener("click", () => {
322 this.newchallenge.cadence = b.innerHTML;
325 const dispCorr = this.$route.query["disp"];
327 dispCorr || localStorage.getItem("type-challenges") || "live";
329 dispCorr || localStorage.getItem("type-games") || "live";
330 this.setDisplay("c", showCtype);
331 this.setDisplay("g", showGtype);
333 beforeDestroy: function() {
334 this.send("disconnect");
338 cadenceFocusIfOpened: function() {
339 if (event.target.checked)
340 document.getElementById("cadence").focus();
342 send: function(code, obj) {
344 this.conn.send(JSON.stringify(Object.assign({ code: code }, obj)));
347 getVname: function(vid) {
348 const variant = this.st.variants.find(v => v.id == vid);
349 // this.st.variants might be uninitialized (variant == null)
350 return variant ? variant.name : "";
352 filterChallenges: function(type) {
353 return this.challenges.filter(c => c.type == type);
355 filterGames: function(type) {
356 return this.games.filter(g => g.type == type);
358 classifyObject: function(o) {
360 return o.cadence.indexOf("d") === -1 ? "live" : "corr";
362 setDisplay: function(letter, type, e) {
363 this[letter + "display"] = type;
364 localStorage.setItem(
365 "type-" + (letter == "c" ? "challenges" : "games"),
370 : document.getElementById("btn" + letter.toUpperCase() + type);
371 elt.classList.add("active");
372 elt.classList.remove("somethingnew"); //in case of
373 if (!!elt.previousElementSibling)
374 elt.previousElementSibling.classList.remove("active");
375 else elt.nextElementSibling.classList.remove("active");
377 isGamer: function(sid) {
378 return this.people[sid].pages.some(p => p.indexOf("/game/") >= 0);
380 challenge: function(sid) {
381 // Available, in Hall (only)
382 this.newchallenge.to = this.people[sid].name;
383 document.getElementById("modalPeople").checked = false;
384 window.doClick("modalNewgame");
386 watchGame: function(sid) {
387 // In some game, maybe playing maybe not: show a random one
389 this.people[sid].pages.forEach(p => {
390 const matchGid = p.match(/[a-zA-Z0-9]+$/);
391 if (!!matchGid) gids.push(matchGid[0]);
393 const gid = gids[Math.floor(Math.random() * gids.length)];
394 const game = this.games.find(g => g.id == gid);
395 if (!!game) this.showGame(game);
396 else this.$router.push("/game/" + gid); //game vs. me
398 showGame: function(g) {
399 // NOTE: we are an observer, since only games I don't play are shown here
400 // ==> Moves sent by connected remote player(s) if live game
401 let url = "/game/" + g.id;
402 if (g.type == "live")
403 url += "?rid=" + g.rids[Math.floor(Math.random() * g.rids.length)];
404 this.$router.push(url);
406 resetSocialColor: function() {
407 // TODO: this is called twice, once on opening an once on closing
408 document.getElementById("peopleBtn").classList.remove("somethingnew");
410 processChat: function(chat) {
411 this.send("newchat", { data: chat });
413 getOppsid: function(c) {
414 let oppsid = c.from.sid; //may not be defined if corr + offline opp
416 oppsid = Object.keys(this.people).find(
417 sid => this.people[sid].id == c.from.id
423 socketMessageListener: function(msg) {
424 if (!this.conn) return;
425 const data = JSON.parse(msg.data);
427 case "pollclientsandgamers": {
428 // Since people can be both in Hall and Game,
429 // need to track "askIdentity" requests:
430 let identityAsked = {};
431 data.sockIds.forEach(s => {
432 const page = s.page || "/";
433 if (s.sid != this.st.user.sid && !identityAsked[s.sid]) {
434 this.send("askidentity", { target: s.sid, page: page });
435 identityAsked[s.sid] = true;
437 if (!this.people[s.sid])
438 // Do not set name or id: identity unknown yet
439 this.$set(this.people, s.sid, { pages: [page] });
440 else if (this.people[s.sid].pages.indexOf(page) < 0)
441 this.people[s.sid].pages.push(page);
444 this.send("askchallenge", { target: s.sid });
446 else this.send("askgame", { target: s.sid, page: page });
452 const page = data.page || "/";
453 // NOTE: player could have been polled earlier, but might have logged in then
454 // So it's a good idea to ask identity if he was anonymous.
455 // But only ask game / challenge if currently disconnected.
456 if (!this.people[data.from]) {
457 this.$set(this.people, data.from, { pages: [page] });
458 if (data.code == "connect")
459 this.send("askchallenge", { target: data.from });
460 else this.send("askgame", { target: data.from, page: page });
462 // Append page if not already in list
463 if (this.people[data.from].pages.indexOf(page) < 0)
464 this.people[data.from].pages.push(page);
466 if (!this.people[data.from].name && this.people[data.from].id !== 0) {
467 // Identity not known yet
468 this.newConnect[data.from] = true; //for self multi-connects tests
469 this.send("askidentity", { target: data.from, page: page });
474 case "gdisconnect": {
475 // If the user reloads the page twice very quickly (experienced with Firefox),
476 // the first reload won't have time to connect but will trigger a "close" event anyway.
477 // ==> Next check is required.
478 if (!this.people[data.from]) return;
479 // Disconnect means no more tmpIds:
480 if (data.code == "disconnect") {
481 // Remove the live challenge sent by this player:
484 c => c.type == "live" && c.from.sid == data.from
487 // Remove the matching live game if now unreachable
488 const gid = data.page.match(/[a-zA-Z0-9]+$/)[0];
489 const gidx = this.games.findIndex(g => g.id == gid);
491 const game = this.games[gidx];
493 game.type == "live" &&
494 game.rids.length == 1 &&
495 game.rids[0] == data.from
497 this.games.splice(gidx, 1);
501 const page = data.page || "/";
502 ArrayFun.remove(this.people[data.from].pages, p => p == page);
503 if (this.people[data.from].pages.length == 0)
504 this.$delete(this.people, data.from);
508 // I logged in elsewhere:
510 alert(this.st.tr["New connexion detected: tab now offline"]);
512 case "askidentity": {
513 // Request for identification (TODO: anonymous shouldn't need to reply)
515 // Decompose to avoid revealing email
516 name: this.st.user.name,
517 sid: this.st.user.sid,
520 this.send("identity", { data: me, target: data.from });
524 const user = data.data;
525 this.$set(this.people, user.sid, {
528 pages: this.people[user.sid].pages
530 // If I multi-connect, kill current connexion if no mark (I'm older)
531 if (this.newConnect[user.sid]) {
534 user.id == this.st.user.id &&
535 user.sid != this.st.user.sid &&
536 !this.killed[this.st.user.sid]
538 this.send("killme", { sid: this.st.user.sid });
539 this.killed[this.st.user.sid] = true;
541 delete this.newConnect[user.sid];
545 case "askchallenge": {
546 // Send my current live challenge (if any)
547 const cIdx = this.challenges.findIndex(
548 c => c.from.sid == this.st.user.sid && c.type == "live"
551 const c = this.challenges[cIdx];
552 // NOTE: in principle, should only send targeted challenge to the target.
553 // But we may not know yet the identity of the target (just name),
554 // so cannot decide if data.from is the target or not.
555 const myChallenge = {
557 from: this.st.user.sid,
559 randomness: c.randomness,
565 this.send("challenge", { data: myChallenge, target: data.from });
569 case "challenge": //after "askchallenge"
570 case "newchallenge": {
571 // NOTE about next condition: see "askchallenge" case.
572 const chall = data.data;
575 (this.people[chall.from].id > 0 &&
576 (chall.from == this.st.user.sid || chall.to == this.st.user.name))
578 let newChall = Object.assign({}, chall);
579 newChall.type = this.classifyObject(chall);
580 newChall.randomness = chall.randomness;
581 newChall.added = Date.now();
582 let fromValues = Object.assign({}, this.people[chall.from]);
583 delete fromValues["pages"]; //irrelevant in this context
584 newChall.from = Object.assign({ sid: chall.from }, fromValues);
585 newChall.vname = this.getVname(newChall.vid);
586 this.challenges.push(newChall);
588 (newChall.type == "live" && this.cdisplay == "corr") ||
589 (newChall.type == "corr" && this.cdisplay == "live")
592 .getElementById("btnC" + newChall.type)
593 .classList.add("somethingnew");
598 case "refusechallenge": {
599 const cid = data.data;
600 ArrayFun.remove(this.challenges, c => c.id == cid);
601 alert(this.st.tr["Challenge declined"]);
604 case "deletechallenge": {
605 // NOTE: the challenge may be already removed
606 const cid = data.data;
607 ArrayFun.remove(this.challenges, c => c.id == cid);
610 case "game": //individual request
612 // NOTE: it may be live or correspondance
613 const game = data.data;
614 // Ignore games where I play (corr games)
615 if (game.players.every(p =>
616 p.sid != this.st.user.sid || p.id != this.st.user.id))
618 let locGame = this.games.find(g => g.id == game.id);
621 newGame.type = this.classifyObject(game);
622 newGame.vname = this.getVname(game.vid);
624 //if new game from Hall
626 newGame.rids = [game.rid];
627 delete newGame["rid"];
628 this.games.push(newGame);
630 (newGame.type == "live" && this.gdisplay == "corr") ||
631 (newGame.type == "corr" && this.gdisplay == "live")
634 .getElementById("btnG" + newGame.type)
635 .classList.add("somethingnew");
638 // Append rid (if not already in list)
639 if (!locGame.rids.includes(game.rid)) locGame.rids.push(game.rid);
645 let g = this.games.find(g => g.id == data.gid);
646 if (!!g) g.score = data.score;
650 // New game just started: data contain all information
651 const gameInfo = data.data;
652 if (this.classifyObject(gameInfo) == "live")
653 this.startNewGame(gameInfo);
656 this.st.tr["New correspondance game:"] +
657 " <a href='#/game/" +
663 let modalBox = document.getElementById("modalInfo");
664 modalBox.checked = true;
669 this.newChat = data.data;
670 if (!document.getElementById("modalPeople").checked)
671 document.getElementById("peopleBtn").classList.add("somethingnew");
675 socketCloseListener: function() {
676 if (!this.conn) return;
677 this.conn = new WebSocket(this.connexionString);
678 this.conn.addEventListener("message", this.socketMessageListener);
679 this.conn.addEventListener("close", this.socketCloseListener);
681 // Challenge lifecycle:
682 loadNewchallVariant: async function(cb) {
683 const vname = this.getVname(this.newchallenge.vid);
684 const vModule = await import("@/variants/" + vname + ".js");
685 this.newchallenge.V = vModule.VariantRules;
686 this.newchallenge.vname = vname;
690 trySetNewchallDiag: function() {
691 if (!this.newchallenge.fen) {
692 this.newchallenge.diag = "";
695 // If vid > 0 then the variant is loaded (function above):
696 window.V = this.newchallenge.V;
698 this.newchallenge.vid > 0 &&
699 !!this.newchallenge.fen &&
700 V.IsGoodFen(this.newchallenge.fen)
702 const parsedFen = V.ParseFen(this.newchallenge.fen);
703 this.newchallenge.diag = getDiagram({
704 position: parsedFen.position,
705 orientation: parsedFen.turn
709 newChallenge: async function() {
710 if (!!(this.newchallenge.cadence.match(/^[0-9]+$/)))
711 this.newchallenge.cadence += "+0"; //assume minutes, no increment
712 const ctype = this.classifyObject(this.newchallenge);
713 // TODO: cadence still unchecked so ctype could be wrong...
715 if (!this.newchallenge.vid)
716 error = this.st.tr["Please select a variant"];
717 else if (ctype == "corr" && this.st.user.id <= 0)
718 error = this.st.tr["Please log in to play correspondance games"];
719 else if (!!this.newchallenge.to) {
720 if (this.newchallenge.to == this.st.user.name)
721 error = this.st.tr["Self-challenge is forbidden"];
724 Object.values(this.people).every(p => p.name != this.newchallenge.to)
726 error = this.newchallenge.to + " " + this.st.tr["is not online"];
732 window.V = this.newchallenge.V;
733 error = checkChallenge(this.newchallenge);
738 // NOTE: "from" information is not required here
739 let chall = Object.assign({}, this.newchallenge);
741 delete chall["diag"];
742 const finishAddChallenge = cid => {
743 chall.id = cid || "c" + getRandString();
744 // Remove old challenge if any (only one at a time of a given type):
745 const cIdx = this.challenges.findIndex(
747 (c.from.sid == this.st.user.sid || c.from.id == this.st.user.id) &&
751 // Delete current challenge (will be replaced now)
752 this.send("deletechallenge", { data: this.challenges[cIdx].id });
753 if (ctype == "corr") {
754 ajax("/challenges", "DELETE", { id: this.challenges[cIdx].id });
756 this.challenges.splice(cIdx, 1);
758 this.send("newchallenge", {
759 data: Object.assign({ from: this.st.user.sid }, chall)
761 // Add new challenge:
763 // Decompose to avoid revealing email
764 sid: this.st.user.sid,
766 name: this.st.user.name
768 chall.added = Date.now();
769 // NOTE: vname and type are redundant (can be deduced from cadence + vid)
771 chall.vname = this.newchallenge.vname;
772 this.challenges.push(chall);
773 // Remember cadence + vid for quicker further challenges:
774 localStorage.setItem("cadence", chall.cadence);
775 localStorage.setItem("vid", chall.vid);
776 localStorage.setItem("randomness", chall.randomness);
777 document.getElementById("modalNewgame").checked = false;
778 // Show the challenge if not on current display
780 (ctype == "live" && this.cdisplay == "corr") ||
781 (ctype == "corr" && this.cdisplay == "live")
783 this.setDisplay('c', ctype);
786 if (ctype == "live") {
787 // Live challenges have a random ID
788 finishAddChallenge(null);
790 // Correspondance game: send challenge to server
791 ajax("/challenges", "POST", { chall: chall }, response => {
792 finishAddChallenge(response.cid);
796 // Callback function after a diagram was showed to accept
797 // or refuse targetted challenge:
798 decisionChallenge: function(accepted) {
799 this.curChallToAccept.accepted = accepted;
800 this.finishProcessingChallenge(this.curChallToAccept);
801 document.getElementById("modalAccept").checked = false;
803 finishProcessingChallenge: function(c) {
806 // Again, avoid c.seat = st.user to not reveal email
807 sid: this.st.user.sid,
809 name: this.st.user.name
813 const oppsid = this.getOppsid(c);
815 this.send("refusechallenge", { data: c.id, target: oppsid });
816 if (c.type == "corr")
817 ajax("/challenges", "DELETE", { id: c.id });
819 this.send("deletechallenge", { data: c.id });
821 clickChallenge: async function(c) {
823 c.from.sid == this.st.user.sid || //live
824 (this.st.user.id > 0 && c.from.id == this.st.user.id); //corr
826 if (c.type == "corr" && this.st.user.id <= 0) {
827 alert(this.st.tr["Please log in to accept corr challenges"]);
831 const vModule = await import("@/variants/" + c.vname + ".js");
832 window.V = vModule.VariantRules;
834 // c.to == this.st.user.name (connected)
836 const parsedFen = V.ParseFen(c.fen);
837 c.mycolor = V.GetOppCol(parsedFen.turn);
838 this.tchallDiag = getDiagram({
839 position: parsedFen.position,
840 orientation: c.mycolor
842 this.curChallToAccept = c;
843 document.getElementById("modalAccept").checked = true;
846 if (!confirm(this.st.tr["Accept challenge?"]))
848 this.finishProcessingChallenge(c);
852 this.finishProcessingChallenge(c);
856 if (c.type == "corr")
857 ajax("/challenges", "DELETE", { id: c.id });
858 this.send("deletechallenge", { data: c.id });
860 // In all cases, the challenge is consumed:
861 ArrayFun.remove(this.challenges, ch => ch.id == c.id);
863 // NOTE: when launching game, the challenge is already being deleted
864 launchGame: function(c) {
865 // These game informations will be shared
868 fen: c.fen || V.GenRandInitFen(c.randomness),
869 // White player index 0, black player index 1:
871 ? (c.mycolor == "w" ? [c.seat, c.from] : [c.from, c.seat])
872 : shuffle([c.from, c.seat]),
876 const notifyNewgame = () => {
877 const oppsid = this.getOppsid(c);
880 this.send("startgame", { data: gameInfo, target: oppsid });
881 // Send game info (only if live) to everyone except me in this tab
882 this.send("newgame", { data: gameInfo });
884 if (c.type == "live") {
886 this.startNewGame(gameInfo);
887 } //corr: game only on server
892 { gameInfo: gameInfo, cid: c.id }, //cid useful to delete challenge
894 gameInfo.id = response.gameId;
896 this.$router.push("/game/" + response.gameId);
901 // NOTE: for live games only (corr games start on the server)
902 startNewGame: function(gameInfo) {
903 const game = Object.assign({}, gameInfo, {
904 // (other) Game infos: constant
905 fenStart: gameInfo.fen,
906 vname: this.getVname(gameInfo.vid),
908 // Game state (including FEN): will be updated
910 clocks: [-1, -1], //-1 = unstarted
911 initime: [0, 0], //initialized later
914 GameStorage.add(game, (err) => {
915 // If an error occurred, game is not added: abort
917 if (this.st.settings.sound)
918 new Audio("/sounds/newgame.flac").play().catch(() => {});
919 this.$router.push("/game/" + gameInfo.id);
927 <style lang="sass" scoped>
935 #newgameDiv > .card, #acceptDiv > .card
939 div#peopleWrap > .card
942 @media screen and (min-width: 1281px)
943 div#peopleWrap > .card
946 @media screen and (max-width: 1280px)
947 div#peopleWrap > .card
950 @media screen and (max-width: 767px)
951 div#peopleWrap > .card
964 @media screen and (max-width: 767px)
983 background-color: #c5fefe !important
986 background-color: #f9faee
989 background-color: lightgreen
991 background-color: red
1005 // width: 100% required for Firefox
1013 @media screen and (max-width: 767px)