@johnhenry/browsermesh-transport 0.1.2 → 0.1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/websocket.mjs +37 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnhenry/browsermesh-transport",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "WebSocket, WebRTC, WebTransport, and relay adapters for BrowserMesh",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
package/src/websocket.mjs CHANGED
@@ -555,6 +555,43 @@ export class WebRTCTransport {
555
555
  async handleOffer(offer) {
556
556
  if (!this.#pc) {
557
557
  this.#pc = new this.#RTCPeerConnectionCtor(this.#config);
558
+
559
+ // Mirror connect()'s wiring, which this answerer path was missing
560
+ // entirely: without it, this side's own gathered ICE candidates were
561
+ // never sent to the remote peer, and ICE candidates received from the
562
+ // remote peer were never fed into this RTCPeerConnection -- SDP offer/
563
+ // answer still completed (that's a separate exchange), but ICE
564
+ // connectivity checks then had no candidates to try on either side,
565
+ // so the connection stalled forever in its initial ICE state. Only
566
+ // wired when a fresh RTCPeerConnection is actually created here, so a
567
+ // reused #pc (offer arriving twice on the same transport) is not
568
+ // double-registered.
569
+ this.#pc.addEventListener('icecandidate', (ev) => {
570
+ if (ev.candidate) {
571
+ this.#signaler.sendIceCandidate(this.#remotePodId, ev.candidate);
572
+ this._fireEvent('ice-candidate', ev.candidate);
573
+ }
574
+ });
575
+
576
+ this.#pc.addEventListener('connectionstatechange', () => {
577
+ this.#stats.iceState = this.#pc.iceConnectionState || 'unknown';
578
+ if (this.#pc.connectionState === 'failed' || this.#pc.connectionState === 'closed') {
579
+ if (this.#state !== 'closed' && this.#state !== 'closing') {
580
+ this.#state = 'closed';
581
+ this._fireEvent('close');
582
+ }
583
+ }
584
+ });
585
+
586
+ this.#signaler.onIceCandidate((data) => {
587
+ if (this.#pc) {
588
+ // See connect()'s identical handler: the promise must not be
589
+ // dropped, for the same reason.
590
+ Promise.resolve(this.#pc.addIceCandidate(data.candidate)).catch((e) => {
591
+ silentCatch('clawser-mesh-websocket', 'ignore-rejected-ice-candidate', e);
592
+ });
593
+ }
594
+ });
558
595
  }
559
596
  this.#state = 'connecting';
560
597