bug: [React Native] InCallManager is started per meeting but never stopped

Open
#209 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
react-native, typescript
Domain
mobile

Research direction

Start with lib/module/NativeAudioManager.js, lib/module/LocalMediaHandler.js, and lib/module/ReactHooks.js, tracing where audio starts and where meeting teardown runs. Check the native Android and iOS stop signatures, then verify cleanup across leave, a second meeting, stage leave and return, and a connected meeting hot-swap. Done means audio resources are released and restarted correctly without an older client stopping a newer meeting's audio.

Written by the indexing model from the issue text.

Description

Package: @cloudflare/realtimekit-react-native 2.0.0 (same code in 2.0.1-staging.0).

What happens

The LocalMediaHandler constructor calls NativeAudioManager.start({ media: 'video' }), but NativeAudioManager.stop() is never called anywhere in lib/. Neither destruct() nor cleanUpEvents() calls it. After a meeting ends:

  • Android: InCallManagerModule.start() acquires a partial wake lock, requests audio focus and sets defaultAudioMode (MODE_IN_COMMUNICATION). All three stay active after leave(), so the device can stay in call mode and other apps' audio can stay ducked.
  • iOS: RNInCallManager keeps _audioSessionInitialized = YES, the VideoChat session and the idle-timer override. On the next meeting, start returns early (if (_audioSessionInitialized) return;), so the audio session is not set up again.

There is also a latent signature mismatch. iOS exports stop:(NSString *)busytoneUriType, but NativeAudioManager.stop() passes {} on iOS. Once stop is actually called, debug builds raise a JSON→NSString conversion error.

How to observe (derived from the source; not captured on a device)
  1. Join a meeting, then meeting.leave().
  2. Android: adb shell dumpsys audio should still show the communication mode, and adb shell dumpsys power should still list the wake lock.
  3. iOS: start a second meeting in the same app session. start should return at the _audioSessionInitialized check, leaving the session as the previous meeting set it.
Suggested fix

Stop the audio manager when local media is torn down and before a new client is created, and pass a string on iOS:

--- a/lib/module/NativeAudioManager.js
+++ b/lib/module/NativeAudioManager.js
@@ -14,7 +14,7 @@
     if (media === 'audio') _InCallManager.setVoiceCallMode();
   }
   stop() {
-    Platform.OS === 'android' ? _InCallManager.stop() : _InCallManager.stop({});
+    Platform.OS === 'android' ? _InCallManager.stop() : _InCallManager.stop('');
   }
   async getIsWiredHeadsetPluggedIn() {
     try {
--- a/lib/module/LocalMediaHandler.js
+++ b/lib/module/LocalMediaHandler.js
@@ -880,6 +880,7 @@
     this.stopVideoTrack();
     this.stopScreenShareTracks();
     if (Platform.OS === 'android') this.#appStateSubscription?.remove();
+    NativeAudioManager.stop();
   }
   stopAudioTrack() {
     this.rawAudioTrack?.stop();
--- a/lib/module/ReactHooks.js
+++ b/lib/module/ReactHooks.js
@@ -9,6 +9,7 @@
 import { deviceChangeListener } from './LocalMediaUtils';
 import { broadcastEmitter } from './LocalMediaHandler';
 import LocalMediaHandler from './LocalMediaHandler';
+import NativeAudioManager from './NativeAudioManager';
 
 /**
  * Public configuration for the Android meeting foreground service.
@@ -157,6 +158,7 @@
 function cleanUpEvents() {
   webRTCModuleEmitter.removeAllListeners('audioSamples');
   deviceChangeListener.removeAllListeners('onAudioDeviceChanged');
+  NativeAudioManager.stop();
   BackgroundTimer.stop();
   try {
     if (Platform.OS === 'android') {

This is a minimal fix with two known limits:

  • destruct() also runs when the server moves the participant off stage (stage.leave() → cleanupSelf). With this patch, InCallManager is not restarted if the participant comes back on stage with the same handler. A complete fix probably needs setupAudioStream to call start again when needed. We haven't tested the stage case.
  • InCallManager is a process-wide singleton. If the previous client's leave() finishes after a new meeting has started (e.g. during the connected-meetings hot-swap in useRealtimeKitClient), its destruct() stops the new meeting's audio manager. Tracking which handler started it would avoid this.
Dominant language
TypeScript
Stars
74
Forks
26
Avg merge
1d 2h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudflare/realtimekit-ui

All issues in cloudflare/realtimekit-ui

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.