]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/video-watch/webtorrent.service.ts
Client: Handle NSFW video
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / video-watch / webtorrent.service.ts
CommitLineData
d3ef341a 1import { Injectable } from '@angular/core';
13fc89f4 2import { Subject } from 'rxjs/Subject';
d3ef341a 3
13fc89f4 4declare const WebTorrent;
d3ef341a
C
5
6@Injectable()
7export class WebTorrentService {
13fc89f4
C
8 errors = new Subject<Error>();
9 warnings = new Subject<Error>();
10
11 // TODO: use WebTorrent @type
d3ef341a
C
12 // private client: WebTorrent.Client;
13 private client: any;
14
15 constructor() {
16 this.client = new WebTorrent({ dht: false });
13fc89f4 17
7af75da4
C
18 this.client.on('error', (err) => this.errors.next(err));
19 this.client.on('warning', (err) => this.warnings.next(err));
d3ef341a
C
20 }
21
22 add(magnetUri: string, callback: Function) {
23 return this.client.add(magnetUri, callback);
24 }
25
26 remove(magnetUri: string) {
27 return this.client.remove(magnetUri);
28 }
92fb909c
C
29
30 has(magnetUri: string) {
31 return this.client.get(magnetUri) !== null;
32 }
d3ef341a 33}