WebRTC iceConnectionState 上的延迟 – ‘disconnected’

huangapple go评论74阅读模式
英文:

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:

  1. 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.

  2. 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.

  3. 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:

  1. 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.

  2. 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.

  3. 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.

huangapple
  • 本文由 发表于 2023年2月13日 23:56:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438274.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定