diff --git a/src/offer-pool.ts b/src/offer-pool.ts index 3e5c1c1..da9f5e7 100644 --- a/src/offer-pool.ts +++ b/src/offer-pool.ts @@ -6,7 +6,8 @@ import { RondevuOffers, Offer } from './offers.js'; export interface AnsweredOffer { offerId: string; answererId: string; - sdp: string; + sdp: string; // Answer SDP + offerSdp: string; // Original offer SDP answeredAt: number; } @@ -110,11 +111,18 @@ export class OfferPool { // Process each answer for (const answer of myAnswers) { - // Notify ServicePool + // Get the original offer + const offer = this.offers.get(answer.offerId); + if (!offer) { + continue; // Offer already consumed, skip + } + + // Notify ServicePool with both answer and original offer SDP await this.options.onAnswered({ offerId: answer.offerId, answererId: answer.answererId, sdp: answer.sdp, + offerSdp: offer.sdp, answeredAt: answer.answeredAt }); diff --git a/src/service-pool.ts b/src/service-pool.ts index 7c3c136..d2e9ed6 100644 --- a/src/service-pool.ts +++ b/src/service-pool.ts @@ -241,7 +241,13 @@ export class ServicePool { peer.role = 'offerer'; peer.offerId = answer.offerId; - // Set remote description (the answer) + // Set local description (the original offer) first + await peer.pc.setLocalDescription({ + type: 'offer', + sdp: answer.offerSdp + }); + + // Now set remote description (the answer) await peer.pc.setRemoteDescription({ type: 'answer', sdp: answer.sdp