@kokimoki/app 0.6.5 → 0.6.7

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.
@@ -18,7 +18,7 @@ export declare class KokimokiClient<StatelessDataT = any, ClientContextT = any>
18
18
  private _providers;
19
19
  private _serverTimeOffset;
20
20
  private _clientContext?;
21
- private _synced;
21
+ private _connected;
22
22
  private _lastPongAt;
23
23
  constructor(host: string, appId: string, code?: string);
24
24
  get id(): string;
@@ -13,7 +13,7 @@ export class KokimokiClient extends EventEmitter {
13
13
  _providers = new Map();
14
14
  _serverTimeOffset = 0;
15
15
  _clientContext;
16
- _synced = false;
16
+ _connected = false;
17
17
  _lastPongAt = 0;
18
18
  constructor(host, appId, code = "") {
19
19
  super();
@@ -95,24 +95,20 @@ export class KokimokiClient extends EventEmitter {
95
95
  this.checkConnectionState();
96
96
  }
97
97
  checkConnectionState() {
98
- const pongReceived = Date.now() - this._lastPongAt < 6000;
99
- if (!pongReceived && this._synced) {
98
+ const connected = this._providers.size === 0 || Date.now() - this._lastPongAt < 6000;
99
+ if (connected && !this._connected) {
100
+ this._connected = true;
101
+ this.emit("connected");
102
+ }
103
+ else if (!connected && this._connected) {
104
+ this._connected = false;
105
+ this.emit("disconnected");
100
106
  // Reset connections to providers
101
107
  this._providers.forEach(async (provider) => {
102
108
  provider.disconnect();
103
109
  await provider.connect();
104
110
  });
105
111
  }
106
- const synced = pongReceived &&
107
- !Array.from(this._providers.values()).some((provider) => provider.status !== "connected" || !provider.synced);
108
- if (synced && !this._synced) {
109
- this._synced = true;
110
- this.emit("connected");
111
- }
112
- else if (!synced && this._synced) {
113
- this._synced = false;
114
- this.emit("disconnected");
115
- }
116
112
  }
117
113
  // Realtime database
118
114
  async setProvider(name, store) {
@@ -142,21 +138,9 @@ export class KokimokiClient extends EventEmitter {
142
138
  };
143
139
  provider.on("synced", handler);
144
140
  });
141
+ this._lastPongAt = Date.now();
145
142
  this._providers.set(name, provider);
146
143
  this.checkConnectionState();
147
- // Handle connection state changes
148
- provider.on("disconnect", async () => {
149
- // KokimokiClient is considered disconnected when any single provider is disconnected
150
- this.checkConnectionState();
151
- // Attempt to reconnect immediately with retries
152
- await provider.connect();
153
- });
154
- provider.on("connect", () => {
155
- this.checkConnectionState();
156
- });
157
- provider.on("synced", () => {
158
- this.checkConnectionState();
159
- });
160
144
  }
161
145
  removeProvider(name) {
162
146
  const provider = this._providers.get(name);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const KOKIMOKI_APP_VERSION = "0.6.5";
1
+ export declare const KOKIMOKI_APP_VERSION = "0.6.7";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const KOKIMOKI_APP_VERSION = "0.6.5";
1
+ export const KOKIMOKI_APP_VERSION = "0.6.7";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokimoki/app",
3
- "version": "0.6.5",
3
+ "version": "0.6.7",
4
4
  "type": "module",
5
5
  "description": "Kokimoki app",
6
6
  "main": "dist/index.js",