@pmate/chat-sdk 0.12.0-next.15 → 0.12.0-next.16
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/lib/runtime/chatSession.js +13 -2
- package/package.json +1 -1
|
@@ -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); });
|
package/package.json
CHANGED