DownloadManager should use custom events to signal the pause request.

This commit is contained in:
Jaroslav Polakovič 2022-01-19 07:30:50 +01:00
Родитель 10ff66bc71
Коммит f2e0c8b324
2 изменённых файлов: 23 добавлений и 1 удалений

Просмотреть файл

@ -226,7 +226,11 @@ export default class DownloadManager {
*/
forcePause() {
this.pause();
this.internal.videoDownloader.downloading = false;
if (document) {
const pauseEvent = new CustomEvent('pausedownload', { detail: this.videoId });
document.dispatchEvent(pauseEvent);
}
}
/**

Просмотреть файл

@ -27,6 +27,10 @@ export default class VideoDownloaderRegistry {
constructor({ connectionStatus }) {
this.instances = new Map();
this.connectionStatus = connectionStatus;
if (document) {
document.addEventListener('pausedownload', this.onPauseDownload.bind(this));
}
}
/**
@ -67,4 +71,18 @@ export default class VideoDownloaderRegistry {
destroyAll() {
this.instances.clear();
}
/**
* When a pause request is received, we need to pause the download.
*
* @param {CustomEvent} e Pause event.
* @param {string} e.detail Video ID.
*/
onPauseDownload(e) {
const downloaderInstance = this.get(e.detail);
if (downloaderInstance) {
downloaderInstance.downloading = false;
}
}
}