Skip to content

Commit 777d706

Browse files
committed
fix(js): make setupListeners idempotent to avoid double-registration
addListener appends subscriptions without de-duping, so a second registerGlobals() left two live listeners per blocking event and invoked each app handler twice per round. Guard setupListeners with a listenersSetUp flag so repeat calls are no-ops.
1 parent a8ea041 commit 777d706

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/AudioDeviceModuleEvents.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,18 @@ class AudioDeviceModuleEventEmitter {
5959
private didDisableEngineHandler: AudioEngineEventHandler | null = null;
6060
private willReleaseEngineHandler: AudioEngineEventNoParamsHandler | null = null;
6161

62+
private listenersSetUp = false;
63+
6264
public setupListeners() {
6365
if (Platform.OS !== 'android' && WebRTCModule) {
66+
// addListener appends without de-duping, so guard against a second
67+
// registerGlobals() double-registering listeners and double-invoking handlers.
68+
if (this.listenersSetUp) {
69+
return;
70+
}
71+
72+
this.listenersSetUp = true;
73+
6474
// Setup handlers for blocking delegate methods
6575
addListener(this, 'audioDeviceModuleEngineCreated', async (event: unknown) => {
6676
const { requestId } = event as EngineEventPayload;

0 commit comments

Comments
 (0)