Hi, using the Livekit React Native SDK for our Exp...
# ask-ai
s
Hi, using the Livekit React Native SDK for our Expo React Native iOS app, we're running into a problem where after entering and then disconnecting a room, we're then unable to use the iOS microphone to record for non-Livekit uses. It feels like the LiveKit is somehow still holding onto the microphone input. Why is this the case, or what are we missing in disconnecting and tearing down the room so we can use the microphone to record for LiveKit uses?
t
Thanks for reaching out, Clark. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! To make sure the microphone is properly released after you disconnect from a LiveKit room in your React Native iOS app, here’s a simple way to handle it: 1. First, call
room.disconnect()
to leave the room. 2. Then, stop the audio session by calling
AudioSession.stopAudioSession()
right after disconnecting. 3. Also, it’s super helpful to add cleanup logic inside your React component’s
useEffect
return function. Here’s a quick example:
Copy code
useEffect(() => {
  const connect = async () => {
    await AudioSession.startAudioSession();
    await room.connect(url, token, {});
  };
  connect();

  return () => {
    room.disconnect();
    AudioSession.stopAudioSession();
  };
}, [url, token, room]);
One more thing—if you have any local audio tracks that you’re done with, make sure to stop those too. The SDK does a great job handling this automatically when
stopOnMute
is enabled. If you run into any issues or want to chat more about this, just let me know—I’m here to help! Sources: src/index.tsx | src/room/track/LocalAudioTrack.ts | app/assistant/index.tsx
s
how to enable stopOnMute?