aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/video-watch
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-11 10:09:18 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-11 10:09:18 +0200
commit33c4972d5b54155540267f4c9c9ee55c539b8385 (patch)
treec150d11c0afdeb90c19c4d59297c6829b2d55dd1 /client/src/app/videos/video-watch
parent4771e0008dd26eadbb7eaff64255a6ec914fdadb (diff)
downloadPeerTube-33c4972d5b54155540267f4c9c9ee55c539b8385.tar.gz
PeerTube-33c4972d5b54155540267f4c9c9ee55c539b8385.tar.zst
PeerTube-33c4972d5b54155540267f4c9c9ee55c539b8385.zip
Type webtorrent
Diffstat (limited to 'client/src/app/videos/video-watch')
-rw-r--r--client/src/app/videos/video-watch/video-watch.component.ts12
-rw-r--r--client/src/app/videos/video-watch/webtorrent.service.ts12
2 files changed, 10 insertions, 14 deletions
diff --git a/client/src/app/videos/video-watch/video-watch.component.ts b/client/src/app/videos/video-watch/video-watch.component.ts
index 12ddf3eef..6bd6c1f7e 100644
--- a/client/src/app/videos/video-watch/video-watch.component.ts
+++ b/client/src/app/videos/video-watch/video-watch.component.ts
@@ -32,7 +32,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
32 loading = false 32 loading = false
33 numPeers: number 33 numPeers: number
34 player: videojs.Player 34 player: videojs.Player
35 playerElement: Element 35 playerElement: HTMLMediaElement
36 uploadSpeed: number 36 uploadSpeed: number
37 userRating: UserVideoRateType = null 37 userRating: UserVideoRateType = null
38 video: Video = null 38 video: Video = null
@@ -41,7 +41,6 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
41 private errorTimer: number 41 private errorTimer: number
42 private paramsSub: Subscription 42 private paramsSub: Subscription
43 private errorsSub: Subscription 43 private errorsSub: Subscription
44 private warningsSub: Subscription
45 private torrentInfosInterval: number 44 private torrentInfosInterval: number
46 45
47 constructor ( 46 constructor (
@@ -82,8 +81,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
82 self.player = this 81 self.player = this
83 }) 82 })
84 83
85 this.errorsSub = this.webTorrentService.errors.subscribe(err => this.notificationsService.error('Error', err.message)) 84 this.errorsSub = this.webTorrentService.errors.subscribe(err => {
86 this.warningsSub = this.webTorrentService.errors.subscribe(err => this.notificationsService.alert('Warning', err.message)) 85 const message = typeof err === 'string' ? err : err.message
86 this.notificationsService.error('Error', message)
87 })
87 } 88 }
88 89
89 ngOnDestroy () { 90 ngOnDestroy () {
@@ -102,7 +103,6 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
102 // Unsubscribe subscriptions 103 // Unsubscribe subscriptions
103 this.paramsSub.unsubscribe() 104 this.paramsSub.unsubscribe()
104 this.errorsSub.unsubscribe() 105 this.errorsSub.unsubscribe()
105 this.warningsSub.unsubscribe()
106 } 106 }
107 107
108 loadVideo () { 108 loadVideo () {
@@ -117,7 +117,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
117 // So we create a timer to inform the user the load is abnormally long 117 // So we create a timer to inform the user the load is abnormally long
118 this.errorTimer = window.setTimeout(() => this.loadTooLong(), VideoWatchComponent.LOADTIME_TOO_LONG) 118 this.errorTimer = window.setTimeout(() => this.loadTooLong(), VideoWatchComponent.LOADTIME_TOO_LONG)
119 119
120 this.webTorrentService.add(this.video.magnetUri, (torrent) => { 120 this.webTorrentService.add(this.video.magnetUri, torrent => {
121 // Clear the error timer 121 // Clear the error timer
122 window.clearTimeout(this.errorTimer) 122 window.clearTimeout(this.errorTimer)
123 // Maybe the error was fired by the timer, so reset it 123 // Maybe the error was fired by the timer, so reset it
diff --git a/client/src/app/videos/video-watch/webtorrent.service.ts b/client/src/app/videos/video-watch/webtorrent.service.ts
index 211894bfd..8819e17d4 100644
--- a/client/src/app/videos/video-watch/webtorrent.service.ts
+++ b/client/src/app/videos/video-watch/webtorrent.service.ts
@@ -5,21 +5,17 @@ import * as WebTorrent from 'webtorrent'
5 5
6@Injectable() 6@Injectable()
7export class WebTorrentService { 7export class WebTorrentService {
8 errors = new Subject<Error>() 8 errors = new Subject<string | Error>()
9 warnings = new Subject<Error>()
10 9
11 // TODO: use WebTorrent @type 10 private client: WebTorrent.Instance
12 // private client: WebTorrent.Client
13 private client: any
14 11
15 constructor () { 12 constructor () {
16 this.client = new WebTorrent({ dht: false }) 13 this.client = new WebTorrent({ dht: false })
17 14
18 this.client.on('error', (err) => this.errors.next(err)) 15 this.client.on('error', err => this.errors.next(err))
19 this.client.on('warning', (err) => this.warnings.next(err))
20 } 16 }
21 17
22 add (magnetUri: string, callback: Function) { 18 add (magnetUri: string, callback: (torrent: WebTorrent.Torrent) => any) {
23 return this.client.add(magnetUri, callback) 19 return this.client.add(magnetUri, callback)
24 } 20 }
25 21