Skip to content

Fix interop/API type mismatches: RtcDataChannel width, SetLocalDescription spec alignment#38

Merged
General-Fault merged 4 commits into
mainfrom
cases/37-interop-api-type-mismatches
Jun 2, 2026
Merged

Fix interop/API type mismatches: RtcDataChannel width, SetLocalDescription spec alignment#38
General-Fault merged 4 commits into
mainfrom
cases/37-interop-api-type-mismatches

Conversation

@General-Fault
Copy link
Copy Markdown
Owner

Fixes #37

Changes

RtcDataChannel (uint32_t -> uint16_t)

MaxPacketLifeTime and MaxRetransmits were declared as Nullable<uint32_t> in the C++/CLI layer. The W3C spec defines both as unsigned short, matching the C# abstract ushort? (Nullable<uint16_t>). The mismatch prevented the interop overrides from satisfying their abstract VTable slots.

SetLocalDescription spec alignment + VTable fix

The C++/CLI override used RtcSessionDescription (non-nullable value type), which is a different CLR signature from the abstract Nullable. Beyond the VTable bug, the W3C spec uses two distinct dictionary types:

  • setLocalDescription takes RTCLocalSessionDescriptionInit where type is optional
  • setRemoteDescription takes RTCSessionDescriptionInit where type is required

The optional type is meaningful: it selects between two native overloads on PeerConnectionInterface -- one that takes an explicit SessionDescriptionInterface, and one that lets the native stack create the description itself.

This PR introduces RtcLocalSessionDescriptionInit with RtcSdpType? Type, an implicit conversion from RtcSessionDescription (so CreateOffer/CreateAnswer results pass through without a cast), and updates the abstract signature, C++/CLI override, and contract test accordingly.

…ption spec alignment

RtcDataChannel MaxPacketLifeTime/MaxRetransmits: uint32_t -> uint16_t to match
W3C spec (unsigned short) and the C# abstract ushort? declaration.

SetLocalDescription: the C++/CLI override used non-nullable RtcSessionDescription
which occupies a different CLR VTable slot from the abstract Nullable<RtcSessionDescription>.
More fundamentally the W3C spec uses a distinct RTCLocalSessionDescriptionInit dict
where 'type' is optional (not required as in RTCSessionDescriptionInit used by
setRemoteDescription). A null type maps to the no-arg native SetLocalDescription()
overload which lets the native stack create the description.

- Add RtcLocalSessionDescriptionInit struct with RtcSdpType? Type
- Add implicit conversion from RtcSessionDescription for CreateOffer/CreateAnswer ergonomics
- Update SetLocalDescription abstract to accept RtcLocalSessionDescriptionInit?
- Update C++/CLI to Nullable<RtcLocalSessionDescriptionInit>
- Update contract test to lock in spec-correct type
- Add TODO in MarshalPeerConnection.h for implementation pass

Fixes #37

BugzId:37
…structs

- Both types use record struct with { get; init; } properties
- Add seealso spec links on Type and Sdp properties of both types
- Add implicit conversion RtcLocalSessionDescriptionInit -> RtcSessionDescription
  (throws InvalidOperationException if Type is null)

BugzId:37
@General-Fault General-Fault merged commit 52093b1 into main Jun 2, 2026
1 check failed
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

Successfully merging this pull request may close these issues.

Fix interop/API type mismatches: RtcDataChannel width, SetLocalDescription spec alignment

1 participant