react-nativewebrtcp2psimple-peer

How to use simple-peer with react-native-webrtc


I'm trying to use react-native-webrtc in the constructor for simple peer

import wrtc from 'react-native-webrtc';

const peer = new SimplePeer({initiator: true, wrtc: wrtc});

the error I'm getting is

ExceptionsManager.js:179 Error: No WebRTC support: Not a supported browser


Solution

  • you have to import it like this

    
    import {
      RTCPeerConnection,
      RTCIceCandidate,
      RTCSessionDescription,
      RTCView,
      MediaStream,
      MediaStreamTrack,
      mediaDevices,
      registerGlobals
    } from 'react-native-webrtc';
    
    const peer = new SimplePeer(
    {initiator: true, 
     wrtc: { 
      RTCPeerConnection,
      RTCIceCandidate,
      RTCSessionDescription,
      RTCView,
      MediaStream,
      MediaStreamTrack,
      mediaDevices,
      registerGlobals
      },
    });