Client: notify client if there are webtorrent errors
authorChocobozzz <florian.bigard@gmail.com>
Sun, 29 Jan 2017 17:35:19 +0000 (18:35 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Sun, 29 Jan 2017 17:35:19 +0000 (18:35 +0100)
README.md
client/config/webpack.common.js
client/src/app/videos/video-watch/video-watch.component.ts
client/src/app/videos/video-watch/webtorrent.service.ts

index a1198019c666435bcb20e99b391ee85f90c4ce45..1047ea6e9bdc59938b9bcf8b505fb3f95c8570f3 100644 (file)
--- a/README.md
+++ b/README.md
@@ -26,7 +26,7 @@ Prototype of a decentralized video streaming platform using P2P (BitTorrent) dir
   <br />
 
   <a href="https://travis-ci.org/Chocobozzz/PeerTube">
-    <img src="https://travis-ci.org/Chocobozzz/PeerTube.svg?branch=master" alt="Build Status" />
+    <img src="https://travis-ci.org/Chocobozzz/PeerTube.svg?branch=develop" alt="Build Status" />
   </a>
 
   <a href="https://david-dm.org/Chocobozzz/PeerTube">
index 08b8a4b09cedf69aa44a3804ba5f984b1e4400c3..2d227f6f8de9a5dce9bad1e8fc11b3eea6d1f9f9 100644 (file)
@@ -8,6 +8,7 @@ const AssetsPlugin = require('assets-webpack-plugin')
 const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
 const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
 const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin')
+const ProvidePlugin = require('webpack/lib/ProvidePlugin')
 const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin')
 const CopyWebpackPlugin = require('copy-webpack-plugin')
 const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
index c27133f74ffd15484363f0d76564e7cfbb28f875..9ac9342b7713bbfea4d68e7077df35c3d82f5410 100644 (file)
@@ -1,5 +1,6 @@
 import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core';
 import { ActivatedRoute } from '@angular/router';
+import { Subscription } from 'rxjs/Subscription';
 
 import * as videojs from 'video.js';
 import { MetaService } from 'ng2-meta';
@@ -36,7 +37,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
   videoNotFound = false;
 
   private errorTimer: number;
-  private sub: any;
+  private paramsSub: Subscription;
+  private errorsSub: Subscription;
+  private warningsSub: Subscription;
   private torrentInfosInterval: number;
 
   constructor(
@@ -51,7 +54,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
   ) {}
 
   ngOnInit() {
-    this.sub = this.route.params.subscribe(routeParams => {
+    this.paramsSub = this.route.params.subscribe(routeParams => {
       let id = routeParams['id'];
       this.videoService.getVideo(id).subscribe(
         video => {
@@ -76,6 +79,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
     videojs(this.playerElement, videojsOptions, function () {
       self.player = this;
     });
+
+    this.errorsSub = this.webTorrentService.errors.subscribe(err => this.notificationsService.error('Error', err.message));
+    this.warningsSub = this.webTorrentService.errors.subscribe(err => this.notificationsService.alert('Warning', err.message));
   }
 
   ngOnDestroy() {
@@ -91,8 +97,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
     // Remove player
     videojs(this.playerElement).dispose();
 
-    // Unsubscribe route subscription
-    this.sub.unsubscribe();
+    // Unsubscribe subscriptions
+    this.paramsSub.unsubscribe();
+    this.errorsSub.unsubscribe();
+    this.warningsSub.unsubscribe();
   }
 
   loadVideo() {
index bf38b5aaaa38da97edd5d136212422c7cc2c36e5..1839c7c277c8112f1ef3aeed233dafcff4a1dd5a 100644 (file)
@@ -1,19 +1,22 @@
-// Don't use webtorrent typings for now
-// It misses some little things I'll fix later
-// <reference path="../../../../typings/globals/webtorrent/index.d.ts" />
-
 import { Injectable } from '@angular/core';
+import { Subject } from 'rxjs/Subject';
 
-// import WebTorrent = require('webtorrent');
-declare var WebTorrent: any;
+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) {