From a6dc342f3ba8824bd839c1577274790de01124b1 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 6 Dec 2025 13:59:16 +0100 Subject: [PATCH] Fix datachannel handling: auto-create channels from remote peer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified peerDataChannelHandler to automatically create DurableChannel instances when receiving data channels from the remote peer. This fixes the connection flow where the answerer needs to receive the data channel that the offerer created. Previously, the handler only attached if a DurableChannel already existed, which meant incoming channels from the remote peer would be ignored. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/durable/connection.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/durable/connection.ts b/src/durable/connection.ts index 37ed220..8b20534 100644 --- a/src/durable/connection.ts +++ b/src/durable/connection.ts @@ -324,11 +324,20 @@ export class DurableConnection extends EventEmitter { }; this.peerDataChannelHandler = (channel: RTCDataChannel) => { - // Find matching durable channel and attach - const durableChannel = this.channels.get(channel.label); - if (durableChannel) { - durableChannel.attachToChannel(channel); + // Find or create durable channel + let durableChannel = this.channels.get(channel.label); + + if (!durableChannel) { + // Auto-create channel for incoming data channels + durableChannel = new DurableChannel(channel.label, { + maxQueueSize: this.config.maxQueueSize, + maxMessageAge: this.config.maxMessageAge + }); + this.channels.set(channel.label, durableChannel); } + + // Attach the received channel + durableChannel.attachToChannel(channel); }; peer.on('connected', this.peerConnectedHandler);