peers / peerjs

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

The call's stream event never fires. #617

Closed CryptishApps closed 2 years ago

CryptishApps commented 4 years ago

Thanks for this awesome bit of work you've put together.

I have an electron/node app running on localhost (laptop) and a react native app running on my mobile (using this)

Both can get an ID from either your server or one that I run locally, no problems there.

Using peer.call(mobileId, stream); on my laptop. This ends up triggering the mobPeer.on('call', function(call) { as expected.

However, the call.on('stream', function(stream) { never gets executed, no matter what I seem to do. Any help would be appreciated.

Electron Project (laptop):

let mobileId = doc.data().mobileId;
let conn = webPeer.connect(mobileId);
conn.on('open', function() {

    const call = webPeer.call(mobileId, stream);

    call.on('stream', function(mobStream){
        console.log("Got null stream", mobStream)
    });
});

React Native code:

const mobPeer = new Peer({
    host: ipv4, secure: false, port: 8090, path: '/peer',
});

mobPeer.on('error', function(err) {
    console.log("MOB CONN ERROR", err);
})

mobPeer.on('open', function(id) {
    console.log("mobile id", id)
    // I send ID to database here for electron app to find
});

mobPeer.on('call', function(call) {
    console.log("Web calling"); // this works fine

    call.answer(null);
    call.on('stream', function(stream) {
        console.log('stream from desktop') // this never runs
    });
});
geocontrol commented 4 years ago

Have you made any progress with this? I have just tried to make a basic app to share data between two devices, its getting the ID, its connecting, but then there is no connection.on('open' event happening that i can see, so no data sent / received etc. I have tried multiple browsers and from a number of different locations (networks and firewall settings) all show the same behaviour.

Cheers

Mark

CryptishApps commented 4 years ago

Yes, my issue was with react-native-peerjs, which the author just solved by releasing 1.0.4. Are you using that?

geocontrol commented 4 years ago

ah, no just the standard JS library here.

odd, ok thanks it must be something else then.

oconnelc commented 3 years ago

Overview

I think I'm having the same problem. I'm not using any of the react-native-js. I'm trying to follow a tutorial that uses peerjs to share streams to create a simple video chat.

Tutorial Source

The source is located at: https://github.com/WebDevSimplified/Zoom-Clone-With-WebRTC with the most important code being located in: https://github.com/WebDevSimplified/Zoom-Clone-With-WebRTC/blob/master/public/script.js

Expected Behavior

When following the tutorial, we launch a PeerJS server on port 3001. When the code is started (using the startDev script), the server is hosted on port 3000. Going to localhost:3000 will generate a new "roomId", which is just a UUID and will reroute the user to: http://localhost:3000/

When a second user attempts to go direct to the room (http://localhost:3000/) a video stream will be created and sent with PeerJS to the first user who will then take the stream, create a new video element and return the first user's stream to the second.

What's Actually Happening

None of the PeerJS calls are being invoked and neither of the streams are being sent to each other. The critical piece of code seems to be the following function:

function connectToNewUser(userId, stream) {
  timestampConsole("Calling user: "+ userId+" with myStream")
  const call = myPeer.call(userId, stream)
  const video = document.createElement('video')
  call.on('stream', userVideoStream => {
    timestampConsole("Call received on stream!");
    addVideoStream(video, userVideoStream)
  })
  call.on('close', () => {
    timestampConsole("Called  recieved close")
    video.remove()
  })

  peers[userId] = call
}

Interesting Behavior

Breakpoint

If I put a break point on line: const video = document.createElement('video') and wait a second or two, then all of the events fire correctly and the streams are shared across the steam.

Sleep

I tried to put a sleep to simulate the breakpoint but that exhibited the broken behavior.

Overall Thoughts

afrokick commented 2 years ago

Seems like not PeerJS issue.