@abraca/dabra 1.0.14 → 1.0.15

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.
@@ -106,7 +106,11 @@ export class ManualSignaling extends EventEmitter {
106
106
 
107
107
  // Add remote ICE candidates.
108
108
  for (const c of offerBlob.candidates) {
109
- await this.pc.addIceCandidate(new RTCIceCandidate(JSON.parse(c)));
109
+ try {
110
+ await this.pc.addIceCandidate(new RTCIceCandidate(JSON.parse(c)));
111
+ } catch {
112
+ // Skip malformed ICE candidate
113
+ }
110
114
  }
111
115
 
112
116
  // Create answer.
@@ -87,9 +87,21 @@ export class SignalingSocket extends EventEmitter {
87
87
  return this.config.token;
88
88
  }
89
89
 
90
+ private _connectPromise: Promise<void> | null = null;
91
+
90
92
  async connect(): Promise<void> {
91
93
  if (this.isConnected) return;
94
+ if (this._connectPromise) return this._connectPromise;
95
+
96
+ this._connectPromise = this._doConnect();
97
+ try {
98
+ await this._connectPromise;
99
+ } finally {
100
+ this._connectPromise = null;
101
+ }
102
+ }
92
103
 
104
+ private async _doConnect(): Promise<void> {
93
105
  if (this.cancelRetry) {
94
106
  this.cancelRetry();
95
107
  this.cancelRetry = undefined;
@@ -18,6 +18,7 @@ import { CHANNEL_NAMES, YJS_MSG } from "./types.ts";
18
18
  * prevent echo loops with the server-based provider.
19
19
  */
20
20
  export class YjsDataChannel {
21
+ public isSynced = false;
21
22
  private docUpdateHandler: ((update: Uint8Array, origin: any) => void) | null = null;
22
23
  private awarenessUpdateHandler: ((changes: { added: number[]; updated: number[]; removed: number[] }, origin: any) => void) | null = null;
23
24
  private channelOpenHandler: ((data: { name: string; channel: RTCDataChannel }) => void) | null = null;