Basic Y.js Websocket

Hi. I’m having trouble implementing Y-websocket with React. I’m running a y-websocket-server then using the code below to connect.

 const wsProvider = new WebsocketProvider(
        'ws://localhost:1234', 'room',
        doc,
        { WebSocketPolyfill: WebSocket }
      )

When I run it locally it works, but I want other devices in the same network to access the websocket. When I use my IP address instead of localhost, it doesn’t connect. So, it’s currently only working on the device running the websocket server, but not any other local devices.

Am I approaching this wrong? How would I fix this?

You probably just have to set HOST=0.0.0.0 y-websocket-server instead of localhost.

Your OS might also prevent outside communication. Check your firewall settings and search for similar issues for your operating system.

1 Like