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<string | Error>()
10 private client: WebTorrent.Instance
13 this.client = new WebTorrent({ dht: false })
15 this.client.on('error', err => this.errors.next(err))
18 add (magnetUri: string, callback: (torrent: WebTorrent.Torrent) => any) {
19 return this.client.add(magnetUri, callback)
22 remove (magnetUri: string) {
23 return this.client.remove(magnetUri)
26 has (magnetUri: string) {
27 return this.client.get(magnetUri) !== null