From ed905fd60be554bc9da20db7cb1b8c18b88078ac Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Mon, 24 Jun 2024 17:42:29 +0000 Subject: [PATCH] stream/manage: inherit controller from parent istream if it exists --- src/modules/stream/manage.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/stream/manage.js b/src/modules/stream/manage.js index 031d6711..06c73a6b 100644 --- a/src/modules/stream/manage.js +++ b/src/modules/stream/manage.js @@ -1,6 +1,7 @@ import NodeCache from "node-cache"; import { randomBytes } from "crypto"; import { nanoid } from "nanoid"; +import { setMaxListeners } from "node:events"; import { decryptStream, encryptStream, generateHmac } from "../sub/crypto.js"; import { env } from "../config.js"; @@ -79,7 +80,13 @@ export function createInternalStream(url, obj = {}) { } const streamID = nanoid(); - const controller = new AbortController(); + let controller = obj.controller; + + if (!controller) { + controller = new AbortController(); + setMaxListeners(Infinity, controller.signal); + } + internalStreamCache[streamID] = { url, service: obj.service,