From dc8bc31be517a53e8fbe7100cfe45cd73f596de0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 14 Mar 2016 13:50:19 +0100 Subject: Angular application :first draft --- .../components/watch/videos-watch.component.html | 2 + .../components/watch/videos-watch.component.scss | 0 .../components/watch/videos-watch.component.ts | 50 ++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 client/angular/videos/components/watch/videos-watch.component.html create mode 100644 client/angular/videos/components/watch/videos-watch.component.scss create mode 100644 client/angular/videos/components/watch/videos-watch.component.ts (limited to 'client/angular/videos/components/watch') diff --git a/client/angular/videos/components/watch/videos-watch.component.html b/client/angular/videos/components/watch/videos-watch.component.html new file mode 100644 index 000000000..e47222751 --- /dev/null +++ b/client/angular/videos/components/watch/videos-watch.component.html @@ -0,0 +1,2 @@ +
+
diff --git a/client/angular/videos/components/watch/videos-watch.component.scss b/client/angular/videos/components/watch/videos-watch.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/client/angular/videos/components/watch/videos-watch.component.ts b/client/angular/videos/components/watch/videos-watch.component.ts new file mode 100644 index 000000000..e3a973820 --- /dev/null +++ b/client/angular/videos/components/watch/videos-watch.component.ts @@ -0,0 +1,50 @@ +/// + +import { Component, OnInit, ElementRef } from 'angular2/core'; +import { RouteParams } from 'angular2/router'; + +declare var WebTorrent: any; + +import { Video } from '../../models/video'; +import { VideosService } from '../../services/videos.service'; + +@Component({ + selector: 'my-video-watch', + templateUrl: 'app/angular/videos/components/watch/videos-watch.component.html', + styleUrls: [ 'app/angular/videos/components/watch/videos-watch.component.css' ] +}) + +export class VideosWatchComponent { + video: Video; + + private client: any; + + constructor( + private _videosService: VideosService, + private _routeParams: RouteParams, + private _elementRef: ElementRef + ) { + this.client = new WebTorrent({ dht: false }); + } + + ngOnInit() { + let id = this._routeParams.get('id'); + this._videosService.getVideo(id).subscribe( + video => this.loadVideo(video), + error => alert(error) + ); + } + + loadVideo(video: Video) { + this.video = video; + + this.client.add(this.video.magnetUri, (torrent) => { + torrent.files[0].appendTo(this._elementRef.nativeElement, (err) => { + if (err) { + alert('Cannot append the file.'); + console.error(err); + } + }) + }) + } +} -- cgit v1.2.3