]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/angular/videos/components/watch/videos-watch.component.ts
Angular application :first draft
[github/Chocobozzz/PeerTube.git] / client / angular / videos / components / watch / videos-watch.component.ts
1 /// <reference path='../../../../typings/browser/ambient/webtorrent/webtorrent.d.ts' />
2
3 import { Component, OnInit, ElementRef } from 'angular2/core';
4 import { RouteParams } from 'angular2/router';
5
6 declare var WebTorrent: any;
7
8 import { Video } from '../../models/video';
9 import { VideosService } from '../../services/videos.service';
10
11 @Component({
12 selector: 'my-video-watch',
13 templateUrl: 'app/angular/videos/components/watch/videos-watch.component.html',
14 styleUrls: [ 'app/angular/videos/components/watch/videos-watch.component.css' ]
15 })
16
17 export class VideosWatchComponent {
18 video: Video;
19
20 private client: any;
21
22 constructor(
23 private _videosService: VideosService,
24 private _routeParams: RouteParams,
25 private _elementRef: ElementRef
26 ) {
27 this.client = new WebTorrent({ dht: false });
28 }
29
30 ngOnInit() {
31 let id = this._routeParams.get('id');
32 this._videosService.getVideo(id).subscribe(
33 video => this.loadVideo(video),
34 error => alert(error)
35 );
36 }
37
38 loadVideo(video: Video) {
39 this.video = video;
40
41 this.client.add(this.video.magnetUri, (torrent) => {
42 torrent.files[0].appendTo(this._elementRef.nativeElement, (err) => {
43 if (err) {
44 alert('Cannot append the file.');
45 console.error(err);
46 }
47 })
48 })
49 }
50 }