From 122f211e7c94a06cea0ef8551591a01ae55b0c62 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Fri, 5 Dec 2025 20:19:14 +0100 Subject: [PATCH] Fix empty SDP in pooled service offers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The publishInitialService() method was creating an offer with SDP but not returning it. This caused the first offer in the pool to have an empty SDP string, which failed when trying to set it as the local description when an answer arrived. Fixed by: - Storing the offer SDP before closing the peer connection - Adding offerSdp to the return value of publishInitialService() - Using the returned SDP when creating the initial offer in the pool This ensures all offers in the pool have valid SDP that can be used to recreate the peer connection state when answers arrive. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/service-pool.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/service-pool.ts b/src/service-pool.ts index d2e9ed6..837b72b 100644 --- a/src/service-pool.ts +++ b/src/service-pool.ts @@ -143,9 +143,9 @@ export class ServicePool { onError: (err, ctx) => this.handleError(err, ctx) }); - // Add all offers to pool + // Add all offers to pool (include the SDP from the initial offer) const allOffers = [ - { id: service.offerId, peerId: this.credentials.peerId, sdp: '', topics: [], expiresAt: service.expiresAt, lastSeen: Date.now() }, + { id: service.offerId, peerId: this.credentials.peerId, sdp: service.offerSdp, topics: [], expiresAt: service.expiresAt, lastSeen: Date.now() }, ...additionalOffers ]; await this.offerPool.addOffers(allOffers); @@ -382,6 +382,7 @@ export class ServicePool { serviceId: string; uuid: string; offerId: string; + offerSdp: string; expiresAt: number; }> { const { username, privateKey, serviceFqn, rtcConfig, isPublic, metadata, ttl } = this.options; @@ -402,6 +403,9 @@ export class ServicePool { throw new Error('Failed to generate SDP'); } + // Store the SDP before closing + const offerSdp = offer.sdp; + // Create signature const timestamp = Date.now(); const message = `publish:${username}:${serviceFqn}:${timestamp}`; @@ -417,7 +421,7 @@ export class ServicePool { body: JSON.stringify({ username, serviceFqn, - sdp: offer.sdp, + sdp: offerSdp, ttl, isPublic, metadata, @@ -439,6 +443,7 @@ export class ServicePool { serviceId: data.serviceId, uuid: data.uuid, offerId: data.offerId, + offerSdp, expiresAt: data.expiresAt }; }