aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/app/videos/video-watch/video-watch.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/app/videos/video-watch/video-watch.component.ts')
-rw-r--r--client/app/videos/video-watch/video-watch.component.ts19
1 files changed, 8 insertions, 11 deletions
diff --git a/client/app/videos/video-watch/video-watch.component.ts b/client/app/videos/video-watch/video-watch.component.ts
index 137db8f0b..71fb4f634 100644
--- a/client/app/videos/video-watch/video-watch.component.ts
+++ b/client/app/videos/video-watch/video-watch.component.ts
@@ -4,14 +4,13 @@ import { CanDeactivate, ComponentInstruction, RouteParams } from '@angular/route
4import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; 4import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
5 5
6import { LoaderComponent, Video, VideoService } from '../shared/index'; 6import { LoaderComponent, Video, VideoService } from '../shared/index';
7 7import { WebTorrentService } from './webtorrent.service';
8// TODO import it with systemjs
9declare var WebTorrent: any;
10 8
11@Component({ 9@Component({
12 selector: 'my-video-watch', 10 selector: 'my-video-watch',
13 templateUrl: 'client/app/videos/video-watch/video-watch.component.html', 11 templateUrl: 'client/app/videos/video-watch/video-watch.component.html',
14 styleUrls: [ 'client/app/videos/video-watch/video-watch.component.css' ], 12 styleUrls: [ 'client/app/videos/video-watch/video-watch.component.css' ],
13 providers: [ WebTorrentService ],
15 directives: [ LoaderComponent ], 14 directives: [ LoaderComponent ],
16 pipes: [ BytesPipe ] 15 pipes: [ BytesPipe ]
17}) 16})
@@ -23,23 +22,21 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
23 uploadSpeed: number; 22 uploadSpeed: number;
24 video: Video; 23 video: Video;
25 24
26 private client: any;
27 private interval: NodeJS.Timer; 25 private interval: NodeJS.Timer;
28 26
29 constructor( 27 constructor(
30 private elementRef: ElementRef, 28 private elementRef: ElementRef,
31 private routeParams: RouteParams, 29 private routeParams: RouteParams,
32 private videoService: VideoService 30 private videoService: VideoService,
33 ) { 31 private webTorrentService: WebTorrentService
34 // TODO: use a service 32 ) {}
35 this.client = new WebTorrent({ dht: false });
36 }
37 33
38 loadVideo(video: Video) { 34 loadVideo(video: Video) {
39 this.loading = true; 35 this.loading = true;
40 this.video = video; 36 this.video = video;
41 console.log('Adding ' + this.video.magnetUri + '.'); 37 console.log('Adding ' + this.video.magnetUri + '.');
42 this.client.add(this.video.magnetUri, (torrent) => { 38
39 this.webTorrentService.add(this.video.magnetUri, (torrent) => {
43 this.loading = false; 40 this.loading = false;
44 console.log('Added ' + this.video.magnetUri + '.'); 41 console.log('Added ' + this.video.magnetUri + '.');
45 torrent.files[0].appendTo(this.elementRef.nativeElement.querySelector('.embed-responsive'), (err) => { 42 torrent.files[0].appendTo(this.elementRef.nativeElement.querySelector('.embed-responsive'), (err) => {
@@ -69,7 +66,7 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
69 routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) { 66 routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
70 console.log('Removing video from webtorrent.'); 67 console.log('Removing video from webtorrent.');
71 clearInterval(this.interval); 68 clearInterval(this.interval);
72 this.client.remove(this.video.magnetUri); 69 this.webTorrentService.remove(this.video.magnetUri);
73 return true; 70 return true;
74 } 71 }
75} 72}