_isReactNativeWebrtc not compatible with latest react-native-webrtc, causing failure to connect on React Native
- Dominant language
- JavaScript
- Stars
- 7.8k
- Forks
- 983
- PR merge metrics
- No merged PRs in 30d
Description
**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`: https://github.com/feross/simple-peer/blob/f1a492d1999ce727fa87193ebdea20ac89c1fc6d/index.js#L109 which was [removed from react-native-webrtc's `RTCPeerConnection` a few years ago (replaced by `_pcId`)](https://github.com/react-native-webrtc/react-native-webrtc/blob/2ffa3e90d31a2647eab7ced0a12d36c68e0b9b16/src/RTCPeerConnection.ts#L75) – 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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.