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

is react-native-peerjs still working ? call.on(stream issue #1030

Open
veeyka opened this issue Feb 4, 2023 · 3 comments
Open

is react-native-peerjs still working ? call.on(stream issue #1030

veeyka opened this issue Feb 4, 2023 · 3 comments
Labels
client related to peerjs client

Comments

@veeyka
Copy link

veeyka commented Feb 4, 2023

does react-native-peerjs works and is it useable ?
im working with this now and every thing works except that call response fires no event . and its event count is 0 ,
my code is good and simple as docs everywhere .
my react native code :

React.useEffect(()=>{
socket.clientSocket.on("connect", ()=>{
console.log("----- - - --- - - socket connection")
});

const start = async () => {
    let s;
    try {
      s = await mediaDevices.getUserMedia({ video: true});

      peer.peerServer.on("open" , (peerId)=>{
        socket.clientSocket.emit("join-room" , {peerId , userId: pageStates.userId , roomId: pageStates.roomId});
      });

      // user entered
      socket.clientSocket.on("a-user-entered" , ({newUserPeerId , newUserId})=>{
            const call = peer.peerServer.call(newUserPeerId, s);
             call.on("stream" , (remoteVideoStream)=>{
                  if(remoteVideoStream){
                         console.log("stream" , remoteVideoStream)
                  }
            });
      });

      peer.peerServer.on("call" , (call)=>{
    
        call.answer(s);
        call.on("stream" , (remoteS)=>{
          console.log("and we got " + remoteS)
        });
      });
     
    } 
};
start();
},[])

and also my call response log is :

{"_events": {}, "_eventsCount": 0, "_localStream": {"_reactTag": "6b63bf42-2383-45cc-9458-2f20927dbb8c", "_tracks": [[MediaStreamTrack]], "active": true, "id": "6b63bf42-2383-45cc-9458-2f20927dbb8c"}, "_negotiator": {"connection": [Circular]}, "_open": false, "connectionId": "mc_20pq73qhn40i", "metadata": undefined, "options": {"_stream": {"_reactTag": "6b63bf42-2383-45cc-9458-2f20927dbb8c", "_tracks": [Array], "active": true, "id": "6b63bf42-2383-45cc-9458-2f20927dbb8c"}}, "peer": "a524dd90-c02e-4378-97ef-f364b502ee07", "peerConnection": {"_pcId": 1, "_remoteStreams": Map {}, "_transceivers": [], "connectionState": "new", "iceConnectionState": "new", "iceGatheringState": "new", "localDescription": null, "onaddstream": [Function anonymous], "remoteDescription": null, "signalingState": "stable"}, "provider": {"_api": {"_options": [Object]}, "_connections": Map {"a524dd90-c02e-4378-97ef-f364b502ee07" => [Array]}, "_destroyed": false, "_disconnected": false, "_events": {"call": [r], "discounnect": [r], "error": [r], "open": [r]}, "_eventsCount": 4, "_id": "0cc522b5-04d5-4b18-aa8b-30c83900373b", "_lastServerId": "0cc522b5-04d5-4b18-aa8b-30c83900373b", "_lostMessages": Map {}, "_open": true, "_options": {"config": [Object], "debug": 0, "host": "node2.bonyadonline.com", "key": "peerjs", "path": "/peer-server/", "port": 443, "secure": true, "token": "106ukcqolqv"}, "_socket": {"_baseUrl": "wss://node2.bonyadonline.com:443/peer-server/peerjs?key=peerjs", "_disconnected": false, "_events": [Object], "_eventsCount": 4, "_id": "0cc522b5-04d5-4b18-aa8b-30c83900373b", "_messagesQueue": [Array], "_socket": [WebSocket], "_wsPingTimer": 46, "pingInterval": 5000}}}

@Baneist
Copy link

Baneist commented May 30, 2023

The same issue. is the problem solved?

@anion155
Copy link

I have managed to make it work, and I'm not using 'react-native-peerjs'. I have added patch you can found here webrtcHacks/adapter#1129 . It can be applied with patch-package. And I have ended up listening for an open event like this.

if (!dataConn.open) {
  await new Promise<void>(resolve => {
    dataConn.on('open', resolve);

    // FIXME: no open event fired before listeners ready
    const interval = setInterval(() => {
      const state = dataConn.dataChannel?.readyState;
      console.log('----', state);
      if (state === 'open') {
        clearInterval(interval);
        if (!dataConn.open) {
          (dataConn as any)._open = true;
          dataConn.emit('open');
        }
      }
    }, 50);
  });
}

Looks like peerjs too late in subscribing to open, and it's just not handled right away. But I did not checked calling yet

@Baneist
Copy link

Baneist commented Jun 17, 2023

it works. thanks a lot !!

@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
client related to peerjs client
Projects
None yet
Development

No branches or pull requests

4 participants