From e0b90575db9968f0f103ff54704904c4360e3846 Mon Sep 17 00:00:00 2001 From: Marcel Gleeson Date: Tue, 18 Jul 2023 11:39:46 +0200 Subject: [PATCH 1/2] fix: close datachannel on stream finish --- packages/transport-webrtc/src/muxer.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/transport-webrtc/src/muxer.ts b/packages/transport-webrtc/src/muxer.ts index 7e5b655a3c..2a5b7465c8 100644 --- a/packages/transport-webrtc/src/muxer.ts +++ b/packages/transport-webrtc/src/muxer.ts @@ -131,6 +131,7 @@ export class DataChannelMuxer implements StreamMuxer { direction: 'inbound', dataChannelOptions: this.dataChannelOptions, onEnd: () => { + channel.close() this.streams = this.streams.filter(s => s.id !== stream.id) this.metrics?.increment({ stream_end: true }) init?.onStreamEnd?.(stream) @@ -158,6 +159,7 @@ export class DataChannelMuxer implements StreamMuxer { direction: 'outbound', dataChannelOptions: this.dataChannelOptions, onEnd: () => { + channel.close() this.streams = this.streams.filter(s => s.id !== stream.id) this.metrics?.increment({ stream_end: true }) this.init?.onStreamEnd?.(stream) From 8cc07e5f8e7a02d5f840066336eb2c4da3b63ce0 Mon Sep 17 00:00:00 2001 From: Marcel Gleeson Date: Thu, 17 Aug 2023 10:27:22 +0200 Subject: [PATCH 2/2] fix: initiator should close the channel --- packages/transport-webrtc/src/muxer.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/transport-webrtc/src/muxer.ts b/packages/transport-webrtc/src/muxer.ts index 2a5b7465c8..991d130230 100644 --- a/packages/transport-webrtc/src/muxer.ts +++ b/packages/transport-webrtc/src/muxer.ts @@ -131,7 +131,6 @@ export class DataChannelMuxer implements StreamMuxer { direction: 'inbound', dataChannelOptions: this.dataChannelOptions, onEnd: () => { - channel.close() this.streams = this.streams.filter(s => s.id !== stream.id) this.metrics?.increment({ stream_end: true }) init?.onStreamEnd?.(stream) @@ -159,7 +158,7 @@ export class DataChannelMuxer implements StreamMuxer { direction: 'outbound', dataChannelOptions: this.dataChannelOptions, onEnd: () => { - channel.close() + 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)