admin管理员组文章数量:1332890
I'm attempting to detect when the other side of a RTCPeerConnection has disconnected. Currently I'm doing the following with my RTCPeerConnection object:
rtcPeerConnection.oniceconnectionstatechange = () => {
const state = rtcPeerConnection.iceConnectionState;
if (state === "failed" || state === "closed") {
// connection to the peer is lost and unsalvageable, run cleanup code
} else if (state === "disconnected") {
// do nothing in the "disconnected" state as it appears to be a transient
// state that can easily return to "connected" - I've seen this with Firefox
}
};
This seems to work in my limited testing with very simply network conditions but the following from MDN gives me pause that it's probably not going to hold up in production:
Of course, "disconnected" and "closed" don't necessarily indicate errors; these can be the result of normal ICE negotiation, so be sure to handle these properly (if at all).
Should I instead be using RTCPeerConnection.onconnectionstatechange
and considering the connection permanently closed if RTCPeerConnection.connectionState
is "closed"
, "failed"
or "disconnected"
?
I'm attempting to detect when the other side of a RTCPeerConnection has disconnected. Currently I'm doing the following with my RTCPeerConnection object:
rtcPeerConnection.oniceconnectionstatechange = () => {
const state = rtcPeerConnection.iceConnectionState;
if (state === "failed" || state === "closed") {
// connection to the peer is lost and unsalvageable, run cleanup code
} else if (state === "disconnected") {
// do nothing in the "disconnected" state as it appears to be a transient
// state that can easily return to "connected" - I've seen this with Firefox
}
};
This seems to work in my limited testing with very simply network conditions but the following from MDN gives me pause that it's probably not going to hold up in production:
Of course, "disconnected" and "closed" don't necessarily indicate errors; these can be the result of normal ICE negotiation, so be sure to handle these properly (if at all).
Should I instead be using RTCPeerConnection.onconnectionstatechange
and considering the connection permanently closed if RTCPeerConnection.connectionState
is "closed"
, "failed"
or "disconnected"
?
1 Answer
Reset to default 10The specification has very carefully crafted advice on that topic:
Performing an ICE restart is remended when
iceConnectionState
transitions to"failed"
. An application may additionally choose to listen for theiceConnectionState
transition to"disconnected"
and then use other sources of information (such as usinggetStats
to measure if the number of bytes sent or received over the next couple of seconds increases) to determine whether an ICE restart is advisable.
See the spec and the PR that added this
Mind you that due to bugs Chrome no longer goes to "failed" in unified plan. "closed" can only happen if your code calls pc.close() so is no longer fired in iceconnectionstatechange as of Chrome 80.
本文标签: javascriptWhen can I consider a RTCPeerConnection to be disconnectedStack Overflow
版权声明:本文标题:javascript - When can I consider a RTCPeerConnection to be disconnected? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742317690a2452146.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论