|
53 | 53 | "
|
54 | 54 | align="left"
|
55 | 55 | >
|
56 |
| - <div class="text-caption" v-if="!isFinished"> |
57 |
| - {{ $t("PlayerStats.RefreshData", { sec: countDownTimer }) }} |
58 |
| - <v-btn |
59 |
| - x-small |
60 |
| - color="secondary" |
61 |
| - @click="refreshStats" |
62 |
| - :disabled="countDownTimer >= 55" |
63 |
| - > |
64 |
| - {{ $t("PlayerStats.RefreshForce") }} |
65 |
| - </v-btn> |
66 |
| - </div> |
67 |
| - <div v-else /> |
68 | 56 | </div>
|
69 | 57 | </v-container>
|
70 | 58 | <v-data-table
|
@@ -127,25 +115,18 @@ export default {
|
127 | 115 | playerstats: [],
|
128 | 116 | isLoading: true,
|
129 | 117 | arrMapString: [{}],
|
130 |
| - playerInterval: -1, |
131 |
| - countDownTimer: 60, |
132 | 118 | allowRefresh: false,
|
133 | 119 | timeoutId: -1,
|
134 | 120 | isFinished: false,
|
135 | 121 | apiUrl: process.env?.VUE_APP_G5V_API_URL || "/api"
|
136 | 122 | };
|
137 | 123 | },
|
| 124 | + sse: { cleanup: true, withCredentials: true, Polyfill: true, forcePolyfill: true }, |
138 | 125 | created() {
|
139 | 126 | // Template will contain v-rows/etc like on main Team page.
|
140 | 127 | this.GetMapPlayerStats();
|
141 | 128 | this.getMapString();
|
142 | 129 | },
|
143 |
| - beforeDestroy() { |
144 |
| - if (!this.isFinished) { |
145 |
| - if (this.timeoutId != -1) clearInterval(this.timeoutId); |
146 |
| - if (this.playerInterval != -1) clearInterval(this.playerInterval); |
147 |
| - } |
148 |
| - }, |
149 | 130 | computed: {
|
150 | 131 | headers() {
|
151 | 132 | return [
|
@@ -258,76 +239,70 @@ export default {
|
258 | 239 | }
|
259 | 240 | },
|
260 | 241 | methods: {
|
| 242 | + async handleMessage(message, tmp) { |
| 243 | + console.log(`Message ${message}, tmp is ${tmp}`); |
| 244 | + }, |
261 | 245 | async GetMapPlayerStats() {
|
262 | 246 | try {
|
263 |
| - let res = await this.GetPlayerStats(this.match_id); |
264 |
| - let getMatchTeamIds = await this.GetMatchData(this.match_id); |
265 |
| - if (typeof res == "string") return; |
266 |
| - let allMapIds = []; |
267 |
| - let totalMatchTeam = []; |
268 |
| - let allTeamIds = []; |
269 |
| - res.filter(item => { |
270 |
| - let i = allMapIds.findIndex(x => x == item.map_id); |
271 |
| - let j = allTeamIds.findIndex(x => x == item.team_id); |
272 |
| - if (i <= -1) allMapIds.push(item.map_id); |
273 |
| - if (j <= -1) allTeamIds.push(item.team_id); |
274 |
| - return null; |
275 |
| - }); |
276 |
| - allMapIds.forEach(map_id => { |
277 |
| - totalMatchTeam.push( |
278 |
| - res.filter(stats => { |
279 |
| - return stats.map_id == map_id; |
280 |
| - }) |
281 |
| - ); |
282 |
| - }); |
283 |
| - this.playerstats = totalMatchTeam; |
284 |
| - await this.playerstats.forEach((matchStats, idx) => { |
285 |
| - matchStats.forEach(async (player, pIdx) => { |
286 |
| - if (player.roundsplayed > 0) { |
287 |
| - let getRating = this.GetRating( |
288 |
| - player.kills, |
289 |
| - player.roundsplayed, |
290 |
| - player.deaths, |
291 |
| - player.k1, |
292 |
| - player.k2, |
293 |
| - player.k3, |
294 |
| - player.k4, |
295 |
| - player.k5 |
296 |
| - ); |
297 |
| - let adr = this.GetADR(player); |
298 |
| - let hsp = this.GetHSP(player); |
299 |
| - let kdr = this.GetKDR(player); |
300 |
| - let fpr = this.GetFPR(player); |
301 |
| - let teamNum = player.team_id == getMatchTeamIds.team1_id ? 1 : 2; |
302 |
| - let newName = |
303 |
| - player.team_id == getMatchTeamIds.team1_id |
304 |
| - ? getMatchTeamIds.team1_string |
305 |
| - : getMatchTeamIds.team2_string; |
306 |
| - this.$set( |
307 |
| - this.playerstats[idx][pIdx], |
308 |
| - "Team", |
309 |
| - teamNum + " " + newName |
310 |
| - ); |
311 |
| - this.$set(this.playerstats[idx][pIdx], "rating", getRating); |
312 |
| - this.$set(this.playerstats[idx][pIdx], "adr", adr); |
313 |
| - this.$set(this.playerstats[idx][pIdx], "hsp", hsp); |
314 |
| - this.$set(this.playerstats[idx][pIdx], "kdr", kdr); |
315 |
| - this.$set(this.playerstats[idx][pIdx], "fpr", fpr); |
316 |
| - } |
| 247 | + let sseClient = await this.GetEventPlayerStats(this.match_id); |
| 248 | + sseClient.on("playerstats", async message => { |
| 249 | + let getMatchTeamIds = await this.GetMatchData(this.match_id); |
| 250 | + if (typeof message == "string") return; |
| 251 | + let allMapIds = []; |
| 252 | + let totalMatchTeam = []; |
| 253 | + let allTeamIds = []; |
| 254 | + message.filter(item => { |
| 255 | + let i = allMapIds.findIndex(x => x == item.map_id); |
| 256 | + let j = allTeamIds.findIndex(x => x == item.team_id); |
| 257 | + if (i <= -1) allMapIds.push(item.map_id); |
| 258 | + if (j <= -1) allTeamIds.push(item.team_id); |
| 259 | + return null; |
317 | 260 | });
|
| 261 | + allMapIds.forEach(map_id => { |
| 262 | + totalMatchTeam.push( |
| 263 | + message.filter(stats => { |
| 264 | + return stats.map_id == map_id; |
| 265 | + }) |
| 266 | + ); |
| 267 | + }); |
| 268 | + this.playerstats = totalMatchTeam; |
| 269 | + await this.playerstats.forEach((matchStats, idx) => { |
| 270 | + matchStats.forEach(async (player, pIdx) => { |
| 271 | + if (player.roundsplayed > 0) { |
| 272 | + let getRating = this.GetRating( |
| 273 | + player.kills, |
| 274 | + player.roundsplayed, |
| 275 | + player.deaths, |
| 276 | + player.k1, |
| 277 | + player.k2, |
| 278 | + player.k3, |
| 279 | + player.k4, |
| 280 | + player.k5 |
| 281 | + ); |
| 282 | + let adr = this.GetADR(player); |
| 283 | + let hsp = this.GetHSP(player); |
| 284 | + let kdr = this.GetKDR(player); |
| 285 | + let fpr = this.GetFPR(player); |
| 286 | + let teamNum = player.team_id == getMatchTeamIds.team1_id ? 1 : 2; |
| 287 | + let newName = |
| 288 | + player.team_id == getMatchTeamIds.team1_id |
| 289 | + ? getMatchTeamIds.team1_string |
| 290 | + : getMatchTeamIds.team2_string; |
| 291 | + this.$set( |
| 292 | + this.playerstats[idx][pIdx], |
| 293 | + "Team", |
| 294 | + teamNum + " " + newName |
| 295 | + ); |
| 296 | + this.$set(this.playerstats[idx][pIdx], "rating", getRating); |
| 297 | + this.$set(this.playerstats[idx][pIdx], "adr", adr); |
| 298 | + this.$set(this.playerstats[idx][pIdx], "hsp", hsp); |
| 299 | + this.$set(this.playerstats[idx][pIdx], "kdr", kdr); |
| 300 | + this.$set(this.playerstats[idx][pIdx], "fpr", fpr); |
| 301 | + } |
| 302 | + }); |
| 303 | + }); |
| 304 | + if (getMatchTeamIds.end_time != null) this.isFinished = true; |
318 | 305 | });
|
319 |
| - if (getMatchTeamIds.end_time != null) this.isFinished = true; |
320 |
| - if (!this.isFinished && this.playerInterval == -1) { |
321 |
| - this.playerInterval = setInterval(async () => { |
322 |
| - this.isLoading = true; |
323 |
| - this.GetMapPlayerStats(); |
324 |
| - this.getMapString(); |
325 |
| - this.countDownTimer = 60; |
326 |
| - }, 60000); |
327 |
| - this.timeoutId = setInterval(() => { |
328 |
| - this.countDownTimer--; |
329 |
| - }, 1000); |
330 |
| - } |
331 | 306 | } catch (error) {
|
332 | 307 | console.log("Our error: " + error);
|
333 | 308 | } finally {
|
@@ -363,23 +338,6 @@ export default {
|
363 | 338 | } catch (error) {
|
364 | 339 | console.log("String error " + error);
|
365 | 340 | }
|
366 |
| - }, |
367 |
| - async refreshStats() { |
368 |
| - clearInterval(this.timeoutId); |
369 |
| - clearInterval(this.playerInterval); |
370 |
| - this.countDownTimer = 60; |
371 |
| - this.playerInterval = setInterval(async () => { |
372 |
| - this.isLoading = true; |
373 |
| - this.GetMapPlayerStats(); |
374 |
| - this.getMapString(); |
375 |
| - this.countDownTimer = 60; |
376 |
| - }, 60000); |
377 |
| - this.timeoutId = setInterval(() => { |
378 |
| - this.countDownTimer--; |
379 |
| - }, 1000); |
380 |
| - this.GetMapPlayerStats(); |
381 |
| - this.getMapString(); |
382 |
| - return; |
383 | 341 | }
|
384 | 342 | }
|
385 | 343 | };
|
|
0 commit comments