aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/app
diff options
context:
space:
mode:
Diffstat (limited to 'client/app')
-rw-r--r--client/app/videos/video-add/video-add.component.ts8
-rw-r--r--client/app/videos/video-watch/index.ts1
-rw-r--r--client/app/videos/video-watch/video-watch.component.ts19
-rw-r--r--client/app/videos/video-watch/webtorrent.service.ts26
4 files changed, 39 insertions, 15 deletions
diff --git a/client/app/videos/video-add/video-add.component.ts b/client/app/videos/video-add/video-add.component.ts
index eb10aedeb..619a4f4d8 100644
--- a/client/app/videos/video-add/video-add.component.ts
+++ b/client/app/videos/video-add/video-add.component.ts
@@ -1,3 +1,6 @@
1/// <reference path="../../../typings/globals/jquery/index.d.ts" />
2/// <reference path="../../../typings/globals/jquery.fileupload/index.d.ts" />
3
1import { Component, ElementRef, OnInit } from '@angular/core'; 4import { Component, ElementRef, OnInit } from '@angular/core';
2import { Router } from '@angular/router-deprecated'; 5import { Router } from '@angular/router-deprecated';
3 6
@@ -6,9 +9,6 @@ import { PROGRESSBAR_DIRECTIVES } from 'ng2-bootstrap/components/progressbar';
6 9
7import { AuthService, User } from '../../users/index'; 10import { AuthService, User } from '../../users/index';
8 11
9// TODO: import it with systemjs
10declare var jQuery: any;
11
12@Component({ 12@Component({
13 selector: 'my-videos-add', 13 selector: 'my-videos-add',
14 styleUrls: [ 'client/app/videos/video-add/video-add.component.css' ], 14 styleUrls: [ 'client/app/videos/video-add/video-add.component.css' ],
@@ -37,7 +37,7 @@ export class VideoAddComponent implements OnInit {
37 dataType: 'json', 37 dataType: 'json',
38 singleFileUploads: true, 38 singleFileUploads: true,
39 multipart: true, 39 multipart: true,
40 autoupload: false, 40 autoUpload: false,
41 41
42 add: (e, data) => { 42 add: (e, data) => {
43 this.form = data; 43 this.form = data;
diff --git a/client/app/videos/video-watch/index.ts b/client/app/videos/video-watch/index.ts
index 2228b6ed7..b17aaacf2 100644
--- a/client/app/videos/video-watch/index.ts
+++ b/client/app/videos/video-watch/index.ts
@@ -1 +1,2 @@
1export * from './video-watch.component'; 1export * from './video-watch.component';
2export * from './webtorrent.service';
diff --git a/client/app/videos/video-watch/video-watch.component.ts b/client/app/videos/video-watch/video-watch.component.ts
index 137db8f0b..71fb4f634 100644
--- a/client/app/videos/video-watch/video-watch.component.ts
+++ b/client/app/videos/video-watch/video-watch.component.ts
@@ -4,14 +4,13 @@ import { CanDeactivate, ComponentInstruction, RouteParams } from '@angular/route
4import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; 4import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
5 5
6import { LoaderComponent, Video, VideoService } from '../shared/index'; 6import { LoaderComponent, Video, VideoService } from '../shared/index';
7 7import { WebTorrentService } from './webtorrent.service';
8// TODO import it with systemjs
9declare var WebTorrent: any;
10 8
11@Component({ 9@Component({
12 selector: 'my-video-watch', 10 selector: 'my-video-watch',
13 templateUrl: 'client/app/videos/video-watch/video-watch.component.html', 11 templateUrl: 'client/app/videos/video-watch/video-watch.component.html',
14 styleUrls: [ 'client/app/videos/video-watch/video-watch.component.css' ], 12 styleUrls: [ 'client/app/videos/video-watch/video-watch.component.css' ],
13 providers: [ WebTorrentService ],
15 directives: [ LoaderComponent ], 14 directives: [ LoaderComponent ],
16 pipes: [ BytesPipe ] 15 pipes: [ BytesPipe ]
17}) 16})
@@ -23,23 +22,21 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
23 uploadSpeed: number; 22 uploadSpeed: number;
24 video: Video; 23 video: Video;
25 24
26 private client: any;
27 private interval: NodeJS.Timer; 25 private interval: NodeJS.Timer;
28 26
29 constructor( 27 constructor(
30 private elementRef: ElementRef, 28 private elementRef: ElementRef,
31 private routeParams: RouteParams, 29 private routeParams: RouteParams,
32 private videoService: VideoService 30 private videoService: VideoService,
33 ) { 31 private webTorrentService: WebTorrentService
34 // TODO: use a service 32 ) {}
35 this.client = new WebTorrent({ dht: false });
36 }
37 33
38 loadVideo(video: Video) { 34 loadVideo(video: Video) {
39 this.loading = true; 35 this.loading = true;
40 this.video = video; 36 this.video = video;
41 console.log('Adding ' + this.video.magnetUri + '.'); 37 console.log('Adding ' + this.video.magnetUri + '.');
42 this.client.add(this.video.magnetUri, (torrent) => { 38
39 this.webTorrentService.add(this.video.magnetUri, (torrent) => {
43 this.loading = false; 40 this.loading = false;
44 console.log('Added ' + this.video.magnetUri + '.'); 41 console.log('Added ' + this.video.magnetUri + '.');
45 torrent.files[0].appendTo(this.elementRef.nativeElement.querySelector('.embed-responsive'), (err) => { 42 torrent.files[0].appendTo(this.elementRef.nativeElement.querySelector('.embed-responsive'), (err) => {
@@ -69,7 +66,7 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
69 routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) { 66 routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
70 console.log('Removing video from webtorrent.'); 67 console.log('Removing video from webtorrent.');
71 clearInterval(this.interval); 68 clearInterval(this.interval);
72 this.client.remove(this.video.magnetUri); 69 this.webTorrentService.remove(this.video.magnetUri);
73 return true; 70 return true;
74 } 71 }
75} 72}
diff --git a/client/app/videos/video-watch/webtorrent.service.ts b/client/app/videos/video-watch/webtorrent.service.ts
new file mode 100644
index 000000000..0c73ab4f4
--- /dev/null
+++ b/client/app/videos/video-watch/webtorrent.service.ts
@@ -0,0 +1,26 @@
1// Don't use webtorrent typings for now
2// It misses some little things I'll fix later
3// <reference path="../../../typings/globals/webtorrent/index.d.ts" />
4
5import { Injectable } from '@angular/core';
6
7// import WebTorrent = require('webtorrent');
8declare var WebTorrent: any;
9
10@Injectable()
11export class WebTorrentService {
12 // private client: WebTorrent.Client;
13 private client: any;
14
15 constructor() {
16 this.client = new WebTorrent({ dht: false });
17 }
18
19 add(magnetUri: string, callback: Function) {
20 return this.client.add(magnetUri, callback);
21 }
22
23 remove(magnetUri: string) {
24 return this.client.remove(magnetUri);
25 }
26}