Skip to content

Commit 1072b25

Browse files
authored
Map stats stream (#179)
* Update ghcr.yml * Create GetMapStatsStream Function * Try PlayerStatTable.vue * Update PlayerStatTable.vue * Update PlayerStatTable.vue * Update PlayerStatTable.vue * Update PlayerStatTable.vue * Update PlayerStatTable.vue * Update PlayerStatTable.vue * test * test * test * fix * fix * soon * test * debug * oups * order ? * await ? * zzz * Debug Day 2 * try 2 * Good !! * fix * Update ghcr.yml * Remove Console.log * Update package.json
1 parent 99e6f9f commit 1072b25

File tree

3 files changed

+63
-28
lines changed

3 files changed

+63
-28
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "g5v",
3-
"version": "1.7.0",
3+
"version": "1.7.1",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",

src/components/PlayerStatTable.vue

+49-27
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ export default {
122122
},
123123
created() {
124124
this.useStreamOrStaticData();
125-
this.getMapString();
126125
},
127126
computed: {
128127
headers() {
@@ -239,8 +238,14 @@ export default {
239238
async useStreamOrStaticData() {
240239
// Template will contain v-rows/etc like on main Team page.
241240
let matchData = await this.GetMatchData(this.match_id);
242-
if (matchData.end_time == null) this.GetMapPlayerStatsStream(matchData);
243-
else this.GetMapPlayerStats(matchData);
241+
if (matchData.end_time == null) {
242+
this.GetMapStatsStream(matchData);
243+
this.GetMapPlayerStatsStream(matchData);
244+
}
245+
else {
246+
this.getMapString(matchData);
247+
this.GetMapPlayerStats(matchData);
248+
}
244249
},
245250
async retrieveStatsHelper(serverResponse, matchData) {
246251
if (typeof serverResponse == "string") return;
@@ -324,34 +329,51 @@ export default {
324329
}
325330
return;
326331
},
327-
async getMapString() {
332+
async GetMapStatsStream(matchData) {
328333
try {
329-
let mapStats = await this.GetMapStats(this.match_id);
330-
if (typeof mapStats == "string") return;
331-
mapStats.forEach((singleMapStat, index) => {
332-
this.arrMapString[index] = {};
333-
this.arrMapString[index].score =
334-
"Score: " +
335-
singleMapStat.team1_score +
336-
" " +
337-
this.GetScoreSymbol(
338-
singleMapStat.team1_score,
339-
singleMapStat.team2_score
340-
) +
341-
" " +
342-
singleMapStat.team2_score;
343-
this.arrMapString[index].start =
344-
"Map Start: " + new Date(singleMapStat.start_time).toLocaleString();
345-
this.arrMapString[index].end =
346-
singleMapStat.end_time == null
347-
? null
348-
: "Map End: " + new Date(singleMapStat.end_time).toLocaleString();
349-
this.arrMapString[index].map = "Map: " + singleMapStat.map_name;
350-
this.arrMapString[index].demo = singleMapStat.demoFile;
334+
let sseClient = await this.GetEventMapStats(this.match_id);
335+
await sseClient.connect();
336+
await sseClient.on("mapstats", async message => {
337+
await this.retrieveMapStatsHelper(message,matchData);
351338
});
352339
} catch (error) {
353-
console.log("String error " + error);
340+
console.log("Our error: " + error);
341+
} finally {
342+
this.isLoading = false;
354343
}
344+
return;
345+
},
346+
async getMapString(matchData) {
347+
try {
348+
let res = await this.GetMapStats(this.match_id);
349+
await this.retrieveMapStatsHelper(res, matchData);
350+
} catch (error) {
351+
console.log("Our error: " + error);
352+
} finally {
353+
this.isLoading = false;
354+
}
355+
return;
356+
},
357+
async retrieveMapStatsHelper(serverResponse, matchData) {
358+
if (typeof serverResponse == "string") return;
359+
await serverResponse.forEach((singleMapStat, index) => {
360+
this.$set(this.arrMapString[index], 'score', "Score: " +
361+
singleMapStat.team1_score +
362+
" " +
363+
this.GetScoreSymbol(
364+
singleMapStat.team1_score,
365+
singleMapStat.team2_score
366+
) +
367+
" " +
368+
singleMapStat.team2_score);
369+
this.$set(this.arrMapString[index], 'start', "Map Start: " + new Date(singleMapStat.start_time).toLocaleString());
370+
this.$set(this.arrMapString[index], 'end', singleMapStat.end_time == null ?
371+
null :
372+
"Map End: " + new Date(singleMapStat.end_time).toLocaleString());
373+
this.$set(this.arrMapString[index], 'map', "Map: " + singleMapStat.map_name);
374+
this.$set(this.arrMapString[index], 'demo', singleMapStat.demoFile);
375+
});
376+
if (matchData.end_time != null) this.isFinished = true;
355377
}
356378
}
357379
};

src/utils/api.vue

+13
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,19 @@ export default {
894894
}
895895
return message;
896896
},
897+
async GetEventMapStats(matchid) {
898+
return this.$sse
899+
.create({
900+
url: `${process.env?.VUE_APP_G5V_API_URL ||
901+
"/api"}/mapstats/${matchid}/stream`,
902+
format: "json",
903+
withCredentials: true,
904+
polyfill: true
905+
})
906+
.on("error", err =>
907+
console.error("Failed to parse or lost connection:", err)
908+
);
909+
},
897910
// END MAP STATS
898911
// BEGIN MATCH ADMIN CALLS
899912
async PauseMatch(matchid) {

0 commit comments

Comments
 (0)