英文:
WebRTC delay on iceConnectionState - 'disconnected'
问题
两个对等方已连接 - 主机和客户端
客户端下线后,大约3-7秒后触发主机的iceConnectionState为'disconnected'
为什么会有延迟?如何去除这个延迟?
我只是想实时获取用户的在线状态。
英文:
Two peers are connected - host and client
Client gets offline and iceConnectionState - 'disconnected' on host is triggered after about 3-7 seconds
Why is there a delay ? and how to remove that delay?
I just wanted get online status of user in realtime
答案1
得分: 2
Peer connection gets closed when there's no data coming for several seconds, hence the delay. There's no Web API to configure this timeout.
I see three ways how you might reduce the delay:
-
Send keepalives between peers via datachannel. If there were no keepalive for n milliseconds, client can be considered disconnected. Then the server might close the connection or display "pending" user status.
Some timeout is still needed, but it can be shorter than the default. -
If client always sends the video, you might use getStats() to detect when there's no new packets coming. It's the same as 1, but using video packets instead of keepalive messages. See this answer.
-
Send a message to server when the client is about to disconnect. For example, you could send a "goodbye" message to WebRTC datachannel in
window.onbeforeunload
callback. The drawback is that if the client goes offline without closing the page, you still have to wait for whatever is the default timeout in your browser.
英文:
Peer connection gets closed when there's no data coming for several seconds, hence the delay. There's no Web API to configure this timeout.
I see three ways how you might reduce the delay:
-
Send keepalives between peers via datachannel. If there were no keepalive for n milliseconds, client can be considered disconnected. Then the server might close the connection or display "pending" user status.
Some timeout is still needed, but it can be shorter than the default. -
If client always sends the video, you might use getStats() to detect when there's no new packets coming. It's the same as 1, but using video packets instead of keepalive messages. See this answer.
-
Send a message to server when client is about to disconnect. For example, you could send a "goodbye" message to WebRTC datachannel in
window.onbeforeunload
callback. The drawback is that if the client goes offline without closing the page you still have to wait for whatever is the default timeout in your browser.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论