@xtr-dev/rondevu-client 0.7.1 → 0.7.2

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.
@@ -16,13 +16,13 @@ export class AnsweringState extends PeerState {
16
16
  type: 'offer',
17
17
  sdp: offerSdp
18
18
  });
19
+ // Enable trickle ICE - set up handler before ICE gathering starts
20
+ this.setupIceCandidateHandler();
19
21
  // Create answer
20
22
  const answer = await this.peer.pc.createAnswer();
21
- await this.peer.pc.setLocalDescription(answer);
23
+ await this.peer.pc.setLocalDescription(answer); // ICE gathering starts here
22
24
  // Send answer to server immediately (don't wait for ICE)
23
25
  await this.peer.offersApi.answer(offerId, answer.sdp);
24
- // Enable trickle ICE - send candidates as they arrive
25
- this.setupIceCandidateHandler(offerId);
26
26
  // Transition to exchanging ICE
27
27
  const { ExchangingIceState } = await import('./exchanging-ice-state.js');
28
28
  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));
@@ -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(offerId: string): void;
20
+ protected setupIceCandidateHandler(): void;
21
21
  cleanup(): void;
22
22
  close(): Promise<void>;
23
23
  }
@@ -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(offerId) {
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtr-dev/rondevu-client",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "TypeScript client for Rondevu topic-based peer discovery and signaling server",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",