@xtr-dev/rondevu-client 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -18,11 +18,14 @@ export class AnsweringState extends PeerState {
|
|
|
18
18
|
});
|
|
19
19
|
// Create answer
|
|
20
20
|
const answer = await this.peer.pc.createAnswer();
|
|
21
|
-
|
|
22
|
-
//
|
|
21
|
+
// Send answer to server BEFORE setLocalDescription
|
|
22
|
+
// This registers us as the answerer so ICE candidates will be accepted
|
|
23
23
|
await this.peer.offersApi.answer(offerId, answer.sdp);
|
|
24
|
-
// Enable trickle ICE -
|
|
25
|
-
this.setupIceCandidateHandler(
|
|
24
|
+
// Enable trickle ICE - set up handler before ICE gathering starts
|
|
25
|
+
this.setupIceCandidateHandler();
|
|
26
|
+
// Set local description - ICE gathering starts here
|
|
27
|
+
// Server already knows we're the answerer, so candidates will be accepted
|
|
28
|
+
await this.peer.pc.setLocalDescription(answer);
|
|
26
29
|
// Transition to exchanging ICE
|
|
27
30
|
const { ExchangingIceState } = await import('./exchanging-ice-state.js');
|
|
28
31
|
this.peer.setState(new ExchangingIceState(this.peer, offerId, options));
|
|
@@ -16,9 +16,12 @@ export class CreatingOfferState extends PeerState {
|
|
|
16
16
|
const channel = this.peer.pc.createDataChannel(options.dataChannelLabel || 'data');
|
|
17
17
|
this.peer.emitEvent('datachannel', channel);
|
|
18
18
|
}
|
|
19
|
+
// Enable trickle ICE - set up handler before ICE gathering starts
|
|
20
|
+
// Handler will check this.peer.offerId before sending
|
|
21
|
+
this.setupIceCandidateHandler();
|
|
19
22
|
// Create WebRTC offer
|
|
20
23
|
const offer = await this.peer.pc.createOffer();
|
|
21
|
-
await this.peer.pc.setLocalDescription(offer);
|
|
24
|
+
await this.peer.pc.setLocalDescription(offer); // ICE gathering starts here
|
|
22
25
|
// Send offer to server immediately (don't wait for ICE)
|
|
23
26
|
const offers = await this.peer.offersApi.create([{
|
|
24
27
|
sdp: offer.sdp,
|
|
@@ -26,9 +29,7 @@ export class CreatingOfferState extends PeerState {
|
|
|
26
29
|
ttl: options.ttl || 300000
|
|
27
30
|
}]);
|
|
28
31
|
const offerId = offers[0].id;
|
|
29
|
-
this.peer.offerId = offerId;
|
|
30
|
-
// Enable trickle ICE - send candidates as they arrive
|
|
31
|
-
this.setupIceCandidateHandler(offerId);
|
|
32
|
+
this.peer.offerId = offerId; // Now handler can send candidates
|
|
32
33
|
// Transition to waiting for answer
|
|
33
34
|
const { WaitingForAnswerState } = await import('./waiting-for-answer-state.js');
|
|
34
35
|
this.peer.setState(new WaitingForAnswerState(this.peer, offerId, options));
|
package/dist/peer/state.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare abstract class PeerState {
|
|
|
17
17
|
* Setup trickle ICE candidate handler
|
|
18
18
|
* Sends local ICE candidates to server as they are discovered
|
|
19
19
|
*/
|
|
20
|
-
protected setupIceCandidateHandler(
|
|
20
|
+
protected setupIceCandidateHandler(): void;
|
|
21
21
|
cleanup(): void;
|
|
22
22
|
close(): Promise<void>;
|
|
23
23
|
}
|
package/dist/peer/state.js
CHANGED
|
@@ -25,13 +25,13 @@ export class PeerState {
|
|
|
25
25
|
* Setup trickle ICE candidate handler
|
|
26
26
|
* Sends local ICE candidates to server as they are discovered
|
|
27
27
|
*/
|
|
28
|
-
setupIceCandidateHandler(
|
|
28
|
+
setupIceCandidateHandler() {
|
|
29
29
|
this.iceCandidateHandler = async (event) => {
|
|
30
|
-
if (event.candidate && offerId) {
|
|
30
|
+
if (event.candidate && this.peer.offerId) {
|
|
31
31
|
const candidateData = event.candidate.toJSON();
|
|
32
32
|
if (candidateData.candidate && candidateData.candidate !== '') {
|
|
33
33
|
try {
|
|
34
|
-
await this.peer.offersApi.addIceCandidates(offerId, [candidateData]);
|
|
34
|
+
await this.peer.offersApi.addIceCandidates(this.peer.offerId, [candidateData]);
|
|
35
35
|
}
|
|
36
36
|
catch (err) {
|
|
37
37
|
console.error('Error sending ICE candidate:', err);
|