Bug 174656 - RTCPeerConnection rollback rejects with InvalidStateError
Summary: RTCPeerConnection rollback rejects with InvalidStateError
Status: RESOLVED DUPLICATE of bug 229991
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-07-19 11:00 PDT by Mark Roberts
Modified: 2022-01-28 00:49 PST (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Roberts 2017-07-19 11:00:17 PDT
RTCPeerConnection should allow rollback in signaling states "have-local-offer" and "have-remote-offer".

Example Code:

    // "have-local-offer"
    (async () => {
      console.log('1. Getting user media')
      const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
      const [track] = stream.getAudioTracks()
      console.log('2. Constructing RTCPeerConnection')
      const pc = new RTCPeerConnection()
      console.log('3. Adding MediaStreamTrack')
      pc.addTrack(track, stream)
      console.log('4. Creating offer')
      const offer = await pc.createOffer()
      console.log('5. Applying local description')
      await pc.setLocalDescription(offer)
      console.log('6. Rolling back local description')
      await pc.setLocalDescription({ type: 'rollback' })
      console.log('Success!')
    })()

    // "have-remote-offer"
    (async () => {
      console.log('1. Getting user media')
      const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
      const [track] = stream.getAudioTracks()
      console.log('2. Constructing RTCPeerConnection')
      const pc = new RTCPeerConnection()
      console.log('3. Adding MediaStreamTrack')
      pc.addTrack(track, stream)
      console.log('4. Creating offer')
      const offer = await pc.createOffer()
      console.log('5. Applying remote description')
      await pc.setRemoteDescription(offer)
      console.log('6. Rolling back remote description')
      await pc.setRemoteDescription({ type: 'rollback' })
      console.log('Success!')
    })()

Expected Output (e.g., Firefox):

    // "have-local-offer"
    1. Getting user media
    2. Constructing RTCPeerConnection
    3. Adding MediaStreamTrack
    4. Creating offer
    5. Applying local description
    6. Rolling back local description
    7. Success!

    // "have-remote-offer"
    1. Getting user media
    2. Constructing RTCPeerConnection
    3. Adding MediaStreamTrack
    4. Creating offer
    5. Applying remote description
    6. Rolling back remote description
    7. Success!

Actual Output (Safari 11 Technology Preview):

    // "have-local-offer"
    1. Getting user media
    2. Constructing RTCPeerConnection
    3. Adding MediaStreamTrack
    4. Creating offer
    5. Applying local description
    6. Rolling back local description
    Unhandled Promise Rejection: InvalidStateError (DOM Exception 11): Description type incompatible with current signaling state

    // "have-remote-offer"
    1. Getting user media
    2. Constructing RTCPeerConnection
    3. Adding MediaStreamTrack
    4. Creating offer
    5. Applying remote description
    6. Rolling back remote description
    Unhandled Promise Rejection: InvalidStateError (DOM Exception 11): Description type incompatible with current signaling state
Comment 1 Radar WebKit Bug Importer 2017-07-19 11:38:19 PDT
<rdar://problem/33407438>
Comment 2 goekhancimsir 2020-06-15 03:55:32 PDT
Same for me in mobile Safari (iOS 13.4.1). Here is a demo in jsfiddle:

https://jsfiddle.net/8eap2t9r/1/

I wonder that this issue has been reported 3 years ago and since then it got stuck in status "NEW". Is this use case (explicit rollback) considered to be obsolete?
Comment 3 youenn fablet 2020-06-15 05:41:46 PDT
Rollback was not defined very precisely, not well tested...
Some effort has been made recently to progress in that area. We might be able to implement it after our next webrtc backend resync.
Comment 4 goekhancimsir 2020-06-16 03:03:05 PDT
OK, thank you for the info. Looking really forward to see this bug fixed. Rolling back without the RTCPeerConnection "rollback" feature working is really a mess, e.g. in the context of "perfect negotiation".
Comment 5 brandon.t.diamond 2021-04-05 18:39:48 PDT
Is there an update on this bug?

This prevents the use of “perfect negotiation” for signaling, the best practice for avoiding glare when connecting peers (as described on MDN and in the spec).

If there is no fix planned, a suggested workaround would be much appreciated.
Comment 6 Dominik Menke 2021-05-06 03:56:23 PDT
(sorry for hijacking this)

There's an example Rails application which deploys some workarounds for Safari:

    https://github.com/domchristie/webrtc-hotwire-rails

The commit introducing support for Safari seems to be this one:

    https://github.com/domchristie/webrtc-hotwire-rails/commit/2b845c1

However, with the recent iOS 14.5 update, Mobile Safari 14.1 now (sometimes) fails to negotiate a connection. The error I'm seeing in the Devtools when calling pc.setRemoteDescription(offer) is:

    InvalidStateError: Description type incompatible with current signaling state

(pc.signalingState is "have-local-offer").

I've opened an issue within the webrtc-hotwire-rails to gather more information, including a repro steps:

    https://github.com/domchristie/webrtc-hotwire-rails/issues/1

I suspect changeset 266511 (for Technology Preview 114) might be responsible for surfacing this issue:

    https://trac.webkit.org/changeset/266511/webkit/

Currently, only iOS Safari seems to be affected, I could not reproduce it with the macOS version.
Comment 7 Dominik Menke 2021-05-06 05:45:17 PDT
So... I can now reproduce the issue reliably with Desktop Safari as well.

(Of course, I did not change anything on my system... :/)

Is there a way to install older Technology Previews to triage the problem better?
Comment 8 jib 2022-01-27 13:15:53 PST
Workaround:
- With bug 229991 setRemoteDescription() now supports implicit rollback.

This may suffice in some situations like when trying to implement perfect negotiation. But appears to be in Tech Preview still.
Comment 9 jib 2022-01-27 16:19:05 PST
Actually both examples in comment 0 as well as https://jsfiddle.net/jib1/bw07k52e/ work for me in 15.4 Tech Preview.

Can this be closed as a dup of bug 229991?
Comment 10 youenn fablet 2022-01-28 00:49:56 PST
Closing, please reopen if some of below examples do not work.

*** This bug has been marked as a duplicate of bug 229991 ***