Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/polyfill/RTCPeerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ export default class RTCPeerConnection extends EventTarget implements globalThis
}

close(): void {
for (const dc of this.#dataChannels) {
if (dc.readyState !== 'closed') {
dc.close();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close

  1. Set the [[ReadyState]] slot of each of connection's RTCDataChannels to "closed".

NOTE

The RTCDataChannels will be closed abruptly and the closing procedure will not be invoked.

Do we actually need a separate method like forceCloseAbruptly for this case?

In the current PR DataChannel.close() implementation, the .readyState is set to "closing" immediately to prevent readyState race conditions, and only transitions to "closed" once the native layer confirms that the data channel has closed. However, according to the W3C WebRTC Data Channel specification, when a data channel is closed abruptly, the closing procedure is not invoked and .readyState must transition directly to "closed".

We should ensure that our implementation matches the expected behavior defined by the spec.

Copy link
Contributor Author

@mertushka mertushka Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@murat-dogan I need your insights here.

Also, could you clarify why this implementation was removed in the first place?
b3000f1#diff-701dfe9764f8864403783f0e275aeac5f8f104601ac6b189f7deda2f9eaaa1f1L339-L340

}
}
this.#dataChannels.clear();

this.#peerConnection.close();
}

Expand Down