From 98625ca76013a364fa8b0fd68d9de0866626f577 Mon Sep 17 00:00:00 2001 From: Alexandru Branza Date: Sun, 25 Feb 2024 14:55:41 +0200 Subject: [PATCH] destroy hls converter on unload --- src/withStreamingServer/destroyHLSConverter.js | 5 +++++ src/withStreamingServer/withStreamingServer.js | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/withStreamingServer/destroyHLSConverter.js diff --git a/src/withStreamingServer/destroyHLSConverter.js b/src/withStreamingServer/destroyHLSConverter.js new file mode 100644 index 0000000..06608ee --- /dev/null +++ b/src/withStreamingServer/destroyHLSConverter.js @@ -0,0 +1,5 @@ +function destroyHLSConverter(streamingServerURL, id) { + return fetch(url.resolve(streamingServerURL, '/hlsv2/' + encodeURIComponent(id) + '/destroy')) +} + +module.exports = destroyHLSConverter; diff --git a/src/withStreamingServer/withStreamingServer.js b/src/withStreamingServer/withStreamingServer.js index e8ff622..37173a9 100644 --- a/src/withStreamingServer/withStreamingServer.js +++ b/src/withStreamingServer/withStreamingServer.js @@ -6,6 +6,7 @@ var deepFreeze = require('deep-freeze'); var mediaCapabilities = require('../mediaCapabilities'); var convertStream = require('./convertStream'); var fetchVideoParams = require('./fetchVideoParams'); +var destroyHLSConverter = require('./destroyHLSConverter'); var ERROR = require('../error'); function withStreamingServer(Video) { @@ -26,6 +27,7 @@ function withStreamingServer(Video) { var self = this; var loadArgs = null; + var hlsConverterId = null; var loaded = false; var actionsQueue = []; var videoParams = null; @@ -140,6 +142,7 @@ function withStreamingServer(Video) { mediaURL: mediaURL, infoHash: infoHash, fileIdx: fileIdx, + hlsConverterId: null, stream: { url: mediaURL } @@ -166,6 +169,7 @@ function withStreamingServer(Video) { mediaURL: mediaURL, infoHash: infoHash, fileIdx: fileIdx, + hlsConverterId: id, stream: { url: url.resolve(commandArgs.streamingServerURL, '/hlsv2/' + id + '/master.m3u8?' + queryParams.toString()), subtitles: Array.isArray(commandArgs.stream.subtitles) ? @@ -200,6 +204,7 @@ function withStreamingServer(Video) { stream: result.stream }) }); + hlsConverterId = result.hlsConverterId; loaded = true; flushActionsQueue(); fetchVideoParams(commandArgs.streamingServerURL, result.mediaURL, result.infoHash, result.fileIdx, commandArgs.stream.behaviorHints) @@ -273,6 +278,12 @@ function withStreamingServer(Video) { return true; } case 'unload': { + if (loadArgs && hlsConverterId !== null) { + destroyHLSConverter(loadArgs.streamingServerURL, hlsConverterId).catch(function(error) { + console.error(error); + }); + } + hlsConverterId = null; loadArgs = null; loaded = false; actionsQueue = [];