w3c/webrtc-pc

PC.local_description and friends - snapshot views or dynamic views?

Opened this issue · 4 comments

In the current specification, current_local_description is described as an attribute that returns the content of the [[CurrentLocalDescription]] slot.
Returning an object in Javascript is basically passing a reference, not cloning the value.

So - in the current model, if we have:

x = pc.current_local_description
... time passes
a new candidate is added
... time passes
what is the value of x.sdp? does it include the new candidate or not?

This came up while hunting for a thread access issue inside WebRTC; it made it clear to me that life would be much simpler if those accessors returned a copy of the current state of [[LocalDescription]], and did not change after returning. But that is not the way attributes usually work.

What should we intend here?
(all the attributes of an RTCSessionDescription are readonly, so the Javascript side can't change it. The question is whether the platform can change it.)

It seems worth writing some tests and checking results for all browsers.

I think the spec mentions when new objects should be created and when the objects should be updated.
Surfacing new ICE candidates should probably not create new objects from what I can see in the spec.
Looking quickly at Safari, it seems new objects are created when surfacing new ICE candidates :(

A quick test https://jsfiddle.net/jib1/gawh7eno/20/ shows the following in all browsers:

  1. pc.localDescription === pc.localDescription
    • caveat: use Firefox Nightly or media.peerconnection.description.legacy.enabled=false in about:config
  2. pc.localDescription replaced by a new RTCSessionDescription upon onicecandidate with a candidate

This seems reasonable to me. pc.localDescription changes but x.sdp does not (which would seem like action at a distance).

In contrast the spec says: "add candidate to connection.[[PendingLocalDescription]].sdp."

I vote we change the spec to match implementations.

So this would replace all the places with "add candidate to connection.[[PendingLocalDescription]].sdp" and similar with
"replace connection.[[PendingLocalDescription]] with a new object where 'candidate' has been added to the sdp"?

This works for me; x = pc.localDescription; x === pc.localDescription; await addCandidate(); x !== pc.LocalDescription

This issue had an associated resolution in WebRTC June 18 2024 meeting – 18 June 2024 (WebRTC: PC.local_description and friends - snapshot views or dynamic views?):

RESOLUTION: no objection to proposal to align spec with implementations