Skip to content

Commit

Permalink
fix(@libp2p/webrtc): close data-channel on muxer stream end (#1976)
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
Marcel-G authored Sep 5, 2023
1 parent 2b755a8 commit 7517082
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions packages/transport-webrtc/src/muxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export class DataChannelMuxer implements StreamMuxer {
direction: 'outbound',
dataChannelOptions: this.dataChannelOptions,
onEnd: () => {
channel.close() // Stream initiator is responsible for closing the channel
this.streams = this.streams.filter(s => s.id !== stream.id)
this.metrics?.increment({ stream_end: true })
this.init?.onStreamEnd?.(stream)
Expand Down

0 comments on commit 7517082

Please sign in to comment.