Fix empty SDP in pooled service offers

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 <noreply@anthropic.com>
This commit is contained in:
2025-12-05 20:19:14 +01:00
parent 4a6d0ee091
commit 122f211e7c

View File

@@ -143,9 +143,9 @@ export class ServicePool {
onError: (err, ctx) => this.handleError(err, ctx) 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 = [ 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 ...additionalOffers
]; ];
await this.offerPool.addOffers(allOffers); await this.offerPool.addOffers(allOffers);
@@ -382,6 +382,7 @@ export class ServicePool {
serviceId: string; serviceId: string;
uuid: string; uuid: string;
offerId: string; offerId: string;
offerSdp: string;
expiresAt: number; expiresAt: number;
}> { }> {
const { username, privateKey, serviceFqn, rtcConfig, isPublic, metadata, ttl } = this.options; const { username, privateKey, serviceFqn, rtcConfig, isPublic, metadata, ttl } = this.options;
@@ -402,6 +403,9 @@ export class ServicePool {
throw new Error('Failed to generate SDP'); throw new Error('Failed to generate SDP');
} }
// Store the SDP before closing
const offerSdp = offer.sdp;
// Create signature // Create signature
const timestamp = Date.now(); const timestamp = Date.now();
const message = `publish:${username}:${serviceFqn}:${timestamp}`; const message = `publish:${username}:${serviceFqn}:${timestamp}`;
@@ -417,7 +421,7 @@ export class ServicePool {
body: JSON.stringify({ body: JSON.stringify({
username, username,
serviceFqn, serviceFqn,
sdp: offer.sdp, sdp: offerSdp,
ttl, ttl,
isPublic, isPublic,
metadata, metadata,
@@ -439,6 +443,7 @@ export class ServicePool {
serviceId: data.serviceId, serviceId: data.serviceId,
uuid: data.uuid, uuid: data.uuid,
offerId: data.offerId, offerId: data.offerId,
offerSdp,
expiresAt: data.expiresAt expiresAt: data.expiresAt
}; };
} }