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="isFocusedOnHall(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;
242 pages: [{ path: "/", focus: true }]
245 // Ask server for current corr games (all but mines)
250 data: { uid: this.st.user.id, excluded: true },
251 success: (response) => {
252 this.games = this.games.concat(
253 response.games.map(g => {
254 const type = this.classifyObject(g);
255 const vname = this.getVname(g.vid);
256 return Object.assign({}, g, { type: type, vname: vname });
262 // Also ask for corr challenges (open + sent by/to me)
267 data: { uid: this.st.user.id },
268 success: (response) => {
269 // Gather all senders names, and then retrieve full identity:
270 // (TODO [perf]: some might be online...)
272 response.challenges.forEach(c => {
273 if (c.uid != this.st.user.id) names[c.uid] = "";
274 else if (!!c.target && c.target != this.st.user.id)
275 names[c.target] = "";
277 const addChallenges = () => {
278 names[this.st.user.id] = this.st.user.name; //in case of
279 this.challenges = this.challenges.concat(
280 response.challenges.map(c => {
281 const from = { name: names[c.uid], id: c.uid }; //or just name
282 const type = this.classifyObject(c);
283 const vname = this.getVname(c.vid);
284 return Object.assign(
290 to: c.target ? names[c.target] : ""
297 if (Object.keys(names).length > 0) {
302 data: { ids: Object.keys(names).join(",") },
303 success: (response2) => {
304 response2.users.forEach(u => {
305 names[u.id] = u.name;
311 } else addChallenges();
315 const connectAndPoll = () => {
316 this.send("connect");
317 this.send("pollclientsandgamers");
319 // Initialize connection
320 this.connexionString =
327 // Hall: path is "/" (could be hard-coded as well)
328 encodeURIComponent(this.$route.path);
329 this.conn = new WebSocket(this.connexionString);
330 this.conn.onopen = connectAndPoll;
331 this.conn.onmessage = this.socketMessageListener;
332 this.conn.onclose = this.socketCloseListener;
334 mounted: function() {
335 document.addEventListener('visibilitychange', this.visibilityChange);
336 ["peopleWrap", "infoDiv", "newgameDiv"].forEach(eltName => {
337 let elt = document.getElementById(eltName);
338 elt.addEventListener("click", processModalClick);
340 document.querySelectorAll("#predefinedCadences > button").forEach(b => {
341 b.addEventListener("click", () => {
342 this.newchallenge.cadence = b.innerHTML;
345 const dispCorr = this.$route.query["disp"];
347 dispCorr || localStorage.getItem("type-challenges") || "live";
349 dispCorr || localStorage.getItem("type-games") || "live";
350 this.setDisplay("c", showCtype);
351 this.setDisplay("g", showGtype);
353 beforeDestroy: function() {
354 document.removeEventListener('visibilitychange', this.visibilityChange);
355 this.send("disconnect");
358 visibilityChange: function() {
359 // TODO: Use document.hidden? https://webplatform.news/issues/2019-03-27
361 document.visibilityState == "visible"
367 cadenceFocusIfOpened: function() {
368 if (event.target.checked)
369 document.getElementById("cadence").focus();
371 send: function(code, obj) {
373 this.conn.send(JSON.stringify(Object.assign({ code: code }, obj)));
376 getVname: function(vid) {
377 const variant = this.st.variants.find(v => v.id == vid);
378 // this.st.variants might be uninitialized (variant == null)
379 return variant ? variant.name : "";
381 filterChallenges: function(type) {
382 return this.challenges.filter(c => c.type == type);
384 filterGames: function(type) {
385 return this.games.filter(g => g.type == type);
387 classifyObject: function(o) {
389 return o.cadence.indexOf("d") === -1 ? "live" : "corr";
391 setDisplay: function(letter, type, e) {
392 this[letter + "display"] = type;
393 localStorage.setItem(
394 "type-" + (letter == "c" ? "challenges" : "games"),
399 : document.getElementById("btn" + letter.toUpperCase() + type);
400 elt.classList.add("active");
401 elt.classList.remove("somethingnew"); //in case of
402 if (!!elt.previousElementSibling)
403 elt.previousElementSibling.classList.remove("active");
404 else elt.nextElementSibling.classList.remove("active");
406 isGamer: function(sid) {
407 return this.people[sid].pages
408 .some(p => p.focus && p.path.indexOf("/game/") >= 0);
410 isFocusedOnHall: function(sid) {
412 // This is meant to challenge people, thus the next 2 conditions:
413 this.st.user.id > 0 &&
414 sid != this.st.user.sid &&
415 this.people[sid].pages.some(p => p.path == "/" && p.focus)
418 challenge: function(sid) {
419 // Available, in Hall (only)
420 this.newchallenge.to = this.people[sid].name;
421 document.getElementById("modalPeople").checked = false;
422 window.doClick("modalNewgame");
424 watchGame: function(sid) {
425 // In some game, maybe playing maybe not: show a random one
427 this.people[sid].pages.forEach(p => {
429 const matchGid = p.path.match(/[a-zA-Z0-9]+$/);
430 if (!!matchGid) gids.push(matchGid[0]);
433 const gid = gids[Math.floor(Math.random() * gids.length)];
434 const game = this.games.find(g => g.id == gid);
435 if (!!game) this.showGame(game);
436 else this.$router.push("/game/" + gid); //game vs. me
438 showGame: function(g) {
439 // NOTE: we are an observer, since only games I don't play are shown here
440 // ==> Moves sent by connected remote player(s) if live game
441 let url = "/game/" + g.id;
442 if (g.type == "live")
443 url += "?rid=" + g.rids[Math.floor(Math.random() * g.rids.length)];
444 this.$router.push(url);
446 resetSocialColor: function() {
447 // TODO: this is called twice, once on opening an once on closing
448 document.getElementById("peopleBtn").classList.remove("somethingnew");
450 processChat: function(chat) {
451 this.send("newchat", { data: chat });
453 getOppsid: function(c) {
454 let oppsid = c.from.sid; //may not be defined if corr + offline opp
456 oppsid = Object.keys(this.people).find(
457 sid => this.people[sid].id == c.from.id
463 socketMessageListener: function(msg) {
464 if (!this.conn) return;
465 const data = JSON.parse(msg.data);
467 case "pollclientsandgamers": {
468 // Since people can be both in Hall and Game,
469 // need to track "askIdentity" requests:
470 let identityAsked = {};
471 data.sockIds.forEach(s => {
472 const page = s.page || "/";
473 if (s.sid != this.st.user.sid && !identityAsked[s.sid]) {
474 this.send("askidentity", { target: s.sid, page: page });
475 identityAsked[s.sid] = true;
477 if (!this.people[s.sid]) {
478 // Do not set name or id: identity unknown yet
479 this.people[s.sid] = { pages: [{path: page, focus: true}] };
481 else if (!(this.people[s.sid].pages.find(p => p.path == page)))
482 this.people[s.sid].pages.push({ path: page, focus: true });
485 this.send("askchallenge", { target: s.sid });
487 else this.send("askgame", { target: s.sid, page: page });
493 const page = data.page || "/";
494 // Only ask game / challenge if first connexion:
495 if (!this.people[data.from]) {
496 this.people[data.from] = { pages: [{ path: page, focus: true }] };
497 if (data.code == "connect")
498 this.send("askchallenge", { target: data.from });
499 else this.send("askgame", { target: data.from, page: page });
501 // Append page if not already in list
502 if (!(this.people[data.from].pages.find(p => p.path == page)))
503 this.people[data.from].pages.push({ path: page, focus: true });
505 if (!this.people[data.from].name && this.people[data.from].id !== 0) {
506 // Identity not known yet
507 this.newConnect[data.from] = true; //for self multi-connects tests
508 this.send("askidentity", { target: data.from, page: page });
513 case "gdisconnect": {
514 // If the user reloads the page twice very quickly (experienced with Firefox),
515 // the first reload won't have time to connect but will trigger a "close" event anyway.
516 // ==> Next check is required.
517 if (!this.people[data.from]) return;
518 // Disconnect means no more tmpIds:
519 if (data.code == "disconnect") {
520 // Remove the live challenge sent by this player:
523 c => c.type == "live" && c.from.sid == data.from
526 // Remove the matching live game if now unreachable
527 const gid = data.page.match(/[a-zA-Z0-9]+$/)[0];
528 const gidx = this.games.findIndex(g => g.id == gid);
530 const game = this.games[gidx];
532 game.type == "live" &&
533 game.rids.length == 1 &&
534 game.rids[0] == data.from
536 this.games.splice(gidx, 1);
540 const page = data.page || "/";
541 ArrayFun.remove(this.people[data.from].pages, p => p.path == page);
542 if (this.people[data.from].pages.length == 0)
543 this.$delete(this.people, data.from);
547 // If user reload a page, focus may arrive earlier than connect
548 if (!!this.people[data.from]) {
549 this.people[data.from].pages
550 .find(p => p.path == data.page).focus = true;
551 this.$forceUpdate(); //TODO: shouldn't be required
555 if (!!this.people[data.from]) {
556 this.people[data.from].pages
557 .find(p => p.path == data.page).focus = false;
558 this.$forceUpdate(); //TODO: shouldn't be required
562 // I logged in elsewhere:
564 alert(this.st.tr["New connexion detected: tab now offline"]);
566 case "askidentity": {
567 // Request for identification (TODO: anonymous shouldn't need to reply)
569 // Decompose to avoid revealing email
570 name: this.st.user.name,
571 sid: this.st.user.sid,
574 this.send("identity", { data: me, target: data.from });
578 const user = data.data;
579 let player = this.people[user.sid];
580 // player.pages is already set
582 player.name = user.name;
583 // TODO: this.$set(people, ...) fails. So forceUpdate.
584 // But this shouldn't be like that!
586 // If I multi-connect, kill current connexion if no mark (I'm older)
587 if (this.newConnect[user.sid]) {
590 user.id == this.st.user.id &&
591 user.sid != this.st.user.sid &&
592 !this.killed[this.st.user.sid]
594 this.send("killme", { sid: this.st.user.sid });
595 this.killed[this.st.user.sid] = true;
597 delete this.newConnect[user.sid];
601 case "askchallenge": {
602 // Send my current live challenge (if any)
603 const cIdx = this.challenges.findIndex(
604 c => c.from.sid == this.st.user.sid && c.type == "live"
607 const c = this.challenges[cIdx];
608 // NOTE: in principle, should only send targeted challenge to the target.
609 // But we may not know yet the identity of the target (just name),
610 // so cannot decide if data.from is the target or not.
611 const myChallenge = {
613 from: this.st.user.sid,
615 randomness: c.randomness,
621 this.send("challenge", { data: myChallenge, target: data.from });
625 case "challenge": //after "askchallenge"
626 case "newchallenge": {
627 // NOTE about next condition: see "askchallenge" case.
628 const chall = data.data;
631 (this.people[chall.from].id > 0 &&
632 (chall.from == this.st.user.sid || chall.to == this.st.user.name))
634 let newChall = Object.assign({}, chall);
635 newChall.type = this.classifyObject(chall);
636 newChall.randomness = chall.randomness;
637 newChall.added = Date.now();
638 let fromValues = Object.assign({}, this.people[chall.from]);
639 delete fromValues["pages"]; //irrelevant in this context
640 newChall.from = Object.assign({ sid: chall.from }, fromValues);
641 newChall.vname = this.getVname(newChall.vid);
642 this.challenges.push(newChall);
644 (newChall.type == "live" && this.cdisplay == "corr") ||
645 (newChall.type == "corr" && this.cdisplay == "live")
648 .getElementById("btnC" + newChall.type)
649 .classList.add("somethingnew");
654 case "refusechallenge": {
655 const cid = data.data;
656 ArrayFun.remove(this.challenges, c => c.id == cid);
657 alert(this.st.tr["Challenge declined"]);
660 case "deletechallenge": {
661 // NOTE: the challenge may be already removed
662 const cid = data.data;
663 ArrayFun.remove(this.challenges, c => c.id == cid);
666 case "game": //individual request
668 // NOTE: it may be live or correspondance
669 const game = data.data;
670 // Ignore games where I play (corr games)
671 if (game.players.every(p =>
672 p.sid != this.st.user.sid || p.id != this.st.user.id))
674 let locGame = this.games.find(g => g.id == game.id);
677 newGame.type = this.classifyObject(game);
678 newGame.vname = this.getVname(game.vid);
680 //if new game from Hall
682 newGame.rids = [game.rid];
683 delete newGame["rid"];
684 this.games.push(newGame);
686 (newGame.type == "live" && this.gdisplay == "corr") ||
687 (newGame.type == "corr" && this.gdisplay == "live")
690 .getElementById("btnG" + newGame.type)
691 .classList.add("somethingnew");
694 // Append rid (if not already in list)
695 if (!locGame.rids.includes(game.rid)) locGame.rids.push(game.rid);
701 let g = this.games.find(g => g.id == data.gid);
702 if (!!g) g.score = data.score;
706 // New game just started: data contain all information
707 const gameInfo = data.data;
708 if (this.classifyObject(gameInfo) == "live")
709 this.startNewGame(gameInfo);
712 this.st.tr["New correspondance game:"] +
713 " <a href='#/game/" +
719 let modalBox = document.getElementById("modalInfo");
720 modalBox.checked = true;
725 this.newChat = data.data;
726 if (!document.getElementById("modalPeople").checked)
727 document.getElementById("peopleBtn").classList.add("somethingnew");
731 socketCloseListener: function() {
732 if (!this.conn) return;
733 this.conn = new WebSocket(this.connexionString);
734 this.conn.addEventListener("message", this.socketMessageListener);
735 this.conn.addEventListener("close", this.socketCloseListener);
737 // Challenge lifecycle:
738 loadNewchallVariant: async function(cb) {
739 const vname = this.getVname(this.newchallenge.vid);
740 const vModule = await import("@/variants/" + vname + ".js");
741 this.newchallenge.V = vModule.VariantRules;
742 this.newchallenge.vname = vname;
746 trySetNewchallDiag: function() {
747 if (!this.newchallenge.fen) {
748 this.newchallenge.diag = "";
751 // If vid > 0 then the variant is loaded (function above):
752 window.V = this.newchallenge.V;
754 this.newchallenge.vid > 0 &&
755 !!this.newchallenge.fen &&
756 V.IsGoodFen(this.newchallenge.fen)
758 const parsedFen = V.ParseFen(this.newchallenge.fen);
759 this.newchallenge.diag = getDiagram({
760 position: parsedFen.position,
761 orientation: parsedFen.turn
765 newChallenge: async function() {
766 if (!!(this.newchallenge.cadence.match(/^[0-9]+$/)))
767 this.newchallenge.cadence += "+0"; //assume minutes, no increment
768 const ctype = this.classifyObject(this.newchallenge);
769 // TODO: cadence still unchecked so ctype could be wrong...
771 if (!this.newchallenge.vid)
772 error = this.st.tr["Please select a variant"];
773 else if (ctype == "corr" && this.st.user.id <= 0)
774 error = this.st.tr["Please log in to play correspondance games"];
775 else if (!!this.newchallenge.to) {
776 if (this.newchallenge.to == this.st.user.name)
777 error = this.st.tr["Self-challenge is forbidden"];
780 Object.values(this.people).every(p => p.name != this.newchallenge.to)
782 error = this.newchallenge.to + " " + this.st.tr["is not online"];
788 window.V = this.newchallenge.V;
789 error = checkChallenge(this.newchallenge);
794 // NOTE: "from" information is not required here
795 let chall = Object.assign({}, this.newchallenge);
797 delete chall["diag"];
798 const finishAddChallenge = cid => {
799 chall.id = cid || "c" + getRandString();
800 // Remove old challenge if any (only one at a time of a given type):
801 const cIdx = this.challenges.findIndex(
803 (c.from.sid == this.st.user.sid || c.from.id == this.st.user.id) &&
807 // Delete current challenge (will be replaced now)
808 this.send("deletechallenge", { data: this.challenges[cIdx].id });
809 if (ctype == "corr") {
813 { data: { id: this.challenges[cIdx].id } }
816 this.challenges.splice(cIdx, 1);
818 this.send("newchallenge", {
819 data: Object.assign({ from: this.st.user.sid }, chall)
821 // Add new challenge:
823 // Decompose to avoid revealing email
824 sid: this.st.user.sid,
826 name: this.st.user.name
828 chall.added = Date.now();
829 // NOTE: vname and type are redundant (can be deduced from cadence + vid)
831 chall.vname = this.newchallenge.vname;
832 this.challenges.push(chall);
833 // Remember cadence + vid for quicker further challenges:
834 localStorage.setItem("cadence", chall.cadence);
835 localStorage.setItem("vid", chall.vid);
836 localStorage.setItem("randomness", chall.randomness);
837 document.getElementById("modalNewgame").checked = false;
838 // Show the challenge if not on current display
840 (ctype == "live" && this.cdisplay == "corr") ||
841 (ctype == "corr" && this.cdisplay == "live")
843 this.setDisplay('c', ctype);
846 if (ctype == "live") {
847 // Live challenges have a random ID
848 finishAddChallenge(null);
850 // Correspondance game: send challenge to server
855 data: { chall: chall },
856 success: (response) => {
857 finishAddChallenge(response.cid);
863 // Callback function after a diagram was showed to accept
864 // or refuse targetted challenge:
865 decisionChallenge: function(accepted) {
866 this.curChallToAccept.accepted = accepted;
867 this.finishProcessingChallenge(this.curChallToAccept);
868 document.getElementById("modalAccept").checked = false;
870 finishProcessingChallenge: function(c) {
873 // Again, avoid c.seat = st.user to not reveal email
874 sid: this.st.user.sid,
876 name: this.st.user.name
880 const oppsid = this.getOppsid(c);
882 this.send("refusechallenge", { data: c.id, target: oppsid });
883 if (c.type == "corr") {
887 { data: { id: c.id } }
891 this.send("deletechallenge", { data: c.id });
893 clickChallenge: async function(c) {
895 c.from.sid == this.st.user.sid || //live
896 (this.st.user.id > 0 && c.from.id == this.st.user.id); //corr
898 if (c.type == "corr" && this.st.user.id <= 0) {
899 alert(this.st.tr["Please log in to accept corr challenges"]);
903 const vModule = await import("@/variants/" + c.vname + ".js");
904 window.V = vModule.VariantRules;
906 // c.to == this.st.user.name (connected)
908 const parsedFen = V.ParseFen(c.fen);
909 c.mycolor = V.GetOppCol(parsedFen.turn);
910 this.tchallDiag = getDiagram({
911 position: parsedFen.position,
912 orientation: c.mycolor
914 this.curChallToAccept = c;
915 document.getElementById("modalAccept").checked = true;
918 if (!confirm(this.st.tr["Accept challenge?"]))
920 this.finishProcessingChallenge(c);
924 this.finishProcessingChallenge(c);
928 if (c.type == "corr") {
932 { data: { id: c.id } }
935 this.send("deletechallenge", { data: c.id });
937 // In all cases, the challenge is consumed:
938 ArrayFun.remove(this.challenges, ch => ch.id == c.id);
940 // NOTE: when launching game, the challenge is already being deleted
941 launchGame: function(c) {
942 // These game informations will be shared
945 fen: c.fen || V.GenRandInitFen(c.randomness),
946 // White player index 0, black player index 1:
948 ? (c.mycolor == "w" ? [c.seat, c.from] : [c.from, c.seat])
949 : shuffle([c.from, c.seat]),
953 const notifyNewgame = () => {
954 const oppsid = this.getOppsid(c);
957 this.send("startgame", { data: gameInfo, target: oppsid });
958 // Send game info (only if live) to everyone except me in this tab
959 this.send("newgame", { data: gameInfo });
961 if (c.type == "live") {
963 this.startNewGame(gameInfo);
964 } //corr: game only on server
970 // cid is useful to delete the challenge:
971 data: { gameInfo: gameInfo, cid: c.id },
972 success: (response) => {
973 gameInfo.id = response.gameId;
975 this.$router.push("/game/" + response.gameId);
981 // NOTE: for live games only (corr games start on the server)
982 startNewGame: function(gameInfo) {
983 const game = Object.assign({}, gameInfo, {
984 // (other) Game infos: constant
985 fenStart: gameInfo.fen,
986 vname: this.getVname(gameInfo.vid),
988 // Game state (including FEN): will be updated
990 clocks: [-1, -1], //-1 = unstarted
991 initime: [0, 0], //initialized later
994 GameStorage.add(game, (err) => {
995 // If an error occurred, game is not added: abort
997 if (this.st.settings.sound)
998 new Audio("/sounds/newgame.flac").play().catch(() => {});
999 this.$router.push("/game/" + gameInfo.id);
1007 <style lang="sass" scoped>
1015 #newgameDiv > .card, #acceptDiv > .card
1019 div#peopleWrap > .card
1022 @media screen and (min-width: 1281px)
1023 div#peopleWrap > .card
1026 @media screen and (max-width: 1280px)
1027 div#peopleWrap > .card
1030 @media screen and (max-width: 767px)
1031 div#peopleWrap > .card
1044 @media screen and (max-width: 767px)
1059 button.player-action
1063 background-color: #c5fefe !important
1066 background-color: #f9faee
1069 background-color: lightgreen
1071 background-color: red
1085 // width: 100% required for Firefox
1093 @media screen and (max-width: 767px)