@abraca/dabra 1.0.13 → 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.
@@ -200,6 +200,8 @@ export class SearchIndex {
200
200
  const queryTrigrams = [...extractTrigrams(query)];
201
201
  if (queryTrigrams.length === 0) return [];
202
202
 
203
+ const maxScoreEntries = limit * 10;
204
+
203
205
  return new Promise<SearchResult[]>((resolve, reject) => {
204
206
  const tx = db.transaction("postings", "readonly");
205
207
  const postings = tx.objectStore("postings");
@@ -212,6 +214,7 @@ export class SearchIndex {
212
214
  const docIds: string[] = req.result ?? [];
213
215
  for (const docId of docIds) {
214
216
  scores.set(docId, (scores.get(docId) ?? 0) + 1);
217
+ if (scores.size >= maxScoreEntries) break;
215
218
  }
216
219
  remaining--;
217
220
  if (remaining === 0) {
@@ -94,9 +94,9 @@ export class DataChannelRouter extends EventEmitter {
94
94
  * Send data on a named channel, encrypting if E2EE is active.
95
95
  * Falls back to plaintext if no encryptor is set or for exempt channels.
96
96
  */
97
- async send(name: string, data: Uint8Array): Promise<void> {
97
+ async send(name: string, data: Uint8Array): Promise<boolean> {
98
98
  const channel = this.channels.get(name);
99
- if (!channel || channel.readyState !== "open") return;
99
+ if (!channel || channel.readyState !== "open") return false;
100
100
 
101
101
  if (this.encryptor?.isEstablished && !this.plaintextChannels.has(name)) {
102
102
  const encrypted = await this.encryptor.encrypt(data);
@@ -104,6 +104,7 @@ export class DataChannelRouter extends EventEmitter {
104
104
  } else {
105
105
  channel.send(data);
106
106
  }
107
+ return true;
107
108
  }
108
109
 
109
110
  private registerChannel(channel: RTCDataChannel): void {
@@ -207,6 +207,7 @@ export class FileTransferChannel extends EventEmitter {
207
207
  try {
208
208
  meta = JSON.parse(json);
209
209
  } catch {
210
+ this.emit("receiveError", { transferId: "unknown", error: "Malformed START message: invalid JSON" });
210
211
  return;
211
212
  }
212
213
 
@@ -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;