aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/app/videos/video-watch/webtorrent.service.ts
blob: 0192167ee88405922fa06f4baace204139253105 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                                           
                                       
 
                         


                                



                                  




                                                 
 

                                                                









                                                
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';

declare const WebTorrent;

@Injectable()
export class WebTorrentService {
  errors = new Subject<Error>();
  warnings = new Subject<Error>();

  // TODO: use WebTorrent @type
  // private client: WebTorrent.Client;
  private client: any;

  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));
  }

  add(magnetUri: string, callback: Function) {
    return this.client.add(magnetUri, callback);
  }

  remove(magnetUri: string) {
    return this.client.remove(magnetUri);
  }
}