react-native-webrtc: requireNativeComponent is not exported from 'react-native'

I am trying to setup a simple project where I am returning a camera stream in RTC View.

I keep getting this error and I have no idea why.

Failed to compile.

./node_modules/react-native-webrtc/RTCView.js
Attempted import error: 'requireNativeComponent' is not exported from 'react-native'.

import React, {useRef, useEffect} from 'react';
import {
  RTCPeerConnection,
  RTCIceCandidate,
  RTCSessionDescription,
  RTCView,
  MediaStream,
  MediaStreamTrack,
  mediaDevices,
  registerGlobals,
} from 'react-native-webrtc';

function ViewCamera() {
  const videoStream= useRef(null);

  useEffect(() => {
    if (!videoStream) {
      return;
    }
    mediaDevices.getUserMedia({video: true}).then((stream) => {
      let video = videoStream.current;
      video.srcObject = stream;
      video.play();
      console.log(stream);
    });
  }, [videoStream]);

  return <RTCView streamURL={videoStream.current.srcObject.toUrl()} />;
}

export default ViewCamera;

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (11 by maintainers)

Most upvoted comments

I built a shim for react-native-web allowing you to use (almost) the same code in react-native-web as in react-native. It works with expo, as long as you eject.

The code itself is pretty short to read, just about 100 lines total (excluding tests). Includes a demo expo app with KITE tests ensuring it works across Chrome/Firefox/Safari.

Repo is at https://github.com/ruddell/react-native-webrtc-web-shim, any feedback is welcome.

The shin would be pretty simple actually, since WebRTC is a standard browser API. Checking the W3C WebRTC API and exporting the necessary parts would be a reasonable next step.