peers / peerjs

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

Detect if peer.call(id, stream) didn't get through to anyone #197

Closed RangerMauve closed 10 years ago

RangerMauve commented 10 years ago

In my application, I noticed that if I tried to connect to a peer id that nobody was listening on anymore, the caller wouldn't get any sort of error or notification about it. This can leave my app in a strange state where it calls and just waits for the call to go through forever.

michelle commented 10 years ago

Hey--you should get an error if the peer doesn't exist. Are you listening for errors on your peer object?

Michelle

On Wed, May 28, 2014 at 8:11 AM, RangerMauve notifications@github.comwrote:

In my application, I noticed that if I tried to connect to a peer id that nobody was listening on anymore, the caller wouldn't get any sort of error or notification about it. This can leave my app in a strange state where it calls and just waits for the call to go through forever.

— Reply to this email directly or view it on GitHubhttps://github.com/peers/peerjs/issues/197 .

RangerMauve commented 10 years ago

Thanks for the quick reply.

Yes. In my code I have

call.on("error", function (err) {
    console.error(err);
});

My flow looks like this

  1. user gets redirected to a page with the peerjs id of the person they want to call
  2. user calls peer.call(id, localstream)
  3. call is established
  4. user refreshes page, disconnecting the person they wanted to call
  5. page tries to invoke peer.call(id, localstream) again. Console spews stuff about how it's totally connecting to the peer with that id
  6. user is stuck waiting for the call to connect until they decide to navigate away

I attach the listeners for all the possible events directly after making the call.

var call = peer.call(room, localStream);
init_call(call);

init_call listens to "stream", "close", and "error" in that order.

michelle commented 10 years ago

Are you running your own servers? Sometimes websockets don't close properly on refresh, so the server isn't aware that you've disconnected yet. You could try adding an onbeforeunload handler to your page that will close the peer when refreshing.

Michelle

On Wed, May 28, 2014 at 10:35 AM, RangerMauve notifications@github.comwrote:

Yes. In my code I have

call.on("error", function (err) { console.error(err);});

My flow looks like this

  1. user gets redirected to a page with the peerjs id of the person they want to call
  2. user calls peer.call(id, localstream)
  3. call is established
  4. user refreshes page, disconnecting the person they wanted to call
  5. page tries to invoke peer.call(id, localstream) again. Console spews stuff about how it's totally connecting to the peer with that id
  6. user is stuck waiting for the call to connect until they decide to navigate away

I attach the listeners for all the possible events directly after making the call.

var call = peer.call(room, localStream);init_call(call);

init_call listens to "stream", "close", and "error" in that order.

— Reply to this email directly or view it on GitHubhttps://github.com/peers/peerjs/issues/197#issuecomment-44439680 .

RangerMauve commented 10 years ago

Yes, I'm currently running it on Heroku (websockets enabled). I'll test that out and report back later. Thank you for the help!

michelle commented 10 years ago

Feel free to reopen this if you're still running into issues!

RangerMauve commented 10 years ago

Whoops, sorry, I totally forgot about this. Basically, after being unable to reproduce my errors, I've tried destroying and creating a new PeerJS connection every time I want to do a call.