@pmate/chat-sdk 0.12.0-next.49 → 0.12.0-next.50

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.
@@ -85,6 +85,7 @@ export declare class ChatSession<T extends StoredMessage> {
85
85
  private initializing?;
86
86
  private closing?;
87
87
  constructor(options: ChatSessionOptions<T>);
88
+ private scheduleCatchUp;
88
89
  start(): Promise<void>;
89
90
  /** Initializes local state and background reading sync without opening a
90
91
  * second transport when the host already owns calls/presence. */
@@ -75,10 +75,22 @@ export class ChatSession {
75
75
  this.countTasks = new WindowedTasks(50, error => { if (!this.closed)
76
76
  options.onError(error); });
77
77
  if (typeof window !== "undefined") {
78
- const wake = () => this.wakeCounts();
79
- window.addEventListener("online", wake);
80
- window.addEventListener("focus", wake);
81
- this.off.push(() => { window.removeEventListener("online", wake); window.removeEventListener("focus", wake); });
78
+ const wake = () => {
79
+ if (typeof document !== "undefined" && document.hidden)
80
+ return;
81
+ this.wakeCounts();
82
+ this.scheduleCatchUp();
83
+ };
84
+ for (const type of ["online", "focus", "pageshow"])
85
+ window.addEventListener(type, wake);
86
+ if (typeof document !== "undefined")
87
+ document.addEventListener("visibilitychange", wake);
88
+ this.off.push(() => {
89
+ for (const type of ["online", "focus", "pageshow"])
90
+ window.removeEventListener(type, wake);
91
+ if (typeof document !== "undefined")
92
+ document.removeEventListener("visibilitychange", wake);
93
+ });
82
94
  }
83
95
  this.off.push(this.messages.subscribeAccessRevoked(() => { if (!this.withdrawn && !this.closed)
84
96
  void this.revokeAccess().catch(error => options.onError(error)); }));
@@ -106,15 +118,22 @@ export class ChatSession {
106
118
  this.connectionState = state;
107
119
  this.publishGlobal();
108
120
  if (state === "connected") {
109
- const since = Date.now();
110
- this.catchUp.schedule("scope", async () => { if (this.connectionState === "connected" && !this.closed && !this.withdrawn)
111
- await this.messages.restore(since, options.activeThreadId); });
121
+ this.scheduleCatchUp();
112
122
  if (this.readingStarted)
113
123
  this.reading.refresh();
114
124
  this.wakeCounts();
115
125
  }
116
126
  }));
117
127
  }
128
+ scheduleCatchUp() {
129
+ if (this.connectionState !== "connected" || this.closed || this.withdrawn)
130
+ return;
131
+ const since = Date.now();
132
+ this.catchUp.schedule("scope", async () => {
133
+ if (this.connectionState === "connected" && !this.closed && !this.withdrawn)
134
+ await this.messages.restore(since, this.options.activeThreadId);
135
+ });
136
+ }
118
137
  start() {
119
138
  this.assertOpen();
120
139
  return this.starting ??= (async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/chat-sdk",
3
- "version": "0.12.0-next.49",
3
+ "version": "0.12.0-next.50",
4
4
  "description": "Cross-platform PMate chat input components, voice input primitives, and ASR helpers",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",