@unicitylabs/sphere-sdk 0.6.10-dev.3 → 0.6.10-dev.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/core/index.cjs +41 -18
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +41 -18
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +41 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +41 -18
- package/dist/index.js.map +1 -1
- package/dist/l1/index.cjs +32 -0
- package/dist/l1/index.cjs.map +1 -1
- package/dist/l1/index.js +32 -0
- package/dist/l1/index.js.map +1 -1
- package/package.json +2 -2
package/dist/core/index.d.cts
CHANGED
|
@@ -3269,7 +3269,7 @@ declare class GroupChatModule {
|
|
|
3269
3269
|
constructor(config?: GroupChatModuleConfig);
|
|
3270
3270
|
initialize(deps: GroupChatModuleDependencies): void;
|
|
3271
3271
|
load(): Promise<void>;
|
|
3272
|
-
destroy():
|
|
3272
|
+
destroy(): void;
|
|
3273
3273
|
private destroyConnection;
|
|
3274
3274
|
connect(): Promise<void>;
|
|
3275
3275
|
getConnectionStatus(): boolean;
|
package/dist/core/index.d.ts
CHANGED
|
@@ -3269,7 +3269,7 @@ declare class GroupChatModule {
|
|
|
3269
3269
|
constructor(config?: GroupChatModuleConfig);
|
|
3270
3270
|
initialize(deps: GroupChatModuleDependencies): void;
|
|
3271
3271
|
load(): Promise<void>;
|
|
3272
|
-
destroy():
|
|
3272
|
+
destroy(): void;
|
|
3273
3273
|
private destroyConnection;
|
|
3274
3274
|
connect(): Promise<void>;
|
|
3275
3275
|
getConnectionStatus(): boolean;
|
package/dist/core/index.js
CHANGED
|
@@ -515,6 +515,33 @@ function waitForConnection() {
|
|
|
515
515
|
connectionCallbacks.push(callback);
|
|
516
516
|
});
|
|
517
517
|
}
|
|
518
|
+
function startPingTimer() {
|
|
519
|
+
stopPingTimer();
|
|
520
|
+
pingTimer = setInterval(() => {
|
|
521
|
+
if (!ws || ws.readyState !== WebSocket.OPEN) return;
|
|
522
|
+
try {
|
|
523
|
+
const id = ++requestId;
|
|
524
|
+
ws.send(JSON.stringify({ jsonrpc: "2.0", id, method: "server.ping", params: [] }));
|
|
525
|
+
pending[id] = {
|
|
526
|
+
resolve: () => {
|
|
527
|
+
},
|
|
528
|
+
reject: () => {
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
const timeoutId = setTimeout(() => {
|
|
532
|
+
delete pending[id];
|
|
533
|
+
}, 1e4);
|
|
534
|
+
pending[id].timeoutId = timeoutId;
|
|
535
|
+
} catch {
|
|
536
|
+
}
|
|
537
|
+
}, PING_INTERVAL);
|
|
538
|
+
}
|
|
539
|
+
function stopPingTimer() {
|
|
540
|
+
if (pingTimer) {
|
|
541
|
+
clearInterval(pingTimer);
|
|
542
|
+
pingTimer = null;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
518
545
|
function connect(endpoint = DEFAULT_ENDPOINT) {
|
|
519
546
|
if (isConnected) {
|
|
520
547
|
return Promise.resolve();
|
|
@@ -537,6 +564,7 @@ function connect(endpoint = DEFAULT_ENDPOINT) {
|
|
|
537
564
|
isConnected = true;
|
|
538
565
|
isConnecting = false;
|
|
539
566
|
reconnectAttempts = 0;
|
|
567
|
+
startPingTimer();
|
|
540
568
|
hasResolved = true;
|
|
541
569
|
resolve();
|
|
542
570
|
connectionCallbacks.forEach((cb) => {
|
|
@@ -548,6 +576,7 @@ function connect(endpoint = DEFAULT_ENDPOINT) {
|
|
|
548
576
|
ws.onclose = () => {
|
|
549
577
|
isConnected = false;
|
|
550
578
|
isBlockSubscribed = false;
|
|
579
|
+
stopPingTimer();
|
|
551
580
|
Object.values(pending).forEach((req) => {
|
|
552
581
|
if (req.timeoutId) clearTimeout(req.timeoutId);
|
|
553
582
|
req.reject(new Error("WebSocket connection closed"));
|
|
@@ -730,6 +759,7 @@ async function getCurrentBlockHeight() {
|
|
|
730
759
|
}
|
|
731
760
|
}
|
|
732
761
|
function disconnect() {
|
|
762
|
+
stopPingTimer();
|
|
733
763
|
if (ws) {
|
|
734
764
|
intentionalClose = true;
|
|
735
765
|
ws.close();
|
|
@@ -750,7 +780,7 @@ function disconnect() {
|
|
|
750
780
|
blockSubscribers.length = 0;
|
|
751
781
|
lastBlockHeader = null;
|
|
752
782
|
}
|
|
753
|
-
var DEFAULT_ENDPOINT, ws, isConnected, isConnecting, requestId, intentionalClose, reconnectAttempts, isBlockSubscribed, lastBlockHeader, pending, blockSubscribers, connectionCallbacks, MAX_RECONNECT_ATTEMPTS, BASE_DELAY, MAX_DELAY, RPC_TIMEOUT, CONNECTION_TIMEOUT;
|
|
783
|
+
var DEFAULT_ENDPOINT, ws, isConnected, isConnecting, requestId, intentionalClose, reconnectAttempts, isBlockSubscribed, lastBlockHeader, pingTimer, pending, blockSubscribers, connectionCallbacks, MAX_RECONNECT_ATTEMPTS, BASE_DELAY, MAX_DELAY, RPC_TIMEOUT, CONNECTION_TIMEOUT, PING_INTERVAL;
|
|
754
784
|
var init_network = __esm({
|
|
755
785
|
"l1/network.ts"() {
|
|
756
786
|
"use strict";
|
|
@@ -766,6 +796,7 @@ var init_network = __esm({
|
|
|
766
796
|
reconnectAttempts = 0;
|
|
767
797
|
isBlockSubscribed = false;
|
|
768
798
|
lastBlockHeader = null;
|
|
799
|
+
pingTimer = null;
|
|
769
800
|
pending = {};
|
|
770
801
|
blockSubscribers = [];
|
|
771
802
|
connectionCallbacks = [];
|
|
@@ -774,6 +805,7 @@ var init_network = __esm({
|
|
|
774
805
|
MAX_DELAY = 6e4;
|
|
775
806
|
RPC_TIMEOUT = 3e4;
|
|
776
807
|
CONNECTION_TIMEOUT = 3e4;
|
|
808
|
+
PING_INTERVAL = 3e4;
|
|
777
809
|
}
|
|
778
810
|
});
|
|
779
811
|
|
|
@@ -12112,18 +12144,15 @@ var GroupChatModule = class {
|
|
|
12112
12144
|
}
|
|
12113
12145
|
}
|
|
12114
12146
|
}
|
|
12115
|
-
|
|
12147
|
+
destroy() {
|
|
12116
12148
|
this.destroyConnection();
|
|
12117
12149
|
if (this.persistTimer) {
|
|
12118
12150
|
clearTimeout(this.persistTimer);
|
|
12119
12151
|
this.persistTimer = null;
|
|
12120
|
-
|
|
12121
|
-
|
|
12122
|
-
|
|
12123
|
-
|
|
12124
|
-
await this.doPersistAll();
|
|
12125
|
-
} catch (err) {
|
|
12126
|
-
logger.debug("GroupChat", "Persist on destroy failed", err);
|
|
12152
|
+
if (this.deps) {
|
|
12153
|
+
this.doPersistAll().catch(
|
|
12154
|
+
(err) => logger.debug("GroupChat", "Persist on destroy failed", err)
|
|
12155
|
+
);
|
|
12127
12156
|
}
|
|
12128
12157
|
}
|
|
12129
12158
|
this.groups.clear();
|
|
@@ -13025,15 +13054,9 @@ var GroupChatModule = class {
|
|
|
13025
13054
|
let latest = 0;
|
|
13026
13055
|
for (const gid of groupIds) {
|
|
13027
13056
|
const msgs = this.messages.get(gid);
|
|
13028
|
-
if (msgs)
|
|
13029
|
-
|
|
13030
|
-
|
|
13031
|
-
if (ts > latest) latest = ts;
|
|
13032
|
-
}
|
|
13033
|
-
}
|
|
13034
|
-
const group = this.groups.get(gid);
|
|
13035
|
-
if (group) {
|
|
13036
|
-
const ts = Math.floor((group.updatedAt || group.createdAt) / 1e3);
|
|
13057
|
+
if (!msgs) continue;
|
|
13058
|
+
for (const m of msgs) {
|
|
13059
|
+
const ts = Math.floor(m.timestamp / 1e3);
|
|
13037
13060
|
if (ts > latest) latest = ts;
|
|
13038
13061
|
}
|
|
13039
13062
|
}
|