]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/admin/requests/request-stats/request-stats.component.ts
Client: fix error alert
[github/Chocobozzz/PeerTube.git] / client / src / app / admin / requests / request-stats / request-stats.component.ts
1 import { Component, OnInit, OnDestroy } from '@angular/core';
2
3 import { RequestService, RequestStats } from '../shared';
4
5 @Component({
6 selector: 'my-request-stats',
7 templateUrl: './request-stats.component.html',
8 styleUrls: [ './request-stats.component.scss' ]
9 })
10 export class RequestStatsComponent implements OnInit, OnDestroy {
11 stats: RequestStats = null;
12
13 private interval: NodeJS.Timer = null;
14
15 constructor(private requestService: RequestService) { }
16
17 ngOnInit() {
18 this.getStats();
19 }
20
21 ngOnDestroy() {
22 if (this.stats.secondsInterval !== null) {
23 clearInterval(this.interval);
24 }
25 }
26
27 getStats() {
28 this.requestService.getStats().subscribe(
29 stats => {
30 console.log(stats);
31 this.stats = stats;
32 this.runInterval();
33 },
34
35 err => alert(err.text)
36 );
37 }
38
39 private runInterval() {
40 this.interval = setInterval(() => {
41 this.stats.remainingMilliSeconds -= 1000;
42
43 if (this.stats.remainingMilliSeconds <= 0) {
44 setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100);
45 clearInterval(this.interval);
46 }
47 }, 1000);
48 }
49
50
51 }