Client: notify client if there are webtorrent errors

pull/40/head
Chocobozzz 2017-01-29 18:35:19 +01:00
parent 5769e1db8d
commit 13fc89f4a4
4 changed files with 23 additions and 11 deletions

View File

@ -26,7 +26,7 @@ Prototype of a decentralized video streaming platform using P2P (BitTorrent) dir
<br /> <br />
<a href="https://travis-ci.org/Chocobozzz/PeerTube"> <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>
<a href="https://david-dm.org/Chocobozzz/PeerTube"> <a href="https://david-dm.org/Chocobozzz/PeerTube">

View File

@ -8,6 +8,7 @@ const AssetsPlugin = require('assets-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin') const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin') const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin')
const ProvidePlugin = require('webpack/lib/ProvidePlugin')
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin') const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin')
const CopyWebpackPlugin = require('copy-webpack-plugin') const CopyWebpackPlugin = require('copy-webpack-plugin')
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin

View File

@ -1,5 +1,6 @@
import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
import * as videojs from 'video.js'; import * as videojs from 'video.js';
import { MetaService } from 'ng2-meta'; import { MetaService } from 'ng2-meta';
@ -36,7 +37,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
videoNotFound = false; videoNotFound = false;
private errorTimer: number; private errorTimer: number;
private sub: any; private paramsSub: Subscription;
private errorsSub: Subscription;
private warningsSub: Subscription;
private torrentInfosInterval: number; private torrentInfosInterval: number;
constructor( constructor(
@ -51,7 +54,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
) {} ) {}
ngOnInit() { ngOnInit() {
this.sub = this.route.params.subscribe(routeParams => { this.paramsSub = this.route.params.subscribe(routeParams => {
let id = routeParams['id']; let id = routeParams['id'];
this.videoService.getVideo(id).subscribe( this.videoService.getVideo(id).subscribe(
video => { video => {
@ -76,6 +79,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
videojs(this.playerElement, videojsOptions, function () { videojs(this.playerElement, videojsOptions, function () {
self.player = this; 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() { ngOnDestroy() {
@ -91,8 +97,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
// Remove player // Remove player
videojs(this.playerElement).dispose(); videojs(this.playerElement).dispose();
// Unsubscribe route subscription // Unsubscribe subscriptions
this.sub.unsubscribe(); this.paramsSub.unsubscribe();
this.errorsSub.unsubscribe();
this.warningsSub.unsubscribe();
} }
loadVideo() { loadVideo() {

View 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 { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
// import WebTorrent = require('webtorrent'); declare const WebTorrent;
declare var WebTorrent: any;
@Injectable() @Injectable()
export class WebTorrentService { export class WebTorrentService {
errors = new Subject<Error>();
warnings = new Subject<Error>();
// TODO: use WebTorrent @type
// private client: WebTorrent.Client; // private client: WebTorrent.Client;
private client: any; private client: any;
constructor() { constructor() {
this.client = new WebTorrent({ dht: false }); 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) { add(magnetUri: string, callback: Function) {