@kokimoki/app 0.6.3 → 0.6.5
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 -0
- package/dist/kokimoki-client.js +21 -8
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -19,6 +19,7 @@ export declare class KokimokiClient<StatelessDataT = any, ClientContextT = any>
|
|
|
19
19
|
private _serverTimeOffset;
|
|
20
20
|
private _clientContext?;
|
|
21
21
|
private _synced;
|
|
22
|
+
private _lastPongAt;
|
|
22
23
|
constructor(host: string, appId: string, code?: string);
|
|
23
24
|
get id(): string;
|
|
24
25
|
get token(): string;
|
|
@@ -27,6 +28,7 @@ export declare class KokimokiClient<StatelessDataT = any, ClientContextT = any>
|
|
|
27
28
|
get clientContext(): ClientContextT & ({} | null);
|
|
28
29
|
connect(): Promise<void>;
|
|
29
30
|
serverTimestamp(): number;
|
|
31
|
+
private receivePong;
|
|
30
32
|
private checkConnectionState;
|
|
31
33
|
setProvider<T extends DocTypeDescription>(name: string, store: SyncedStore<T>): Promise<void>;
|
|
32
34
|
removeProvider(name: string): void;
|
package/dist/kokimoki-client.js
CHANGED
|
@@ -14,6 +14,7 @@ export class KokimokiClient extends EventEmitter {
|
|
|
14
14
|
_serverTimeOffset = 0;
|
|
15
15
|
_clientContext;
|
|
16
16
|
_synced = false;
|
|
17
|
+
_lastPongAt = 0;
|
|
17
18
|
constructor(host, appId, code = "") {
|
|
18
19
|
super();
|
|
19
20
|
this.host = host;
|
|
@@ -80,19 +81,30 @@ export class KokimokiClient extends EventEmitter {
|
|
|
80
81
|
});
|
|
81
82
|
// Ping interval
|
|
82
83
|
setInterval(() => {
|
|
83
|
-
this.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this._synced = true;
|
|
89
|
-
this.emit("connected");
|
|
84
|
+
this.checkConnectionState();
|
|
85
|
+
this._providers.forEach((provider) => provider.sendStateless("ping"));
|
|
86
|
+
}, 5000);
|
|
87
|
+
// Check initial connected state
|
|
88
|
+
this.receivePong();
|
|
90
89
|
}
|
|
91
90
|
serverTimestamp() {
|
|
92
91
|
return Date.now() - this._serverTimeOffset;
|
|
93
92
|
}
|
|
93
|
+
receivePong() {
|
|
94
|
+
this._lastPongAt = Date.now();
|
|
95
|
+
this.checkConnectionState();
|
|
96
|
+
}
|
|
94
97
|
checkConnectionState() {
|
|
95
|
-
const
|
|
98
|
+
const pongReceived = Date.now() - this._lastPongAt < 6000;
|
|
99
|
+
if (!pongReceived && this._synced) {
|
|
100
|
+
// Reset connections to providers
|
|
101
|
+
this._providers.forEach(async (provider) => {
|
|
102
|
+
provider.disconnect();
|
|
103
|
+
await provider.connect();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const synced = pongReceived &&
|
|
107
|
+
!Array.from(this._providers.values()).some((provider) => provider.status !== "connected" || !provider.synced);
|
|
96
108
|
if (synced && !this._synced) {
|
|
97
109
|
this._synced = true;
|
|
98
110
|
this.emit("connected");
|
|
@@ -116,6 +128,7 @@ export class KokimokiClient extends EventEmitter {
|
|
|
116
128
|
// Handle incoming stateless messages
|
|
117
129
|
provider.on("stateless", (e) => {
|
|
118
130
|
if (e.payload === "pong") {
|
|
131
|
+
this._lastPongAt = Date.now();
|
|
119
132
|
return;
|
|
120
133
|
}
|
|
121
134
|
const payload = JSON.parse(e.payload);
|
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.5";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const KOKIMOKI_APP_VERSION = "0.6.
|
|
1
|
+
export const KOKIMOKI_APP_VERSION = "0.6.5";
|