@pmate/chat-sdk 0.12.0-next.15 → 0.12.0-next.17
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.
|
@@ -45,7 +45,14 @@ export class ChatSession {
|
|
|
45
45
|
throw new Error("CHAT_SESSION_SCOPE_MISMATCH");
|
|
46
46
|
}
|
|
47
47
|
this.messages = new MessageClient(options.messages);
|
|
48
|
-
this.connection = options.sharedConnection ?? new ChatClient(options.connection)
|
|
48
|
+
this.connection = options.sharedConnection ?? new ChatClient({ ...options.connection, onReach: async (event) => {
|
|
49
|
+
const handled = await this.handleReach(event);
|
|
50
|
+
if (handled)
|
|
51
|
+
return handled;
|
|
52
|
+
if (options.connection.onReach)
|
|
53
|
+
return options.connection.onReach(event);
|
|
54
|
+
throw new Error("REACH_HANDLER_UNAVAILABLE");
|
|
55
|
+
} });
|
|
49
56
|
this.reading = new ReadingClient({ ...options.reading, storageScope: JSON.stringify([scope.accountId]), migrateLegacy: true });
|
|
50
57
|
this.readers = new MessageReadersClient({ appId: scope.appId, profileId: scope.profileId, token: options.reading.sessionToken, scope, onError: options.onError, hubHttpUrl: options.reading.hubHttpUrl, fetch: options.reading.fetch });
|
|
51
58
|
this.sender = new DurableChatSender(this.connection, scope, options.onError);
|
|
@@ -65,7 +72,11 @@ export class ChatSession {
|
|
|
65
72
|
try {
|
|
66
73
|
const decoded = options.decode(message);
|
|
67
74
|
if (decoded)
|
|
68
|
-
void this.messages.receive(decoded.threadId, [decoded]).then(
|
|
75
|
+
void this.messages.receive(decoded.threadId, [decoded]).then(async () => {
|
|
76
|
+
if (!this.closed && this.readingStarted)
|
|
77
|
+
this.reading.refresh();
|
|
78
|
+
await this.sender.confirm([message.hash]);
|
|
79
|
+
}).catch(error => { if (String(error).includes("MESSAGE_PROJECTION_CHANGED"))
|
|
69
80
|
this.messages.invalidate(decoded.threadId);
|
|
70
81
|
else if (!this.closed)
|
|
71
82
|
options.onError(error); });
|
|
@@ -74,8 +74,11 @@ export class ReadCountsClient {
|
|
|
74
74
|
this.heartbeat = setInterval(() => { if (!this.closed && this.thread === threadId)
|
|
75
75
|
this.renew(); }, 20_000);
|
|
76
76
|
// Recover changes that occurred before a receiver/subscription became ready.
|
|
77
|
-
if (recovered
|
|
77
|
+
if (recovered) {
|
|
78
|
+
// A fresh cache predates the new lease and cannot cover its delivery gap.
|
|
79
|
+
this.force = true;
|
|
78
80
|
this.schedule(0);
|
|
81
|
+
}
|
|
79
82
|
}).catch(error => {
|
|
80
83
|
if (this.closed || generation !== this.generation)
|
|
81
84
|
return;
|
package/package.json
CHANGED