diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-06-03 22:08:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-06-03 22:08:03 +0200 |
commit | 4a6995be18b15de1834a39c8921a0e4109671bb6 (patch) | |
tree | b659661cea33687fcc6bd8fc2251cb7a15ab9f9d /client/app/videos/video-watch/video-watch.component.ts | |
parent | 468892541175f9662f8b1b977e819dc1a496f282 (diff) | |
download | PeerTube-4a6995be18b15de1834a39c8921a0e4109671bb6.tar.gz PeerTube-4a6995be18b15de1834a39c8921a0e4109671bb6.tar.zst PeerTube-4a6995be18b15de1834a39c8921a0e4109671bb6.zip |
First draft to use webpack instead of systemjs
Diffstat (limited to 'client/app/videos/video-watch/video-watch.component.ts')
-rw-r--r-- | client/app/videos/video-watch/video-watch.component.ts | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/client/app/videos/video-watch/video-watch.component.ts b/client/app/videos/video-watch/video-watch.component.ts deleted file mode 100644 index 71fb4f634..000000000 --- a/client/app/videos/video-watch/video-watch.component.ts +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
1 | import { Component, ElementRef, OnInit } from '@angular/core'; | ||
2 | import { CanDeactivate, ComponentInstruction, RouteParams } from '@angular/router-deprecated'; | ||
3 | |||
4 | import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; | ||
5 | |||
6 | import { LoaderComponent, Video, VideoService } from '../shared/index'; | ||
7 | import { WebTorrentService } from './webtorrent.service'; | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-video-watch', | ||
11 | templateUrl: 'client/app/videos/video-watch/video-watch.component.html', | ||
12 | styleUrls: [ 'client/app/videos/video-watch/video-watch.component.css' ], | ||
13 | providers: [ WebTorrentService ], | ||
14 | directives: [ LoaderComponent ], | ||
15 | pipes: [ BytesPipe ] | ||
16 | }) | ||
17 | |||
18 | export class VideoWatchComponent implements OnInit, CanDeactivate { | ||
19 | downloadSpeed: number; | ||
20 | loading: boolean = false; | ||
21 | numPeers: number; | ||
22 | uploadSpeed: number; | ||
23 | video: Video; | ||
24 | |||
25 | private interval: NodeJS.Timer; | ||
26 | |||
27 | constructor( | ||
28 | private elementRef: ElementRef, | ||
29 | private routeParams: RouteParams, | ||
30 | private videoService: VideoService, | ||
31 | private webTorrentService: WebTorrentService | ||
32 | ) {} | ||
33 | |||
34 | loadVideo(video: Video) { | ||
35 | this.loading = true; | ||
36 | this.video = video; | ||
37 | console.log('Adding ' + this.video.magnetUri + '.'); | ||
38 | |||
39 | this.webTorrentService.add(this.video.magnetUri, (torrent) => { | ||
40 | this.loading = false; | ||
41 | console.log('Added ' + this.video.magnetUri + '.'); | ||
42 | torrent.files[0].appendTo(this.elementRef.nativeElement.querySelector('.embed-responsive'), (err) => { | ||
43 | if (err) { | ||
44 | alert('Cannot append the file.'); | ||
45 | console.error(err); | ||
46 | } | ||
47 | }); | ||
48 | |||
49 | // Refresh each second | ||
50 | this.interval = setInterval(() => { | ||
51 | this.downloadSpeed = torrent.downloadSpeed; | ||
52 | this.numPeers = torrent.numPeers; | ||
53 | this.uploadSpeed = torrent.uploadSpeed; | ||
54 | }, 1000); | ||
55 | }); | ||
56 | } | ||
57 | |||
58 | ngOnInit() { | ||
59 | let id = this.routeParams.get('id'); | ||
60 | this.videoService.getVideo(id).subscribe( | ||
61 | video => this.loadVideo(video), | ||
62 | error => alert(error) | ||
63 | ); | ||
64 | } | ||
65 | |||
66 | routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) { | ||
67 | console.log('Removing video from webtorrent.'); | ||
68 | clearInterval(this.interval); | ||
69 | this.webTorrentService.remove(this.video.magnetUri); | ||
70 | return true; | ||
71 | } | ||
72 | } | ||