@kokimoki/app 0.6.0 → 0.6.2
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/dist/kokimoki-client.d.ts +2 -3
- package/dist/kokimoki-client.js +28 -18
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -18,8 +18,7 @@ export declare class KokimokiClient<StatelessDataT = any, ClientContextT = any>
|
|
|
18
18
|
private _providers;
|
|
19
19
|
private _serverTimeOffset;
|
|
20
20
|
private _clientContext?;
|
|
21
|
-
private
|
|
22
|
-
private _connected;
|
|
21
|
+
private _synced;
|
|
23
22
|
constructor(host: string, appId: string, code?: string);
|
|
24
23
|
get id(): string;
|
|
25
24
|
get token(): string;
|
|
@@ -28,7 +27,7 @@ export declare class KokimokiClient<StatelessDataT = any, ClientContextT = any>
|
|
|
28
27
|
get clientContext(): NonNullable<ClientContextT>;
|
|
29
28
|
connect(): Promise<void>;
|
|
30
29
|
serverTimestamp(): number;
|
|
31
|
-
private
|
|
30
|
+
private checkConnectionState;
|
|
32
31
|
setProvider<T extends DocTypeDescription>(name: string, store: SyncedStore<T>): Promise<void>;
|
|
33
32
|
removeProvider(name: string): void;
|
|
34
33
|
getProvider(name: string): HocuspocusProvider | undefined;
|
package/dist/kokimoki-client.js
CHANGED
|
@@ -13,8 +13,7 @@ export class KokimokiClient extends EventEmitter {
|
|
|
13
13
|
_providers = new Map();
|
|
14
14
|
_serverTimeOffset = 0;
|
|
15
15
|
_clientContext;
|
|
16
|
-
|
|
17
|
-
_connected = false;
|
|
16
|
+
_synced = false;
|
|
18
17
|
constructor(host, appId, code = "") {
|
|
19
18
|
super();
|
|
20
19
|
this.host = host;
|
|
@@ -84,26 +83,23 @@ export class KokimokiClient extends EventEmitter {
|
|
|
84
83
|
this._providers.forEach((provider) => {
|
|
85
84
|
provider.sendStateless("ping");
|
|
86
85
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this._lastPong < Date.now() - 10000) {
|
|
91
|
-
this.emit("disconnected");
|
|
92
|
-
this._connected = false;
|
|
93
|
-
}
|
|
94
|
-
}, 10000);
|
|
95
|
-
// Emit initial connected event
|
|
86
|
+
}, 30000);
|
|
87
|
+
// Initial connected state
|
|
88
|
+
this._synced = true;
|
|
96
89
|
this.emit("connected");
|
|
97
|
-
this._connected = true;
|
|
98
90
|
}
|
|
99
91
|
serverTimestamp() {
|
|
100
92
|
return Date.now() - this._serverTimeOffset;
|
|
101
93
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (!this.
|
|
94
|
+
checkConnectionState() {
|
|
95
|
+
const synced = !Array.from(this._providers.values()).some((provider) => provider.status !== "connected" || !provider.synced);
|
|
96
|
+
if (synced && !this._synced) {
|
|
97
|
+
this._synced = true;
|
|
105
98
|
this.emit("connected");
|
|
106
|
-
|
|
99
|
+
}
|
|
100
|
+
else if (!synced && this._synced) {
|
|
101
|
+
this._synced = false;
|
|
102
|
+
this.emit("disconnected");
|
|
107
103
|
}
|
|
108
104
|
}
|
|
109
105
|
// Realtime database
|
|
@@ -120,7 +116,6 @@ export class KokimokiClient extends EventEmitter {
|
|
|
120
116
|
// Handle incoming stateless messages
|
|
121
117
|
provider.on("stateless", (e) => {
|
|
122
118
|
if (e.payload === "pong") {
|
|
123
|
-
this.receivePong();
|
|
124
119
|
return;
|
|
125
120
|
}
|
|
126
121
|
const payload = JSON.parse(e.payload);
|
|
@@ -134,8 +129,21 @@ export class KokimokiClient extends EventEmitter {
|
|
|
134
129
|
};
|
|
135
130
|
provider.on("synced", handler);
|
|
136
131
|
});
|
|
137
|
-
this.receivePong();
|
|
138
132
|
this._providers.set(name, provider);
|
|
133
|
+
this.checkConnectionState();
|
|
134
|
+
// Handle connection state changes
|
|
135
|
+
provider.on("disconnect", async () => {
|
|
136
|
+
// KokimokiClient is considered disconnected when any single provider is disconnected
|
|
137
|
+
this.checkConnectionState();
|
|
138
|
+
// Attempt to reconnect immediately with retries
|
|
139
|
+
await provider.connect();
|
|
140
|
+
});
|
|
141
|
+
provider.on("connect", () => {
|
|
142
|
+
this.checkConnectionState();
|
|
143
|
+
});
|
|
144
|
+
provider.on("synced", () => {
|
|
145
|
+
this.checkConnectionState();
|
|
146
|
+
});
|
|
139
147
|
}
|
|
140
148
|
removeProvider(name) {
|
|
141
149
|
const provider = this._providers.get(name);
|
|
@@ -144,6 +152,8 @@ export class KokimokiClient extends EventEmitter {
|
|
|
144
152
|
}
|
|
145
153
|
provider.destroy();
|
|
146
154
|
this._providers.delete(name);
|
|
155
|
+
// Connection state can change if the removed provider was not connected or synced
|
|
156
|
+
this.checkConnectionState();
|
|
147
157
|
}
|
|
148
158
|
getProvider(name) {
|
|
149
159
|
return this._providers.get(name);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const KOKIMOKI_APP_VERSION = "0.6.
|
|
1
|
+
export declare const KOKIMOKI_APP_VERSION = "0.6.2";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const KOKIMOKI_APP_VERSION = "0.6.
|
|
1
|
+
export const KOKIMOKI_APP_VERSION = "0.6.2";
|