Skip to content

_isReactNativeWebrtc not compatible with latest react-native-webrtc, causing failure to connect on React Native #947

@davidisaaclee

Description

@davidisaaclee

What version of this package are you using?
9.11.1

What operating system, Node.js, and npm version?
iOS 18.6.2 / idk, n/a afaik but can get it if needed

What happened?
Attempting to connect two React Native peers correctly signals, but SimplePeer never emits a connect. (The underlying RTCPeerConnection does transition to a connected connectionState.)

Debugging, I saw that getStats took the non-_isReactNativeWebrtc branch because _isReactNativeWebrtc was false, despite running on a RN platform. To be sure, I executed getStats in console and got a Promise back – so it's a bug that we didn't take the promise-based getStats branch.

_isReactNativeWebrtc checks _peerConnectionId:

this._isReactNativeWebrtc = typeof this._pc._peerConnectionId === 'number'
which was removed from react-native-webrtc's RTCPeerConnection a few years ago (replaced by _pcId) – so the current check on typeof resolves to 'undefined'.

This would be fixed by either (or both of):

  1. Change _isReactNativeWebrtc to check typeof _pcId
  2. Allow the caller to pass in isReactNativeWebrtc in the SimplePeer constructor opts – more work for caller, but avoids getting stuck with this kind of breakage in the future, as _pcId is a heuristic and not a stable API

I patched in (2) in my local dependency to unblock myself, and it appears to work.

Sorry to mess with the PR template – it just seems like the bug is apparent from the source. I can be more formal if it's really needed.

Are you willing to submit a pull request to fix this bug?
Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions