]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/angular/videos/components/watch/videos-watch.component.ts
Add search with field choose support in client
[github/Chocobozzz/PeerTube.git] / client / angular / videos / components / watch / videos-watch.component.ts
index d1b90c190da842faeb1763b1f89654db10581acc..3eb005d07b4debd23ca197fa8a646729703fe10f 100644 (file)
@@ -1,21 +1,28 @@
-import { Component, OnInit, ElementRef } from 'angular2/core';
-import { RouteParams, CanDeactivate, ComponentInstruction } from 'angular2/router';
+import { Component, OnInit, ElementRef } from '@angular/core';
+import { RouteParams, CanDeactivate, ComponentInstruction } from '@angular/router-deprecated';
+import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
 
 // TODO import it with systemjs
 declare var WebTorrent: any;
 
-import { Video } from '../../models/video';
-import { VideosService } from '../../services/videos.service';
+import { Video } from '../../video';
+import { VideosService } from '../../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' ]
+  styleUrls: [ 'app/angular/videos/components/watch/videos-watch.component.css' ],
+  pipes: [ BytesPipe ]
 })
 
 export class VideosWatchComponent implements OnInit, CanDeactivate {
   video: Video;
+  downloadSpeed: number;
+  uploadSpeed: number;
+  numPeers: number;
+  loading: boolean = false;
 
+  private _interval: NodeJS.Timer;
   private client: any;
 
   constructor(
@@ -36,21 +43,31 @@ export class VideosWatchComponent implements OnInit, CanDeactivate {
   }
 
   loadVideo(video: Video) {
+    this.loading = true;
     this.video = video;
     console.log('Adding ' + this.video.magnetUri + '.');
     this.client.add(this.video.magnetUri, (torrent) => {
+      this.loading = false;
       console.log('Added ' + this.video.magnetUri + '.');
-      torrent.files[0].appendTo(this._elementRef.nativeElement, (err) => {
+      torrent.files[0].appendTo(this._elementRef.nativeElement.querySelector('.embed-responsive'), (err) => {
         if (err) {
           alert('Cannot append the file.');
           console.error(err);
         }
       });
+
+      // Refresh each second
+      this._interval = setInterval(() => {
+        this.downloadSpeed = torrent.downloadSpeed;
+        this.uploadSpeed = torrent.uploadSpeed;
+        this.numPeers = torrent.numPeers;
+      }, 1000);
     });
   }
 
   routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) : any {
     console.log('Removing video from webtorrent.');
+    clearInterval(this._interval);
     this.client.remove(this.video.magnetUri);
     return true;
   }