y-openrtc 0.1.2 → 1.0.0

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.
package/README.md CHANGED
@@ -69,6 +69,8 @@ Keep TURN credentials server-generated and short lived. Do not commit `.env` fil
69
69
 
70
70
  - `signaling` and `peerOpts` are accepted for compatibility, but ignored.
71
71
  - OpenRTC remains the source of truth for room membership and peer transport.
72
+ - Runtime connection events and room-membership changes drive peer attachment;
73
+ the provider does not poll or own base-connection retries.
72
74
  - Same-tab sync still prefers `BroadcastChannel` when available.
73
75
  - `password` encrypts provider payloads end-to-end on top of OpenRTC.
74
76
 
@@ -34,7 +34,6 @@ export declare class OpenrtcProvider {
34
34
  private localObserversAttached;
35
35
  private connectPromise;
36
36
  private reconcileTimer;
37
- private runtimeRefreshTimer;
38
37
  private readonly diagnostics;
39
38
  constructor(roomName: string, doc: Y.Doc, options?: OpenrtcProviderOptions);
40
39
  get connected(): boolean;
@@ -66,12 +65,12 @@ export declare class OpenrtcProvider {
66
65
  private hasBcNodeId;
67
66
  private isRelevantConnection;
68
67
  private refreshKnownRuntimeConnections;
69
- private startRuntimeConnectionRefresh;
70
68
  private resyncPeer;
71
69
  private sendInitialSync;
72
70
  private attachConnection;
73
71
  private sendToConnection;
74
72
  private sendControlToConnection;
73
+ private sendControlBestEffort;
75
74
  private sendBroadcastPayload;
76
75
  private broadcastProviderPayload;
77
76
  private broadcastInitialBcState;
package/dist/provider.js CHANGED
@@ -68,6 +68,9 @@ function isRoomFullError(error) {
68
68
  function isTransientStartupError(error) {
69
69
  return /relay-only endpoint ticket unavailable|failed to fetch|network|timed out/i.test(errorText(error));
70
70
  }
71
+ function isClosedConnectionSendError(error) {
72
+ return /connection is closed|closed connection|not open|writer is closed|application crypto is required but the connection is closed/i.test(errorText(error));
73
+ }
71
74
  function sleep(ms) {
72
75
  return new Promise((resolve) => setTimeout(resolve, ms));
73
76
  }
@@ -93,7 +96,6 @@ export class OpenrtcProvider {
93
96
  this.localObserversAttached = false;
94
97
  this.connectPromise = null;
95
98
  this.reconcileTimer = null;
96
- this.runtimeRefreshTimer = null;
97
99
  this.diagnostics = {
98
100
  openrtcSent: 0,
99
101
  openrtcReceived: 0,
@@ -282,7 +284,6 @@ export class OpenrtcProvider {
282
284
  return;
283
285
  }
284
286
  this.attachConnection(connection);
285
- void this.reconcilePeers();
286
287
  });
287
288
  if (typeof runtime.onConnectionStateChange === 'function') {
288
289
  const stopRuntimeConnectionStates = runtime.onConnectionStateChange((state) => {
@@ -350,7 +351,6 @@ export class OpenrtcProvider {
350
351
  this.requestReconcile();
351
352
  });
352
353
  this.refreshKnownRuntimeConnections();
353
- this.startRuntimeConnectionRefresh();
354
354
  this.broadcastInitialBcState();
355
355
  this.requestReconcile();
356
356
  this.updateSyncedState();
@@ -508,7 +508,6 @@ export class OpenrtcProvider {
508
508
  }
509
509
  catch (error) {
510
510
  console.warn(`[y-openrtc] failed to connect to room peer ${member.nodeId}:`, error);
511
- this.requestReconcile();
512
511
  }
513
512
  finally {
514
513
  this.pendingNodeIds.delete(member.nodeId);
@@ -540,31 +539,22 @@ export class OpenrtcProvider {
540
539
  }
541
540
  }
542
541
  }
543
- startRuntimeConnectionRefresh() {
544
- if (this.runtimeRefreshTimer) {
545
- return;
546
- }
547
- this.runtimeRefreshTimer = setInterval(() => {
548
- this.refreshKnownRuntimeConnections();
549
- this.requestReconcile();
550
- }, 1000);
551
- }
552
542
  resyncPeer(remoteNodeId) {
553
543
  const record = this.openrtcConnections.get(remoteNodeId);
554
544
  if (!record) {
555
545
  return;
556
546
  }
557
547
  record.synced = false;
558
- void this.sendControlToConnection(record.connection, encodeSyncStep1(this.doc));
559
- void this.sendControlToConnection(record.connection, encodeAwarenessQuery());
548
+ this.sendControlBestEffort(record.connection, encodeSyncStep1(this.doc));
549
+ this.sendControlBestEffort(record.connection, encodeAwarenessQuery());
560
550
  this.updateSyncedState();
561
551
  }
562
552
  sendInitialSync(connection, record) {
563
- void this.sendControlToConnection(connection, encodeSyncStep1(this.doc));
564
- void this.sendControlToConnection(connection, encodeAwarenessQuery());
553
+ this.sendControlBestEffort(connection, encodeSyncStep1(this.doc));
554
+ this.sendControlBestEffort(connection, encodeAwarenessQuery());
565
555
  const awarenessStates = Array.from(this.awareness.getStates().keys());
566
556
  if (awarenessStates.length > 0) {
567
- void this.sendControlToConnection(connection, encodeAwarenessUpdate(this.awareness, awarenessStates));
557
+ this.sendControlBestEffort(connection, encodeAwarenessUpdate(this.awareness, awarenessStates));
568
558
  }
569
559
  for (const delayMs of [250, 1000, 3000]) {
570
560
  setTimeout(() => {
@@ -575,8 +565,8 @@ export class OpenrtcProvider {
575
565
  || this.openrtcConnections.get(connection.remoteNodeId)?.connection.id !== connection.id) {
576
566
  return;
577
567
  }
578
- void this.sendControlToConnection(connection, encodeSyncStep1(this.doc));
579
- void this.sendControlToConnection(connection, encodeAwarenessQuery());
568
+ this.sendControlBestEffort(connection, encodeSyncStep1(this.doc));
569
+ this.sendControlBestEffort(connection, encodeAwarenessQuery());
580
570
  }, delayMs);
581
571
  }
582
572
  }
@@ -604,7 +594,11 @@ export class OpenrtcProvider {
604
594
  return;
605
595
  }
606
596
  this.diagnostics.openrtcReceived += 1;
607
- void this.handleIncomingPayload(normalizeBinaryPayload(message), { type: 'openrtc', nodeId, connectionId: connection.id }, (reply) => this.sendControlToConnection(connection, reply), record);
597
+ void this.handleIncomingPayload(normalizeBinaryPayload(message), { type: 'openrtc', nodeId, connectionId: connection.id }, (reply) => this.sendControlToConnection(connection, reply), record).catch((error) => {
598
+ if (!isClosedConnectionSendError(error)) {
599
+ console.warn('[y-openrtc] incoming payload handler failed', error);
600
+ }
601
+ });
608
602
  });
609
603
  connection.onDisconnect(() => {
610
604
  if (!this.openrtcConnections.delete(nodeId)) {
@@ -612,7 +606,6 @@ export class OpenrtcProvider {
612
606
  }
613
607
  this.emitPeers([], [nodeId]);
614
608
  this.updateSyncedState();
615
- this.requestReconcile();
616
609
  });
617
610
  this.sendInitialSync(connection, record);
618
611
  }
@@ -642,6 +635,13 @@ export class OpenrtcProvider {
642
635
  }
643
636
  await connection.send(encrypted);
644
637
  }
638
+ sendControlBestEffort(connection, payload) {
639
+ void this.sendControlToConnection(connection, payload).catch((error) => {
640
+ if (!isClosedConnectionSendError(error)) {
641
+ console.warn('[y-openrtc] control send failed', error);
642
+ }
643
+ });
644
+ }
645
645
  async sendBroadcastPayload(payload) {
646
646
  const encrypted = await encryptFrame(payload, await this.keyPromise);
647
647
  this.diagnostics.broadcastSent += 1;
@@ -731,10 +731,6 @@ export class OpenrtcProvider {
731
731
  clearTimeout(this.reconcileTimer);
732
732
  this.reconcileTimer = null;
733
733
  }
734
- if (this.runtimeRefreshTimer) {
735
- clearInterval(this.runtimeRefreshTimer);
736
- this.runtimeRefreshTimer = null;
737
- }
738
734
  this.broadcastTransport?.disconnect();
739
735
  this.broadcastTransport = null;
740
736
  this.roomMembers.clear();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "y-openrtc",
3
- "version": "0.1.2",
3
+ "version": "1.0.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "lib0": "^0.2.114",
46
- "openrtc": "^0.2.0",
46
+ "openrtc": "^1.0.0",
47
47
  "y-protocols": "^1.0.6"
48
48
  },
49
49
  "peerDependencies": {