I am having problem with webRTC video call, with nodejs

Viewed 24

So i am using webRTC for video call application, it works fine locally, but while I host my react app and node backend in Ip. Chat works fine, but there is an error in the following function

const constraints = { audio: true, video: audioOnly ? false : true };
 console.log(navigator)
  navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
    console.log(stream)
    store.dispatch(setLocalStream(stream) as any);

    if (callback) {
        callback();
    }
    
}).catch((err) => {
    console.log(err);
    console.log("Error getting local stream");
})

There is an error that shows: Uncaught TypeError: Cannot read properties of undefined (reading 'getUserMedia') at getLocalStreamPreview

Can anyone help me how can I solve this issue ?

1 Answers

getUserMedia is a part of the Browser API. It will not be available if you have some kind of SSR/server-processing enabled. Just make sure the component is mounted already before you call getUserMedia and it should work fine.

Related