]>
Commit | Line | Data |
---|---|---|
d3ef341a | 1 | import { Injectable } from '@angular/core'; |
13fc89f4 | 2 | import { Subject } from 'rxjs/Subject'; |
d3ef341a | 3 | |
13fc89f4 | 4 | declare const WebTorrent; |
d3ef341a C |
5 | |
6 | @Injectable() | |
7 | export 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 C |
17 | |
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 | } | |
29 | } |