Skip to content

Commit 7517082

Browse files
authored
fix(@libp2p/webrtc): close data-channel on muxer stream end (#1976)
`RTCDataChannel`s are not properly closed after the stream ends. They stay in an open state and eventually the browser will not be able to create more `RTCDataChannel`s with the following error: ``` Uncaught (in promise) DOMException: Failed to execute 'createDataChannel' on 'RTCPeerConnection': RTCDataChannel creation failed ``` Fixes #1895
1 parent 2b755a8 commit 7517082

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

packages/transport-webrtc/src/muxer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export class DataChannelMuxer implements StreamMuxer {
158158
direction: 'outbound',
159159
dataChannelOptions: this.dataChannelOptions,
160160
onEnd: () => {
161+
channel.close() // Stream initiator is responsible for closing the channel
161162
this.streams = this.streams.filter(s => s.id !== stream.id)
162163
this.metrics?.increment({ stream_end: true })
163164
this.init?.onStreamEnd?.(stream)

0 commit comments

Comments
 (0)