Fix datachannel handling: auto-create channels from remote peer

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 <noreply@anthropic.com>
This commit is contained in:
2025-12-06 13:59:16 +01:00
parent 9486376442
commit a6dc342f3b

View File

@@ -324,11 +324,20 @@ export class DurableConnection extends EventEmitter<DurableConnectionEvents> {
};
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);