1 /// <reference path='../../../../typings/browser/ambient/webtorrent/webtorrent.d.ts' />
3 import { Component, OnInit, ElementRef } from 'angular2/core';
4 import { RouteParams } from 'angular2/router';
6 declare var WebTorrent: any;
8 import { Video } from '../../models/video';
9 import { VideosService } from '../../services/videos.service';
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' ]
17 export class VideosWatchComponent {
23 private _videosService: VideosService,
24 private _routeParams: RouteParams,
25 private _elementRef: ElementRef
27 this.client = new WebTorrent({ dht: false });
31 let id = this._routeParams.get('id');
32 this._videosService.getVideo(id).subscribe(
33 video => this.loadVideo(video),
38 loadVideo(video: Video) {
41 this.client.add(this.video.magnetUri, (torrent) => {
42 torrent.files[0].appendTo(this._elementRef.nativeElement, (err) => {
44 alert('Cannot append the file.');