+import { setInterval, setTimeout } from 'timers'
import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
-import { ModalDirective } from 'ng2-bootstrap/components/modal';
import { MetaService } from 'ng2-meta';
import * as videojs from 'video.js';
+import { AuthService } from '../../core';
+import { VideoMagnetComponent } from './video-magnet.component';
+import { VideoShareComponent } from './video-share.component';
+import { VideoReportComponent } from './video-report.component';
import { Video, VideoService } from '../shared';
import { WebTorrentService } from './webtorrent.service';
export class VideoWatchComponent implements OnInit, OnDestroy {
private static LOADTIME_TOO_LONG: number = 30000;
- @ViewChild('magnetUriModal') magnetUriModal: ModalDirective;
- @ViewChild('shareModal') shareModal: ModalDirective;
+ @ViewChild('videoMagnetModal') videoMagnetModal: VideoMagnetComponent;
+ @ViewChild('videoShareModal') videoShareModal: VideoShareComponent;
+ @ViewChild('videoReportModal') videoReportModal: VideoReportComponent;
downloadSpeed: number;
error: boolean = false;
playerElement: Element;
uploadSpeed: number;
video: Video = null;
+ videoNotFound = false;
private errorTimer: NodeJS.Timer;
private sub: any;
private route: ActivatedRoute,
private videoService: VideoService,
private metaService: MetaService,
- private webTorrentService: WebTorrentService
+ private webTorrentService: WebTorrentService,
+ private authService: AuthService
) {}
ngOnInit() {
this.setOpenGraphTags();
this.loadVideo();
},
- error => alert(error.text)
+ error => {
+ this.videoNotFound = true;
+ }
);
});
console.log('Removing video from webtorrent.');
clearInterval(this.torrentInfosInterval);
clearTimeout(this.errorTimer);
- this.webTorrentService.remove(this.video.magnetUri);
+
+ if (this.video !== null) {
+ this.webTorrentService.remove(this.video.magnetUri);
+ }
// Remove player
videojs(this.playerElement).dispose();
});
}
- showMagnetUriModal() {
- this.magnetUriModal.show();
- }
-
- hideMagnetUriModal() {
- this.magnetUriModal.hide();
+ showReportModal(event: Event) {
+ event.preventDefault();
+ this.videoReportModal.show();
}
showShareModal() {
- this.shareModal.show();
- }
-
- hideShareModal() {
- this.shareModal.hide();
+ this.videoShareModal.show();
}
- getVideoIframeCode() {
- return '<iframe width="560" height="315" ' +
- 'src="' + window.location.origin + '/videos/embed/' + this.video.id + '" ' +
- 'frameborder="0" allowfullscreen>' +
- '</iframe>';
+ showMagnetUriModal() {
+ this.videoMagnetModal.show();
}
- getVideoUrl() {
- return window.location.href;
+ isUserLoggedIn() {
+ return this.authService.isLoggedIn();
}
private loadTooLong() {