Skip to content

Commit

Permalink
destroy hls converter on unload
Browse files Browse the repository at this point in the history
  • Loading branch information
jaruba committed Feb 25, 2024
1 parent d22d76d commit 98625ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/withStreamingServer/destroyHLSConverter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function destroyHLSConverter(streamingServerURL, id) {
return fetch(url.resolve(streamingServerURL, '/hlsv2/' + encodeURIComponent(id) + '/destroy'))
}

module.exports = destroyHLSConverter;
11 changes: 11 additions & 0 deletions src/withStreamingServer/withStreamingServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -26,6 +27,7 @@ function withStreamingServer(Video) {

var self = this;
var loadArgs = null;
var hlsConverterId = null;
var loaded = false;
var actionsQueue = [];
var videoParams = null;
Expand Down Expand Up @@ -140,6 +142,7 @@ function withStreamingServer(Video) {
mediaURL: mediaURL,
infoHash: infoHash,
fileIdx: fileIdx,
hlsConverterId: null,
stream: {
url: mediaURL
}
Expand All @@ -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) ?
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 = [];
Expand Down

0 comments on commit 98625ca

Please sign in to comment.