diff options
Diffstat (limited to 'client/src/app/videos/video-watch')
-rw-r--r-- | client/src/app/videos/video-watch/video-watch.component.ts | 44 | ||||
-rw-r--r-- | client/src/app/videos/video-watch/webtorrent.service.ts | 4 |
2 files changed, 36 insertions, 12 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 5678f6df8..37ed70a99 100644 --- a/client/src/app/videos/video-watch/video-watch.component.ts +++ b/client/src/app/videos/video-watch/video-watch.component.ts | |||
@@ -1,12 +1,13 @@ | |||
1 | import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'; | 1 | import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'; |
2 | import { ActivatedRoute } from '@angular/router'; | 2 | import { ActivatedRoute, Router } from '@angular/router'; |
3 | import { Observable } from 'rxjs/Observable'; | ||
3 | import { Subscription } from 'rxjs/Subscription'; | 4 | import { Subscription } from 'rxjs/Subscription'; |
4 | 5 | ||
5 | import * as videojs from 'video.js'; | 6 | import * as videojs from 'video.js'; |
6 | import { MetaService } from '@nglibs/meta'; | 7 | import { MetaService } from '@nglibs/meta'; |
7 | import { NotificationsService } from 'angular2-notifications'; | 8 | import { NotificationsService } from 'angular2-notifications'; |
8 | 9 | ||
9 | import { AuthService } from '../../core'; | 10 | import { AuthService, ConfirmService } from '../../core'; |
10 | import { VideoMagnetComponent } from './video-magnet.component'; | 11 | import { VideoMagnetComponent } from './video-magnet.component'; |
11 | import { VideoShareComponent } from './video-share.component'; | 12 | import { VideoShareComponent } from './video-share.component'; |
12 | import { VideoReportComponent } from './video-report.component'; | 13 | import { VideoReportComponent } from './video-report.component'; |
@@ -47,7 +48,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
47 | private elementRef: ElementRef, | 48 | private elementRef: ElementRef, |
48 | private ngZone: NgZone, | 49 | private ngZone: NgZone, |
49 | private route: ActivatedRoute, | 50 | private route: ActivatedRoute, |
51 | private router: Router, | ||
50 | private videoService: VideoService, | 52 | private videoService: VideoService, |
53 | private confirmService: ConfirmService, | ||
51 | private metaService: MetaService, | 54 | private metaService: MetaService, |
52 | private webTorrentService: WebTorrentService, | 55 | private webTorrentService: WebTorrentService, |
53 | private authService: AuthService, | 56 | private authService: AuthService, |
@@ -58,15 +61,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
58 | this.paramsSub = this.route.params.subscribe(routeParams => { | 61 | this.paramsSub = this.route.params.subscribe(routeParams => { |
59 | let id = routeParams['id']; | 62 | let id = routeParams['id']; |
60 | this.videoService.getVideo(id).subscribe( | 63 | this.videoService.getVideo(id).subscribe( |
61 | video => { | 64 | video => this.onVideoFetched(video), |
62 | this.video = video; | 65 | |
63 | this.setOpenGraphTags(); | 66 | error => this.videoNotFound = true |
64 | this.loadVideo(); | ||
65 | this.checkUserRating(); | ||
66 | }, | ||
67 | error => { | ||
68 | this.videoNotFound = true; | ||
69 | } | ||
70 | ); | 67 | ); |
71 | }); | 68 | }); |
72 | 69 | ||
@@ -92,7 +89,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
92 | window.clearInterval(this.torrentInfosInterval); | 89 | window.clearInterval(this.torrentInfosInterval); |
93 | window.clearTimeout(this.errorTimer); | 90 | window.clearTimeout(this.errorTimer); |
94 | 91 | ||
95 | if (this.video !== null) { | 92 | if (this.video !== null && this.webTorrentService.has(this.video.magnetUri)) { |
96 | this.webTorrentService.remove(this.video.magnetUri); | 93 | this.webTorrentService.remove(this.video.magnetUri); |
97 | } | 94 | } |
98 | 95 | ||
@@ -206,6 +203,29 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
206 | ); | 203 | ); |
207 | } | 204 | } |
208 | 205 | ||
206 | private onVideoFetched(video: Video) { | ||
207 | this.video = video; | ||
208 | |||
209 | let observable; | ||
210 | if (this.video.isVideoNSFWForUser(this.authService.getUser())) { | ||
211 | observable = this.confirmService.confirm('This video is not safe for work. Are you sure you want to watch it?', 'NSFW'); | ||
212 | } else { | ||
213 | observable = Observable.of(true); | ||
214 | } | ||
215 | |||
216 | observable.subscribe( | ||
217 | res => { | ||
218 | if (res === false) { | ||
219 | return this.router.navigate([ '/videos/list' ]); | ||
220 | } | ||
221 | |||
222 | this.setOpenGraphTags(); | ||
223 | this.loadVideo(); | ||
224 | this.checkUserRating(); | ||
225 | } | ||
226 | ); | ||
227 | } | ||
228 | |||
209 | private updateVideoRating(oldRating: RateType, newRating: RateType) { | 229 | private updateVideoRating(oldRating: RateType, newRating: RateType) { |
210 | let likesToIncrement = 0; | 230 | let likesToIncrement = 0; |
211 | let dislikesToIncrement = 0; | 231 | let dislikesToIncrement = 0; |
diff --git a/client/src/app/videos/video-watch/webtorrent.service.ts b/client/src/app/videos/video-watch/webtorrent.service.ts index 0192167ee..630a5c469 100644 --- a/client/src/app/videos/video-watch/webtorrent.service.ts +++ b/client/src/app/videos/video-watch/webtorrent.service.ts | |||
@@ -26,4 +26,8 @@ export class WebTorrentService { | |||
26 | remove(magnetUri: string) { | 26 | remove(magnetUri: string) { |
27 | return this.client.remove(magnetUri); | 27 | return this.client.remove(magnetUri); |
28 | } | 28 | } |
29 | |||
30 | has(magnetUri: string) { | ||
31 | return this.client.get(magnetUri) !== null; | ||
32 | } | ||
29 | } | 33 | } |