mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
EventEmitter memory leak detected
This commit is contained in:
1 parent
a6ac14aff1
commit
0c1f9adb12
1 file changed
+34
@@ -27,6 +27,9 @@ const WEBM_MAGIC = Buffer.from([0x1a, 0x45, 0xdf, 0xa3]);
|
|||||||
/** @type {Buffer} @description OGG container magic bytes ("OggS"). */
|
/** @type {Buffer} @description OGG container magic bytes ("OggS"). */
|
||||||
const OGG_MAGIC = Buffer.from("OggS", "ascii");
|
const OGG_MAGIC = Buffer.from("OggS", "ascii");
|
||||||
|
|
||||||
|
/** @type {number} @description livekit TrackKind.KIND_AUDIO — publications with this kind are managed by the bridge. */
|
||||||
|
const TRACK_KIND_AUDIO = 1;
|
||||||
|
|
||||||
/** @extends {EventEmitter} */
|
/** @extends {EventEmitter} */
|
||||||
export class FluxerAudioBridge extends EventEmitter {
|
export class FluxerAudioBridge extends EventEmitter {
|
||||||
_conn = null;
|
_conn = null;
|
||||||
@@ -77,6 +80,8 @@ export class FluxerAudioBridge extends EventEmitter {
|
|||||||
this.stop();
|
this.stop();
|
||||||
if (!conn) throw new Error("[AudioBridge] No voice connection provided");
|
if (!conn) throw new Error("[AudioBridge] No voice connection provided");
|
||||||
|
|
||||||
|
this._unpublishStaleAudioTracks(conn);
|
||||||
|
|
||||||
const generation = ++this._playGeneration;
|
const generation = ++this._playGeneration;
|
||||||
this._conn = conn;
|
this._conn = conn;
|
||||||
this._playing = true;
|
this._playing = true;
|
||||||
@@ -576,6 +581,7 @@ export class FluxerAudioBridge extends EventEmitter {
|
|||||||
|
|
||||||
if (this._conn) {
|
if (this._conn) {
|
||||||
try { this._conn.stop(); } catch (_) {}
|
try { this._conn.stop(); } catch (_) {}
|
||||||
|
this._unpublishStaleAudioTracks(this._conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wasPlaying) {
|
if (wasPlaying) {
|
||||||
@@ -584,6 +590,34 @@ export class FluxerAudioBridge extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {object} conn - Fluxer voice connection
|
||||||
|
* @param {string|null} [keepSid=null] - Track SID to keep (currently active publication)
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_unpublishStaleAudioTracks(conn, keepSid = null) {
|
||||||
|
try {
|
||||||
|
const room = conn?.room;
|
||||||
|
const participant = room?.localParticipant;
|
||||||
|
if (!room?.isConnected || typeof participant?.unpublishTrack !== "function") return;
|
||||||
|
|
||||||
|
const publications = participant.trackPublications;
|
||||||
|
if (!publications || typeof publications.entries !== "function") return;
|
||||||
|
|
||||||
|
for (const [sid, pub] of publications.entries()) {
|
||||||
|
if (keepSid && sid === keepSid) continue;
|
||||||
|
if (pub?.kind !== TRACK_KIND_AUDIO) continue;
|
||||||
|
try {
|
||||||
|
const p = participant.unpublishTrack(sid, true);
|
||||||
|
if (p?.catch) p.catch(() => {});
|
||||||
|
logger.player("[AudioBridge] Unpublished stale audio track: " + sid);
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
// Never let cleanup break playback.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the playback volume on the voice connection.
|
* Set the playback volume on the voice connection.
|
||||||
* @param {number} percent - Volume 0–100.
|
* @param {number} percent - Volume 0–100.
|
||||||
|
|||||||
Reference in new issue
Block a user