【发布时间】:2020-02-14 16:06:27
【问题描述】:
我正在尝试检测 RTCPeerConnection 的另一端何时断开连接。目前我正在使用我的 RTCPeerConnection 对象执行以下操作:
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
}
};
这似乎适用于我在非常简单的网络条件下进行的有限测试,但来自MDN 的以下内容让我停下来,它可能不会在生产中支持:
当然,“断开”和“关闭”不一定表示错误;这些可能是正常 ICE 协商的结果,因此请务必妥善处理(如果有的话)。
如果RTCPeerConnection.connectionState 是"closed"、"failed" 或"disconnected",我是否应该改用RTCPeerConnection.onconnectionstatechange 并考虑永久关闭连接?
【问题讨论】:
标签: javascript webrtc rtcpeerconnection