peers / peerjs

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

peer.connect not open on some users #1189

Open Elabbasy00 opened 4 months ago

Elabbasy00 commented 4 months ago

I am using peerjs custom server on nodejs and the client is Electron app

    const handelPeer = async (peerId: string) => {
    const id = `${Math.random().toString(16).slice(2)}_${user?.username
      ?.replaceAll(' ', '_')
      .toString()!}`;

    const peer = new Peer(id, {
      host: 'xxx.xxxx.xxx',
      path: '/peerjs',
      secure: true,
    });

    peer.on('open', () => {

      const connection = peer.connect(peerId); // Never called on some users 

      connection.on('open', async () => {
        dataSream.current = await createStream();
        callRef.current = peer.call(peerId, dataSream.current);

        callRef.current?.on('error', (e) => {
          console.log('error', e);
        });
        callRef.current?.on('close', () => {
          cleanUp(connection);
        });
      });

      connection.on('close', () => {
        cleanUp(connection);
      });
      connection.on('error', (e: any) => {
        console.log('got connection error', e);
      });
    });

    peer.on('disconnected', () => {
      console.log('disconnect');
      cleanUp();
    });

    peer.on('error', (error) => {

      cleanUp();

    });
  };

everything working great but it's not working on some users' devices without errors after debugging I have figured that peer.connect never open even on setTimeOut console.log(connection)

Screenshot 2024-01-11 at 6 09 20 PM