peers / peerjs

Simple peer-to-peer with WebRTC.
https://peerjs.com
MIT License
12.38k stars 1.43k forks source link

PeerJS not working with React #641

Open anim8rDev opened 4 years ago

anim8rDev commented 4 years ago

I was excited to get PeerJS working my local developer environment using Gatsby/React. However, when I went to build the website, it didn't work because, come to find out, PeerJs must be trying to access the window.

Does anyone know how to get around this? An alternative that I can try?

Thanks

poison commented 4 years ago

Yes, it's a very annoying dependency which kills server-side rendering (SSR) like on NextJS. I ended up by moving the PeerJS to the 'store' layers, using redux-saga for my experiment, using eventChannels (https://redux-saga.js.org/docs/advanced/Channels.html). I only start the saga when I'm in client-side scope and I have 'window' available.

export default function* rootSaga() {
  // NextJS' webpack config injects process.browser if this snippet is running in the browser
  if (process.browser) {
    yield all([...gameSagas])
  }
}

Good luck!

gax97 commented 4 years ago

I managed to get around this by importing react component that uses peerjs with @loadable/component.

B-Pratik commented 4 years ago

I have created this POC for video calling web-app with react. https://github.com/B-Pratik/call-it hosted on Heroku

j-mcgregor commented 3 years ago

Yes, it's a very annoying dependency which kills server-side rendering (SSR) like on NextJS. I ended up by moving the PeerJS to the 'store' layers, using redux-saga for my experiment, using eventChannels (https://redux-saga.js.org/docs/advanced/Channels.html). I only start the saga when I'm in client-side scope and I have 'window' available.

export default function* rootSaga() {
  // NextJS' webpack config injects process.browser if this snippet is running in the browser
  if (process.browser) {
    yield all([...gameSagas])
  }
}

Good luck!

Hey :-) long shot I know since it was a long time ago you answered, but I could use some help with running PeerJS in NextJS with Redux Saga. I'm using next-redux-wrapper and all my Sagas run fine, but no matter how I try and use PeerJS it always responds with navigator not found, which I know is a SSR problem, but like I said, I can't stop the PeerJS code running before the browser is present