]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/admin/requests/request-stats/request-stats.component.ts
First version with PostgreSQL
[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 !== null && this.stats.secondsInterval !== null) {
23 clearInterval(this.interval);
24 }
25 }
26
27 getStats() {
28 this.requestService.getStats().subscribe(
29 stats => {
30 this.stats = stats;
31 this.runInterval();
32 },
33
34 err => alert(err.text)
35 );
36 }
37
38 private runInterval() {
39 this.interval = setInterval(() => {
40 this.stats.remainingMilliSeconds -= 1000;
41
42 if (this.stats.remainingMilliSeconds <= 0) {
43 setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100);
44 clearInterval(this.interval);
45 }
46 }, 1000);
47 }
48
49
50 }