- watch: {
- // Watch event "user infos retrieved" (through /whoami)
- "st.user.id": function(newId) {
- if (newId > 0) //should always be the case
- {
- // Ask server for current corr games (all but mines)
- // ajax(
- // "/games",
- // "GET",
- // {excluded: this.st.user.id},
- // response => {
- // this.games = this.games.concat(response.games);
- // }
- // );
- // Also ask for corr challenges (open + sent to me)
- ajax(
- "/challenges",
+ created: function() {
+ // Always add myself to players' list
+ const my = this.st.user;
+ this.people.push({sid:my.sid, id:my.id, name:my.name});
+ // Retrieve live challenge (not older than 30 minute) if any:
+ const chall = JSON.parse(localStorage.getItem("challenge") || "false");
+ if (!!chall)
+ {
+ if ((Date.now() - chall.added)/1000 <= 30*60)
+ this.challenges.push(chall);
+ else
+ localStorage.removeItem("challenge");
+ }
+ // Ask server for current corr games (all but mines)
+ ajax(
+ "/games",
+ "GET",
+ {uid: this.st.user.id, excluded: true},
+ response => {
+ this.games = this.games.concat(response.games.map(g => {
+ const type = this.classifyObject(g);
+ const vname = this.getVname(g.vid);
+ return Object.assign({}, g, {type: type, vname: vname});
+ }));
+ }
+ );
+ // Also ask for corr challenges (open + sent to me)
+ ajax(
+ "/challenges",
+ "GET",
+ {uid: this.st.user.id},
+ response => {
+ // Gather all senders names, and then retrieve full identity:
+ // (TODO [perf]: some might be online...)
+ const uids = response.challenges.map(c => { return c.uid });
+ ajax("/users",