-import { Injectable } from '@angular/core';
-import { Subject } from 'rxjs/Subject';
+import { Injectable } from '@angular/core'
+import { Subject } from 'rxjs/Subject'
-declare const WebTorrent;
+import * as WebTorrent from 'webtorrent'
@Injectable()
export class WebTorrentService {
- errors = new Subject<Error>();
- warnings = new Subject<Error>();
+ errors = new Subject<Error>()
+ warnings = new Subject<Error>()
// TODO: use WebTorrent @type
- // private client: WebTorrent.Client;
- private client: any;
+ // private client: WebTorrent.Client
+ private client: any
- constructor() {
- this.client = new WebTorrent({ dht: false });
+ constructor () {
+ this.client = new WebTorrent({ dht: false })
- this.client.on('error', (err) => this.errors.next(err));
- this.client.on('warning', (err) => this.warnings.next(err));
+ this.client.on('error', (err) => this.errors.next(err))
+ this.client.on('warning', (err) => this.warnings.next(err))
}
- add(magnetUri: string, callback: Function) {
- return this.client.add(magnetUri, callback);
+ add (magnetUri: string, callback: Function) {
+ return this.client.add(magnetUri, callback)
}
- remove(magnetUri: string) {
- return this.client.remove(magnetUri);
+ remove (magnetUri: string) {
+ return this.client.remove(magnetUri)
}
- has(magnetUri: string) {
- return this.client.get(magnetUri) !== null;
+ has (magnetUri: string) {
+ return this.client.get(magnetUri) !== null
}
}