Skip to content

Commit

Permalink
Map stats stream (#179)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Iwhite67 authored Apr 9, 2024
1 parent 99e6f9f commit 1072b25
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "g5v",
"version": "1.7.0",
"version": "1.7.1",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
76 changes: 49 additions & 27 deletions src/components/PlayerStatTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export default {
},
created() {
this.useStreamOrStaticData();
this.getMapString();
},
computed: {
headers() {
Expand Down Expand Up @@ -239,8 +238,14 @@ export default {
async useStreamOrStaticData() {
// Template will contain v-rows/etc like on main Team page.
let matchData = await this.GetMatchData(this.match_id);
if (matchData.end_time == null) this.GetMapPlayerStatsStream(matchData);
else this.GetMapPlayerStats(matchData);
if (matchData.end_time == null) {
this.GetMapStatsStream(matchData);
this.GetMapPlayerStatsStream(matchData);
}
else {
this.getMapString(matchData);
this.GetMapPlayerStats(matchData);
}
},
async retrieveStatsHelper(serverResponse, matchData) {
if (typeof serverResponse == "string") return;
Expand Down Expand Up @@ -324,34 +329,51 @@ export default {
}
return;
},
async getMapString() {
async GetMapStatsStream(matchData) {
try {
let mapStats = await this.GetMapStats(this.match_id);
if (typeof mapStats == "string") return;
mapStats.forEach((singleMapStat, index) => {
this.arrMapString[index] = {};
this.arrMapString[index].score =
"Score: " +
singleMapStat.team1_score +
" " +
this.GetScoreSymbol(
singleMapStat.team1_score,
singleMapStat.team2_score
) +
" " +
singleMapStat.team2_score;
this.arrMapString[index].start =
"Map Start: " + new Date(singleMapStat.start_time).toLocaleString();
this.arrMapString[index].end =
singleMapStat.end_time == null
? null
: "Map End: " + new Date(singleMapStat.end_time).toLocaleString();
this.arrMapString[index].map = "Map: " + singleMapStat.map_name;
this.arrMapString[index].demo = singleMapStat.demoFile;
let sseClient = await this.GetEventMapStats(this.match_id);
await sseClient.connect();
await sseClient.on("mapstats", async message => {
await this.retrieveMapStatsHelper(message,matchData);
});
} catch (error) {
console.log("String error " + error);
console.log("Our error: " + error);
} finally {
this.isLoading = false;
}
return;
},
async getMapString(matchData) {
try {
let res = await this.GetMapStats(this.match_id);
await this.retrieveMapStatsHelper(res, matchData);
} catch (error) {
console.log("Our error: " + error);
} finally {
this.isLoading = false;
}
return;
},
async retrieveMapStatsHelper(serverResponse, matchData) {
if (typeof serverResponse == "string") return;
await serverResponse.forEach((singleMapStat, index) => {
this.$set(this.arrMapString[index], 'score', "Score: " +
singleMapStat.team1_score +
" " +
this.GetScoreSymbol(
singleMapStat.team1_score,
singleMapStat.team2_score
) +
" " +
singleMapStat.team2_score);
this.$set(this.arrMapString[index], 'start', "Map Start: " + new Date(singleMapStat.start_time).toLocaleString());
this.$set(this.arrMapString[index], 'end', singleMapStat.end_time == null ?
null :
"Map End: " + new Date(singleMapStat.end_time).toLocaleString());
this.$set(this.arrMapString[index], 'map', "Map: " + singleMapStat.map_name);
this.$set(this.arrMapString[index], 'demo', singleMapStat.demoFile);
});
if (matchData.end_time != null) this.isFinished = true;
}
}
};
Expand Down
13 changes: 13 additions & 0 deletions src/utils/api.vue
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,19 @@ export default {
}
return message;
},
async GetEventMapStats(matchid) {
return this.$sse
.create({
url: `${process.env?.VUE_APP_G5V_API_URL ||
"/api"}/mapstats/${matchid}/stream`,
format: "json",
withCredentials: true,
polyfill: true
})
.on("error", err =>
console.error("Failed to parse or lost connection:", err)
);
},
// END MAP STATS
// BEGIN MATCH ADMIN CALLS
async PauseMatch(matchid) {
Expand Down

0 comments on commit 1072b25

Please sign in to comment.