]>
Commit | Line | Data |
---|---|---|
1 | import { Injectable } from '@angular/core'; | |
2 | import { Subject } from 'rxjs/Subject'; | |
3 | ||
4 | declare const WebTorrent; | |
5 | ||
6 | @Injectable() | |
7 | export class WebTorrentService { | |
8 | errors = new Subject<Error>(); | |
9 | warnings = new Subject<Error>(); | |
10 | ||
11 | // TODO: use WebTorrent @type | |
12 | // private client: WebTorrent.Client; | |
13 | private client: any; | |
14 | ||
15 | constructor() { | |
16 | this.client = new WebTorrent({ dht: false }); | |
17 | ||
18 | this.client.on('error', (err) => this.errors.next(err)); | |
19 | this.client.on('warning', (err) => this.warnings.next(err)); | |
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 | } | |
29 | ||
30 | has(magnetUri: string) { | |
31 | return this.client.get(magnetUri) !== null; | |
32 | } | |
33 | } |