Skip to content

[react-native] WebRTC TrackSubscribed handler uses web-only DOM APIs #641

@kraenhansen

Description

@kraenhansen

Problem

The TrackSubscribed handler in WebRTCConnection.ts (line 355-401) uses web-only APIs that don't exist in React Native:

  1. remoteAudioTrack.attach() internally calls document.createElement('audio')
  2. document.body.appendChild(audioElement)
  3. setupAudioCapture() uses AudioContext and AudioWorkletNode

Since v1.0.0 defaults to WebRTC for voice connections, and the React Native setup strategy (reactNativeSessionSetup) delegates to webSessionSetup() without any RN-specific WebRTC handling, this code path runs unguarded on React Native.

Impact

  • The async handler throws, so setupAudioCapture is never reached
  • No onAudio callback fires for agent audio
  • No output analyser available (getOutputByteFrequencyData returns null)
  • setVolume() has no effect (empty audioElements array)
  • Audio may still play via LiveKit's native WebRTC layer, but mode/callbacks are broken

Found during

Investigation of #635

Suggested fix

Guard the DOM-specific code in the TrackSubscribed handler to skip attach(), appendChild, and setupAudioCapture when running in React Native, relying on LiveKit's native audio playback instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions