client-sdk-react-native icon indicating copy to clipboard operation
client-sdk-react-native copied to clipboard

TrackID is undefined during auto publishing of microphone track (audio={true}) in LiveKitRoom (React Native SDK)

Open ayush10000 opened this issue 7 months ago • 7 comments

I’m encountering an issue in the React Native SDK (@livekit/react-native) where auto-publishing of the microphone track sometimes results in a missing track ID. When using the LiveKitRoom component with audio set to true, the SDK automatically handles microphone publishing. However, during this process, the published track sometimes shows trackID as undefined, leading to a runtime error: “TypeError: Cannot read property 'toLowerCase' of undefined” Which seems to come from internal SDK code, where toLowerCase() is called on trackID, assuming it is a string. My setup involves the @livekit/react-native SDK (latest version) running on both Android and iOS platforms. I’m using the LiveKitRoom component in this way: TSX

<LiveKitRoom
  serverUrl="wss://your-livekit-server-url.livekit.cloud"
  token={token}
  connect={true}
  audio={true}
  video={false}
/>

I’m not manually creating or publishing any tracks—the SDK is responsible for auto-publishing the microphone track. However, the SDK sometimes publishes a track object like this:

json
{
  "enabled": true,
  "kind": "audio",
  "muted": false,
  "pID": "PA_dVTQPxudDipR",
  "participant": "qOFJJ4pRNCMHEox2MrN7Gc5PlMO2",
  "room": "room_qOFJJ4pRNCMHEox2MrN7Gc5PlMO2",
  "source": "microphone",
  "streamID": "8297a9c7-3d83-4d40-8301-baa46c419a45",
  "streamTrackID": "8297a9c7-3d83-4d40-8301-baa46c419a45",
  "trackID": undefined
}

Shortly after, I received this error in the logs:

javascript
**TypeError: Cannot read property 'toLowerCase' of undefined**

I expect the SDK to assign a valid string trackID to any auto-published microphone track and to handle cases where trackID might be missing before calling any string methods on it. Since track control is fully managed inside the SDK and not exposed in the React Native version, I believe this is an internal SDK bug. Please let me know if this is a known issue, whether there’s a temporary workaround, or if sharing a minimal reproduction repo would help in diagnosing the problem. Thank you for your work on LiveKit—I look forward to your guidance.

ayush10000 avatar Jul 17 '25 07:07 ayush10000

I'm encountering the same issue

Sumiya-ii avatar Jul 19 '25 04:07 Sumiya-ii

Same here!

tinomarques avatar Jul 19 '25 11:07 tinomarques

same issue, any update @davidliu

fuocpham avatar Jul 21 '25 03:07 fuocpham

Hmm, we don't call toLowerCase() on trackId anywhere in this library or in livekit-client. Is there some more logs indicating which line of code it's coming from?

It sorta sounds similar to issue #222, but really need some more information. It'd be great if you could include a repro, as I don't see it on my end.

davidliu avatar Jul 23 '25 09:07 davidliu

what worked for me, check that this is present in index.js

  const { registerGlobals } = require('@livekit/react-native');
  registerGlobals();

make sure that registerGlobals is imported from this library and not react-native-webrtc

15rock-naman-gupta avatar Aug 14 '25 09:08 15rock-naman-gupta

I have the exact same issue with android, solution offered by @15rock-naman-gupta isnt working in my case. enabling audio for livekit in android still uresolved.

letoyian avatar Sep 22 '25 20:09 letoyian

"publishing track"{ "room":"call-1765653122252", "roomID":"RM_GUKjuNJoK59r", "participant":"aa55f9f0-578a-11f0-b526-11be3533b15c", "pID":"PA_uPCD7YduXKfe", "trackID":"undefined", "source":"microphone", "muted":false, "enabled":true, "kind":"audio", "streamID":"FA5083EB-4404-46D0-9666-01A46634E226", "…" }

"trackID":"undefined",

@davidliu "@livekit/react-native": "^2.9.4", "@livekit/react-native-webrtc": "^137.0.2", "livekit-client": "^2.15.15", "react-native": "^0.81.0",

AbdulRehman960 avatar Dec 13 '25 19:12 AbdulRehman960

@AbdulRehman960 this log is emitted before the track is actually published, and before a trackId is assigned from the server. trackId being undefined here is expected.

davidliu avatar Feb 09 '26 08:02 davidliu

Closing as dupe of https://github.com/livekit/client-sdk-js/issues/1433

Please ensure that you call registerGlobals() from the @livekit/react-native package, as shown in our usage instructions.

davidliu avatar Feb 09 '26 08:02 davidliu