@usions/sdk 2.20.0 → 2.20.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usions/sdk",
3
- "version": "2.20.0",
3
+ "version": "2.20.1",
4
4
  "description": "Usion Mini App SDK for iframe games and services",
5
5
  "type": "module",
6
6
  "main": "src/modules/index.js",
package/src/browser.js CHANGED
@@ -69,7 +69,7 @@ var Usion = (function () {
69
69
  * Core Usion object with init, _post, _request
70
70
  */
71
71
  const core = {
72
- version: '2.20.0', // injected from package.json at build
72
+ version: '2.20.1', // injected from package.json at build
73
73
  config: {},
74
74
  _initialized: false,
75
75
  _initCallback: null,
@@ -4851,6 +4851,24 @@ var Usion = (function () {
4851
4851
  applyGameMethods(game, Usion);
4852
4852
  applyGameNetcode(game, Usion);
4853
4853
 
4854
+ // Foreground catch-up safety net (generic across every transport).
4855
+ //
4856
+ // When a page/iframe is backgrounded its JS is suspended: timers freeze and
4857
+ // relayed actions can be missed (postMessage to a frozen WebView). A brief
4858
+ // app-switch may also never trip a socket disconnect/reconnect, so the game's
4859
+ // onReconnect handler never fires and it silently misses moves made while it
4860
+ // was away — leaving turn state behind and the table deadlocked. On every
4861
+ // return to visibility, if we're in a room, request a sync so the game
4862
+ // deterministically catches up. Per the action reliability contract, onSync
4863
+ // is deduped by sequence, so an unnecessary resync is a no-op.
4864
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
4865
+ document.addEventListener('visibilitychange', function() {
4866
+ if (document.visibilityState !== 'visible') return;
4867
+ if (!game.roomId) return;
4868
+ try { game.requestSync(); } catch (e) { /* non-fatal */ }
4869
+ });
4870
+ }
4871
+
4854
4872
  return game;
4855
4873
  }
4856
4874
 
@@ -242,5 +242,23 @@ export function createGameModule(Usion) {
242
242
  applyGameMethods(game, Usion);
243
243
  applyGameNetcode(game, Usion);
244
244
 
245
+ // Foreground catch-up safety net (generic across every transport).
246
+ //
247
+ // When a page/iframe is backgrounded its JS is suspended: timers freeze and
248
+ // relayed actions can be missed (postMessage to a frozen WebView). A brief
249
+ // app-switch may also never trip a socket disconnect/reconnect, so the game's
250
+ // onReconnect handler never fires and it silently misses moves made while it
251
+ // was away — leaving turn state behind and the table deadlocked. On every
252
+ // return to visibility, if we're in a room, request a sync so the game
253
+ // deterministically catches up. Per the action reliability contract, onSync
254
+ // is deduped by sequence, so an unnecessary resync is a no-op.
255
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
256
+ document.addEventListener('visibilitychange', function() {
257
+ if (document.visibilityState !== 'visible') return;
258
+ if (!game.roomId) return;
259
+ try { game.requestSync(); } catch (e) { /* non-fatal */ }
260
+ });
261
+ }
262
+
245
263
  return game;
246
264
  }