aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/video-watch
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/videos/video-watch')
-rw-r--r--client/src/app/videos/video-watch/video-watch.component.ts38
1 files changed, 21 insertions, 17 deletions
diff --git a/client/src/app/videos/video-watch/video-watch.component.ts b/client/src/app/videos/video-watch/video-watch.component.ts
index 99188bfb3..09255de5d 100644
--- a/client/src/app/videos/video-watch/video-watch.component.ts
+++ b/client/src/app/videos/video-watch/video-watch.component.ts
@@ -1,5 +1,5 @@
1import { Component, ElementRef, OnInit } from '@angular/core'; 1import { Component, ElementRef, OnDestroy, OnInit } from '@angular/core';
2import { CanDeactivate, RouteSegment } from '@angular/router'; 2import { ActivatedRoute } from '@angular/router';
3 3
4import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; 4import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
5 5
@@ -15,7 +15,7 @@ import { WebTorrentService } from './webtorrent.service';
15 pipes: [ BytesPipe ] 15 pipes: [ BytesPipe ]
16}) 16})
17 17
18export class VideoWatchComponent implements OnInit, CanDeactivate { 18export class VideoWatchComponent implements OnInit, OnDestroy {
19 private static LOADTIME_TOO_LONG: number = 30000; 19 private static LOADTIME_TOO_LONG: number = 30000;
20 20
21 downloadSpeed: number; 21 downloadSpeed: number;
@@ -26,11 +26,12 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
26 video: Video; 26 video: Video;
27 27
28 private errorTimer: NodeJS.Timer; 28 private errorTimer: NodeJS.Timer;
29 private sub: any;
29 private torrentInfosInterval: NodeJS.Timer; 30 private torrentInfosInterval: NodeJS.Timer;
30 31
31 constructor( 32 constructor(
32 private elementRef: ElementRef, 33 private elementRef: ElementRef,
33 private routeSegment: RouteSegment, 34 private route: ActivatedRoute,
34 private videoService: VideoService, 35 private videoService: VideoService,
35 private webTorrentService: WebTorrentService 36 private webTorrentService: WebTorrentService
36 ) {} 37 ) {}
@@ -73,22 +74,25 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
73 }); 74 });
74 } 75 }
75 76
76 ngOnInit() { 77 ngOnDestroy() {
77 let id = this.routeSegment.getParam('id');
78 this.videoService.getVideo(id).subscribe(
79 video => {
80 this.video = video;
81 this.loadVideo();
82 },
83 error => alert(error)
84 );
85 }
86
87 routerCanDeactivate() {
88 console.log('Removing video from webtorrent.'); 78 console.log('Removing video from webtorrent.');
89 clearInterval(this.torrentInfosInterval); 79 clearInterval(this.torrentInfosInterval);
90 this.webTorrentService.remove(this.video.magnetUri); 80 this.webTorrentService.remove(this.video.magnetUri);
91 return Promise.resolve(true); 81
82 this.sub.unsubscribe();
83 }
84
85 ngOnInit() {
86 this.sub = this.route.params.subscribe(routeParams => {
87 let id = routeParams['id'];
88 this.videoService.getVideo(id).subscribe(
89 video => {
90 this.video = video;
91 this.loadVideo();
92 },
93 error => alert(error)
94 );
95 });
92 } 96 }
93 97
94 private loadTooLong() { 98 private loadTooLong() {