1 import { Injectable } from '@angular/core'
2 import { Subject } from 'rxjs/Subject'
4 import * as WebTorrent from 'webtorrent'
7 export class WebTorrentService {
8 errors = new Subject<Error>()
9 warnings = new Subject<Error>()
11 // TODO: use WebTorrent @type
12 // private client: WebTorrent.Client
16 this.client = new WebTorrent({ dht: false })
18 this.client.on('error', (err) => this.errors.next(err))
19 this.client.on('warning', (err) => this.warnings.next(err))
22 add (magnetUri: string, callback: Function) {
23 return this.client.add(magnetUri, callback)
26 remove (magnetUri: string) {
27 return this.client.remove(magnetUri)
30 has (magnetUri: string) {
31 return this.client.get(magnetUri) !== null