Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PeerJS not working with React #641

Open
anim8rDev opened this issue Mar 31, 2020 · 4 comments
Open

PeerJS not working with React #641

anim8rDev opened this issue Mar 31, 2020 · 4 comments
Labels
bug client related to peerjs client

Comments

@anim8rDev
Copy link

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
Copy link

poison commented Apr 1, 2020

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
Copy link

gax97 commented May 6, 2020

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

@afrokick afrokick added the bug label May 11, 2020
@B-Pratik
Copy link

B-Pratik commented Aug 4, 2020

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

@j-mcgregor
Copy link

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

@irgalamarr irgalamarr added the client related to peerjs client label Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug client related to peerjs client
Projects
None yet
Development

No branches or pull requests

7 participants