Client: remove videojs on destroy
This commit is contained in:
parent
99cc4f4948
commit
067e3f84ce
|
@ -25,6 +25,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
loading: boolean = false;
|
loading: boolean = false;
|
||||||
numPeers: number;
|
numPeers: number;
|
||||||
player: VideoJSPlayer;
|
player: VideoJSPlayer;
|
||||||
|
playerElement: Element;
|
||||||
uploadSpeed: number;
|
uploadSpeed: number;
|
||||||
video: Video = null;
|
video: Video = null;
|
||||||
|
|
||||||
|
@ -54,23 +55,30 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.playerElement = this.elementRef.nativeElement.querySelector('#video-container');
|
||||||
|
|
||||||
const videojsOptions = {
|
const videojsOptions = {
|
||||||
controls: true,
|
controls: true,
|
||||||
autoplay: false
|
autoplay: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
videojs('video-container', videojsOptions, function () {
|
videojs(this.playerElement, videojsOptions, function () {
|
||||||
self.player = this;
|
self.player = this;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
|
// Remove WebTorrent stuff
|
||||||
console.log('Removing video from webtorrent.');
|
console.log('Removing video from webtorrent.');
|
||||||
clearInterval(this.torrentInfosInterval);
|
clearInterval(this.torrentInfosInterval);
|
||||||
clearTimeout(this.errorTimer);
|
clearTimeout(this.errorTimer);
|
||||||
this.webTorrentService.remove(this.video.magnetUri);
|
this.webTorrentService.remove(this.video.magnetUri);
|
||||||
|
|
||||||
|
// Remove player
|
||||||
|
videojs(this.playerElement).dispose();
|
||||||
|
|
||||||
|
// Unsubscribe route subscription
|
||||||
this.sub.unsubscribe();
|
this.sub.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +104,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|
||||||
console.log('Added ' + this.video.magnetUri + '.');
|
console.log('Added ' + this.video.magnetUri + '.');
|
||||||
torrent.files[0].renderTo('#video-container video', { autoplay: true }, (err) => {
|
torrent.files[0].renderTo(this.playerElement, { autoplay: true }, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
alert('Cannot append the file.');
|
alert('Cannot append the file.');
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
Loading…
Reference in New Issue