javascript - Ending WebRTC video call between two peers - Stack Overflow

I've set up a video chat between two peers using WebRTC. I would like to allow a peer to end the c

I've set up a video chat between two peers using WebRTC. I would like to allow a peer to end the chat and for the other peer to know that the chat was ended. Once the chat ends, some code needs to be executed for both peers. The PeerConnection object has a removeStream() method which should trigger the onremovestream() listener. This would be perfect for my use case, however, before onremovestream() is called there needs to be a re-negotiation (offer/answer) between the peers. For my case this seems odd. Why would I re-negotiate only to disconnect? Shouldn't the PeerConnection object realize no stream is ing from the other user? My question: how can I end a PeerConnection and alert the other user?

I've set up a video chat between two peers using WebRTC. I would like to allow a peer to end the chat and for the other peer to know that the chat was ended. Once the chat ends, some code needs to be executed for both peers. The PeerConnection object has a removeStream() method which should trigger the onremovestream() listener. This would be perfect for my use case, however, before onremovestream() is called there needs to be a re-negotiation (offer/answer) between the peers. For my case this seems odd. Why would I re-negotiate only to disconnect? Shouldn't the PeerConnection object realize no stream is ing from the other user? My question: how can I end a PeerConnection and alert the other user?

Share Improve this question edited Oct 9, 2014 at 21:16 chRyNaN asked Oct 9, 2014 at 21:01 chRyNaNchRyNaN 3,6925 gold badges49 silver badges74 bronze badges 3
  • 1 The reason it is being renegotiated is for the case when you have more than one stream. You can just close the connection if you only have one media stream in the connection. – Benjamin Trent Commented Oct 9, 2014 at 21:57
  • @BenjaminTrent how would one peer know when the other closed the stream in my case? Is there a listener? – chRyNaN Commented Oct 9, 2014 at 22:09
  • How are the peers municating? That is, are they capable of sending messages to each other? Or can they only municate with the sever? – AeroBuffalo Commented Oct 10, 2014 at 14:44
Add a ment  | 

2 Answers 2

Reset to default 2

You can simply close the connection. The other peer can listen for the signal oniceconnectionstatechange and the state of disconnected means that your peer has closed the connection/is no longer available. If I were you, I would do a timeout before closing as this state could be because of a flaky network connection. MDN has some good info

Or, you could keep track of connections with your signalling server and signal the peers when somebody leaves. Either way should work.

Open a datachannel and use it to say "I'm done"; when one side gets "I'm done" it says "ok, you're done". To be totally safe and have both sides know the call is ending before it really disconnects, use a 3-way handshake over datachannels to end the call (and you can change the media to black/silence immediately by setting track.enabled = false for the audio and video tracks)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745647205a4638042.html

相关推荐

  • javascript - Ending WebRTC video call between two peers - Stack Overflow

    I've set up a video chat between two peers using WebRTC. I would like to allow a peer to end the c

    22天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信