cry-synced-db-client 0.1.21 → 0.1.23

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.
@@ -30,6 +30,7 @@ export declare class SyncedDb implements I_SyncedDb {
30
30
  private onWsDisconnect?;
31
31
  private onWsReconnect?;
32
32
  private onWsNotification?;
33
+ private onOnlineStatusChange?;
33
34
  private online;
34
35
  private forcedOffline;
35
36
  private syncing;
package/dist/index.js CHANGED
@@ -282,6 +282,7 @@ class SyncedDb {
282
282
  onWsDisconnect;
283
283
  onWsReconnect;
284
284
  onWsNotification;
285
+ onOnlineStatusChange;
285
286
  online = false;
286
287
  forcedOffline = false;
287
288
  syncing = false;
@@ -319,6 +320,7 @@ class SyncedDb {
319
320
  this.onWsDisconnect = config.onWsDisconnect;
320
321
  this.onWsReconnect = config.onWsReconnect;
321
322
  this.onWsNotification = config.onWsNotification;
323
+ this.onOnlineStatusChange = config.onOnlineStatusChange;
322
324
  this.updaterId = Math.random().toString(36).substring(2, 15);
323
325
  for (const col of config.collections) {
324
326
  this.collections.set(col.name, col);
@@ -382,7 +384,7 @@ class SyncedDb {
382
384
  this.forcedOffline = forced;
383
385
  if (forced) {
384
386
  this.stopAutoSync();
385
- } else if (this.online) {
387
+ } else {
386
388
  this.tryGoOnline().catch((err) => {
387
389
  console.error("Failed to go online after forceOffline release:", err);
388
390
  });
@@ -404,8 +406,12 @@ class SyncedDb {
404
406
  }
405
407
  }
406
408
  goOffline(reason) {
409
+ const wasOnline = this.online;
407
410
  this.online = false;
408
411
  this.stopAutoSync();
412
+ if (wasOnline) {
413
+ this.onOnlineStatusChange?.(false);
414
+ }
409
415
  if (this.onForcedOffline) {
410
416
  try {
411
417
  this.onForcedOffline(reason);
@@ -424,12 +430,20 @@ class SyncedDb {
424
430
  console.warn("Ping failed - staying offline");
425
431
  return;
426
432
  }
433
+ const wasOffline = !this.online;
427
434
  this.online = true;
435
+ if (wasOffline) {
436
+ this.onOnlineStatusChange?.(true);
437
+ }
428
438
  this.startAutoSync();
429
439
  await this.sync("INITIAL SYNC");
430
440
  } catch (err) {
431
441
  console.warn("Failed to go online (ping failed or timed out):", err);
442
+ const wasOnline = this.online;
432
443
  this.online = false;
444
+ if (wasOnline) {
445
+ this.onOnlineStatusChange?.(false);
446
+ }
433
447
  }
434
448
  }
435
449
  startAutoSync() {
@@ -203,6 +203,8 @@ export interface SyncedDbConfig {
203
203
  onWsReconnect?: (attempt: number) => void;
204
204
  /** Callback when a WebSocket notification is received */
205
205
  onWsNotification?: (info: WsNotificationInfo) => void;
206
+ /** Callback when online status changes (after ping success/failure in tryGoOnline or goOffline) */
207
+ onOnlineStatusChange?: (online: boolean) => void;
206
208
  }
207
209
  /**
208
210
  * Glavna logika za sinhronizirano bazo podatkov
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",