Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTCSessionDescription parameters should be readonly. #573

Closed
jan-ivar opened this issue Apr 11, 2016 · 22 comments
Closed

RTCSessionDescription parameters should be readonly. #573

jan-ivar opened this issue Apr 11, 2016 · 22 comments

Comments

@jan-ivar
Copy link
Member

The current language implies that content can modify the local description like this:

pc.localDescription.type = "answer";

which would be a travesty (an interface as an attribute is by reference).

In light of #302 I propose we solve this by changing RTCSessionDescription's parameters to readonly, and change createOffer and createAnswer to resolve with RTCSessionDescriptionInit instead.

@alvestrand
Copy link
Contributor

"which would be a travesty (an interface as an attribute is by reference)."
I can't parse either the grammar of the sentence, what your opinion is, or why you have it.

The localDescription and remoteDescription parameters of the PC are already readonly, which makes the code you suggest illegal (unless I've misunderstood the properties of a readonly attribute).

4.7.2 says "Attributes on this interface are mutable for legacy reasons." I see no compelling reason to change it.

@adam-be
Copy link
Member

adam-be commented Apr 12, 2016

The type attribute was readonly to begin with, but we changed it to allow scripts to, for example, switch from an "answer" to a "pranswer" before setting.

@jan-ivar
Copy link
Member Author

I checked with our DOM guys, and readonly just means there's no setter for .localDescription. The returned interface is still mutable, which seems problematic.

If we do what I suggest then there's no reason to leave them for legacy reasons, since createOffer would return RTCSessionDescriptionInit, a dictionary, instead.

@jan-ivar
Copy link
Member Author

Also, dictionaries have copy semantics, whereas interfaces do not. So a conforming implementation of the current webidl MUST work like this:

var pc = new RTCPeerConnection();
pc.createDataChannel("dummy");
pc.createOffer().then(offer => pc.setLocalDescription(offer))
.then(() => {
  console.log(pc.localDescription.type); // offer
  pc.localDescription.type = "answer";
  console.log(pc.localDescription.type); // answer
})
.catch(log);

Luckily, neither Firefox nor Chrome are compliant.

@martinthomson
Copy link
Member

You can't have an attribute with a dictionary type. The right solution is to make RTCSessionDescription immutable itself, as @jan-ivar says originally. That we are all current in flagrant defiance of expectations here isn't that bad, we just make the attributes readonly and move on.

@jan-ivar
Copy link
Member Author

Yes I just meant remove the legacy mutability. The interfaces are needed forever for the attributes.

@foolip
Copy link
Member

foolip commented Nov 8, 2016

https://crbug.com/662898 is a bug originating from @philn with Igalia where they (I presume) they tried to follow the spec but ran into trouble.

@philn, if you think the spec should change, can you file a new issue describing the compat constraints?

@foolip
Copy link
Member

foolip commented Nov 8, 2016

Somewhat relevant is also whatwg/webidl#213, but compat demands what it demands. I've asked on the Chromium issue if appear.in might change in the meantime.

@ShijunS, do you know what the Edge behavior is here?

@philn
Copy link

philn commented Nov 8, 2016

@foolip
Copy link
Member

foolip commented Nov 8, 2016

Somewhat related is that RTCSessionDescriptionInit's type is required in the spec but not in Gecko or Blink. I'll sprinkle some use counters in Blink, not sure whether reverting the spec change or trying to match the spec is better overall.

@bzbarsky
Copy link

bzbarsky commented Nov 8, 2016

I'm 90% sure that both Gecko and Blink implemented RTCSessionDescriptionInit before IDL "required" syntax existed, which is why they're not using it yet...

@foolip
Copy link
Member

foolip commented Nov 8, 2016

Indeed, no surprise there.

Per https://twitter.com/pnormand/status/795938320224309249 appear.in changed their code, so let's hope that most other usage in the wild doesn't depend on the current behavior. (Use counters in https://codereview.chromium.org/2490543002/)

@ShijunS
Copy link

ShijunS commented Nov 8, 2016

Re Edge behavior, we have tried to follow the spec before this change. However, in our implementation, both localDescription and remoteDescription are new interface objects copied from the media stack. They can change when app calls setLocalDescription() and setRemoteDescription(). But, we don't pass down any app-level change to the lower level. There is no major conflict to the change of "type" and "sdp" to readonly.

At this point, setLocalDescription() and setRemoteDescription() still require RTCSessionDescription interface object as input, and will throw exception on RTCSessionDescriptionInit. Similarly, createOffer() and createAnswer() will return RTCSessionDescription interface object rather than RTCSessionDescriptionInit dictionary. I expect this option will stay until all major browser implementations and websites have migrated according to the latest spec.

@jan-ivar
Copy link
Member Author

jan-ivar commented Nov 8, 2016

https://crbug.com/662898

Looks like we missed a common use-case when we made this read-only:

new RTCSessionDescription().sdp = "v=0\no=- 627673561523047307...";

I suppose we could solve it by using a different interface for the attribute... RTCSessionDescriptionAttr ?

@jan-ivar
Copy link
Member Author

jan-ivar commented Nov 9, 2016

@foolip Or maybe make RTCSessionDescription writable again and Object.freeze() the specific attributes instead? Is there some webidl for that?

@bzbarsky
Copy link

bzbarsky commented Nov 9, 2016

Freeze which attributes? What are their types?

@jan-ivar
Copy link
Member Author

jan-ivar commented Nov 9, 2016

[Frozen]

@jan-ivar
Copy link
Member Author

jan-ivar commented Nov 9, 2016

@bzbarsky pc.localDescription and friends.

@bzbarsky
Copy link

bzbarsky commented Nov 9, 2016

I don't see how freezing them would do any good. What would be the goal?

@jan-ivar
Copy link
Member Author

jan-ivar commented Nov 9, 2016

@bzbarsky To prevent pc.localDescription.type = "answer"; as mentioned at the top of this issue.

@bzbarsky
Copy link

bzbarsky commented Nov 9, 2016

Freezing it won't prevent that, because the setter isn't mutating any state the freezing freezes.

@jan-ivar
Copy link
Member Author

jan-ivar commented Nov 9, 2016

Ok @bzbarsky showed me freezing only works on value properties, not setters, so that won't work.

So I revert to the RTCReadonlySessionDescription idea, or since the RTCSessionDescription constructor is legacy, we could just ignore the webcompat on this one and hope it is small.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants