+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('videoMagnetModal') videoMagnetModal: VideoMagnetComponent;
+ @ViewChild('videoShareModal') videoShareModal: VideoShareComponent;
+ @ViewChild('videoReportModal') videoReportModal: VideoReportComponent;
downloadSpeed: number;
error: boolean = false;
loading: boolean = false;
numPeers: number;
+ player: VideoJSPlayer;
+ 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;
+ }
);
});
+
+ this.playerElement = this.elementRef.nativeElement.querySelector('#video-container');
+
+ const videojsOptions = {
+ controls: true,
+ autoplay: false
+ };
+
+ const self = this;
+ videojs(this.playerElement, videojsOptions, function () {
+ self.player = this;
+ });
}
ngOnDestroy() {
+ // Remove WebTorrent stuff
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();
+
+ // Unsubscribe route subscription
this.sub.unsubscribe();
}
loadVideo() {
-
- console.log('<iframe width="560" height="315" src="' + window.location.origin + '/videos/embed/' + this.video.id + '" frameborder="0" allowfullscreen></iframe>');
-
// Reset the error
this.error = false;
// We are loading the video
this.loading = false;
console.log('Added ' + this.video.magnetUri + '.');
- torrent.files[0].appendTo(this.elementRef.nativeElement.querySelector('.embed-responsive'), (err) => {
+ torrent.files[0].renderTo(this.playerElement, { autoplay: true }, (err) => {
if (err) {
alert('Cannot append the file.');
console.error(err);
});
}
+ showReportModal(event: Event) {
+ event.preventDefault();
+ this.videoReportModal.show();
+ }
+
+ showShareModal() {
+ this.videoShareModal.show();
+ }
+
showMagnetUriModal() {
- this.magnetUriModal.show();
+ this.videoMagnetModal.show();
}
- hideMagnetUriModal() {
- this.magnetUriModal.hide();
+ isUserLoggedIn() {
+ return this.authService.isLoggedIn();
}
private loadTooLong() {