@umicat/platform-sdk 0.4.0 → 0.5.0

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.
@@ -26,6 +26,8 @@ export declare class PostMessageTransport implements Transport {
26
26
  * longer to boot. One-shot hello was losing the handshake on Android.
27
27
  */
28
28
  static connect(timeoutMs?: number, sdkVersion?: string, helloRetryMs?: number): Promise<PostMessageTransport | null>;
29
+ /** The most recent host push of each type, for subscribers that arrive late. */
30
+ private readonly lastEvent;
29
31
  private installResultListener;
30
32
  on(event: string, handler: (payload: unknown) => void): () => void;
31
33
  call<T = unknown>(method: string, params?: unknown, timeoutMs?: number): Promise<T>;
@@ -14,6 +14,8 @@ export class PostMessageTransport {
14
14
  this.pending = new Map();
15
15
  this.seq = 0;
16
16
  this.eventHandlers = new Map();
17
+ /** The most recent host push of each type, for subscribers that arrive late. */
18
+ this.lastEvent = new Map();
17
19
  }
18
20
  /**
19
21
  * Perform the handshake. Resolves once parent has replied with `umicat:init`.
@@ -95,6 +97,17 @@ export class PostMessageTransport {
95
97
  return;
96
98
  }
97
99
  // Host-pushed event stream (e.g. 'umicat:voice') → registered handlers.
100
+ //
101
+ // Remembered as well as delivered. A host pushes STATE as soon as the
102
+ // handshake completes, and the modules that want it are constructed after
103
+ // `connect()` returns — so the first push of a fold arrived with nobody
104
+ // listening and was never repeated. The symptom is a game laid out for one
105
+ // screen on a device that is already folded, which then fixes itself the
106
+ // moment anything moves.
107
+ //
108
+ // Only the LAST of each type: this is for state, and a replayed queue of
109
+ // old transcript fragments would be worse than dropping them.
110
+ this.lastEvent.set(data.type, data);
98
111
  const handlers = this.eventHandlers.get(data.type);
99
112
  if (handlers)
100
113
  for (const handler of handlers)
@@ -108,6 +121,10 @@ export class PostMessageTransport {
108
121
  this.eventHandlers.set(event, handlers);
109
122
  }
110
123
  handlers.add(handler);
124
+ // Catch up, if this type already arrived before anyone subscribed.
125
+ const last = this.lastEvent.get(event);
126
+ if (last !== undefined)
127
+ handler(last);
111
128
  return () => { handlers.delete(handler); };
112
129
  }
113
130
  call(method, params, timeoutMs = 10000) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umicat/platform-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Umicat's platform layer, independent of any rendering engine: identity, cloud saves, shared game data, multiplayer, runtime AI, voice and scripted dialogue. Consumed by @umicat/phaser-sdk and @umicat/three-sdk alike.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",