+/// <reference path="../../../typings/globals/jquery/index.d.ts" />
+/// <reference path="../../../typings/globals/jquery.fileupload/index.d.ts" />
+
import { Component, ElementRef, OnInit } from '@angular/core';
import { Router } from '@angular/router-deprecated';
import { AuthService, User } from '../../users/index';
-// TODO: import it with systemjs
-declare var jQuery: any;
-
@Component({
selector: 'my-videos-add',
styleUrls: [ 'client/app/videos/video-add/video-add.component.css' ],
dataType: 'json',
singleFileUploads: true,
multipart: true,
- autoupload: false,
+ autoUpload: false,
add: (e, data) => {
this.form = data;
export * from './video-watch.component';
+export * from './webtorrent.service';
import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
import { LoaderComponent, Video, VideoService } from '../shared/index';
-
-// TODO import it with systemjs
-declare var WebTorrent: any;
+import { WebTorrentService } from './webtorrent.service';
@Component({
selector: 'my-video-watch',
templateUrl: 'client/app/videos/video-watch/video-watch.component.html',
styleUrls: [ 'client/app/videos/video-watch/video-watch.component.css' ],
+ providers: [ WebTorrentService ],
directives: [ LoaderComponent ],
pipes: [ BytesPipe ]
})
uploadSpeed: number;
video: Video;
- private client: any;
private interval: NodeJS.Timer;
constructor(
private elementRef: ElementRef,
private routeParams: RouteParams,
- private videoService: VideoService
- ) {
- // TODO: use a service
- this.client = new WebTorrent({ dht: false });
- }
+ private videoService: VideoService,
+ private webTorrentService: WebTorrentService
+ ) {}
loadVideo(video: Video) {
this.loading = true;
this.video = video;
console.log('Adding ' + this.video.magnetUri + '.');
- this.client.add(this.video.magnetUri, (torrent) => {
+
+ this.webTorrentService.add(this.video.magnetUri, (torrent) => {
this.loading = false;
console.log('Added ' + this.video.magnetUri + '.');
torrent.files[0].appendTo(this.elementRef.nativeElement.querySelector('.embed-responsive'), (err) => {
routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
console.log('Removing video from webtorrent.');
clearInterval(this.interval);
- this.client.remove(this.video.magnetUri);
+ this.webTorrentService.remove(this.video.magnetUri);
return true;
}
}
--- /dev/null
+// Don't use webtorrent typings for now
+// It misses some little things I'll fix later
+// <reference path="../../../typings/globals/webtorrent/index.d.ts" />
+
+import { Injectable } from '@angular/core';
+
+// import WebTorrent = require('webtorrent');
+declare var WebTorrent: any;
+
+@Injectable()
+export class WebTorrentService {
+ // private client: WebTorrent.Client;
+ private client: any;
+
+ constructor() {
+ this.client = new WebTorrent({ dht: false });
+ }
+
+ add(magnetUri: string, callback: Function) {
+ return this.client.add(magnetUri, callback);
+ }
+
+ remove(magnetUri: string) {
+ return this.client.remove(magnetUri);
+ }
+}
"app/videos/video-list/video-sort.component.ts",
"app/videos/video-watch/index.ts",
"app/videos/video-watch/video-watch.component.ts",
+ "app/videos/video-watch/webtorrent.service.ts",
"main.ts",
"typings/globals/es6-shim/index.d.ts",
"typings/globals/jasmine/index.d.ts",
+ "typings/globals/jquery.fileupload/index.d.ts",
+ "typings/globals/jquery/index.d.ts",
"typings/globals/node/index.d.ts",
"typings/index.d.ts"
],