具有完美协商的 WebRTC - 在移动 Safari 上回滚不起作用 [英] WebRTC with perfect negotiation - Rollback on mobile Safari does not work

查看:116
本文介绍了具有完美协商的 WebRTC - 在移动 Safari 上回滚不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过考虑以下页面中的示例,我正在尝试为我的小型视频会议应用程序实现完美的 WebRTC 协商:

I am trying to implement perfect WebRTC negotiation for my small video conferencing application by considering the examples from the following page:

https://blog.mozilla.org/webrtc/perfect-网络谈判/

不幸的是我没有设法让它完全工作,尤其是移动 safari 似乎以自己的方式处理回滚行为,这里是处理回滚行为的代码:

Unortunately I did not manage to make it fully work, especially mobile safari seems to handle rollback behavior its own way, here is the code that handles the rollback behavior:

      if (description) {
        const offerCollision = description.type == 'offer' && (makingOffer || pc.signalingState != 'stable');
        this.ignoreOffer = !this.polite && offerCollision;
        if (this.ignoreOffer) {
          return;
        }
        if (offerCollision) {
          await Promise.all([pc.setRemoteDescription({ type: 'rollback' }), pc.setRemoteDescription(description)]);

因此,当在移动 Safari 上检测到要约冲突 (offerCollision === true) 并且 pc.setRemoteDescription({ type: 'rollback' }) 被称为它在我的代码中实现,它抛出 InvalidStateError 类型的错误.仔细查看有关 MDN 中此类错误的文档(https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/setRemoteDescription#Browser_compatibility) 显示:

So when on mobile safari an offer collision (offerCollision === true) is detected and pc.setRemoteDescription({ type: 'rollback' }) is called as it's implemented in my code, it throws an error of type InvalidStateError. Taking a closer look at the documentation about this type of error in MDN (https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/setRemoteDescription#Browser_compatibility) shows:

"RTCPeerConnection 已关闭,或处于与指定描述类型不兼容的状态.例如,如果类型为回滚且信令状态为 stable、have-local-pranswer 或 have-remote-pranswer,抛出此异常,因为您无法回滚已完全建立或处于连接的最后阶段的连接."

"The RTCPeerConnection is closed, or it's in a state which isn't compatible with the specified description's type. For example, if the type is rollback and the signaling state is one of stable, have-local-pranswer, or have-remote-pranswer, this exception is thrown, because you can't roll back a connection that's either fully established or is in the final stage of becoming connected."

在回滚之前检查对等连接信号状态表明它处于have-local-offer"状态,这应该没问题,因为 MDN 说回滚是不可能的(抛出 InvalidStateError)在 stable、have-local-pranswer 或 have-remote-pranswer 状态.

Checking the peer connections signaling state just before rolling back shows that it is in the state "have-local-offer" which should be ok since MDN says that rollback is not possible (throws InvalidStateError) in the states stable, have-local-pranswer, or have-remote-pranswer.

对于另一种情况,当我的桌面 Chrome 浏览器在报价冲突中运行时,一切都按预期工作,并且在启动回滚之前具有相同的信号状态.

For the other case when my Desktop Chrome browser runs in an offer collision everything just works as expected with the same signaling state just before rollback is initiated.

这里有人知道移动 Safari 可能出现的错误或不同的处理方式吗.

Does someone here have an idea what's potentially wrong or to be handled differrently for mobile Safari.

推荐答案

评论,Safari(iOS/移动和 macOS)有一个 已知错误{ type: 'rollback' }.它还不支持 setLocalDescription/setRemoteDescription 中的可选描述,这是规范中最新的完美协商建议.

As mentioned in the comments, Safari (both iOS/mobile and macOS) has a known bug with { type: 'rollback' }. It also does not yet support optional descriptions in setLocalDescription/setRemoteDescription, the latest perfect negotiation recommendation in the spec.

这可以通过丢弃冲突的对等连接并重试来解决(按照建议).为此,请按照以下步骤处理设置远程描述时的错误:

This can be fixed by discarding the colliding peer connections and retrying (as suggested). To do this, handle the error when setting a remote description with the following steps:

  1. 重置任何状态变量(例如makingOfferisSettingRemoteAnswerPending)
  2. 通过调用peerConnection.close()
  3. 关闭对等连接
  4. 拆除任何对等连接事件侦听器(例如negotiationneededicecandidatetrack)
  5. 向其他对等方发出信号以执行相同操作,例如通过 websocket 消息传递
  6. 收到重启信号后,对方可以通过同样的步骤,最后创建一个新的报价,重新开始谈判过程.

可以在 这个演示.

这篇关于具有完美协商的 WebRTC - 在移动 Safari 上回滚不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆