@usions/sdk 2.14.0 → 2.16.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.
- package/package.json +2 -2
- package/src/browser.js +47 -1
- package/src/modules/core.js +46 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usions/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.0",
|
|
4
4
|
"description": "Usion Mini App SDK for iframe games and services",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/modules/index.js",
|
|
@@ -60,4 +60,4 @@
|
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|
|
62
62
|
}
|
|
63
|
-
}
|
|
63
|
+
}
|
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.
|
|
72
|
+
version: '2.16.0', // injected from package.json at build
|
|
73
73
|
config: {},
|
|
74
74
|
_initialized: false,
|
|
75
75
|
_initCallback: null,
|
|
@@ -192,10 +192,56 @@ var Usion = (function () {
|
|
|
192
192
|
}
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
+
// Report the user's first real interaction to the host (see below).
|
|
196
|
+
this._setupInteractionBeacon();
|
|
197
|
+
|
|
195
198
|
// Signal ready to parent
|
|
196
199
|
this._post({ type: 'READY' });
|
|
197
200
|
},
|
|
198
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Tell the host the moment the user FIRST genuinely interacts with the
|
|
204
|
+
* mini-app — a tap, click, key press, or touch — and only once.
|
|
205
|
+
*
|
|
206
|
+
* The host uses this as the SOLE signal to surface the mini-app in the user's
|
|
207
|
+
* chat list — only after real engagement (opening alone, and automatic
|
|
208
|
+
* load-time SDK calls, never count). It works for a fully self-contained
|
|
209
|
+
* app/game that never calls any other SDK method: no `Usion.*` call is
|
|
210
|
+
* required for the host to know the user is engaged.
|
|
211
|
+
*
|
|
212
|
+
* Standalone (non-embedded) apps are unaffected — `_post` no-ops when there
|
|
213
|
+
* is no host. Note: input that produces no DOM gesture (pure device-motion,
|
|
214
|
+
* gamepad) won't trigger this until the first tap/click/key.
|
|
215
|
+
* @private
|
|
216
|
+
*/
|
|
217
|
+
_setupInteractionBeacon: function() {
|
|
218
|
+
const self = this;
|
|
219
|
+
if (self._interactionBeaconSetup) return;
|
|
220
|
+
self._interactionBeaconSetup = true;
|
|
221
|
+
if (typeof window === 'undefined' || !window.addEventListener) return;
|
|
222
|
+
|
|
223
|
+
const events = ['pointerdown', 'mousedown', 'touchstart', 'keydown'];
|
|
224
|
+
function fire(event) {
|
|
225
|
+
// Only count real user gestures, never programmatically dispatched ones.
|
|
226
|
+
if (event && event.isTrusted === false) return;
|
|
227
|
+
if (self._interactionReported) return;
|
|
228
|
+
self._interactionReported = true;
|
|
229
|
+
for (let i = 0; i < events.length; i++) {
|
|
230
|
+
try { window.removeEventListener(events[i], fire, true); } catch (e) { /* noop */ }
|
|
231
|
+
}
|
|
232
|
+
self._post({ type: 'USER_INTERACTION' });
|
|
233
|
+
}
|
|
234
|
+
for (let i = 0; i < events.length; i++) {
|
|
235
|
+
// Capture phase + passive so we observe the gesture without interfering
|
|
236
|
+
// with the app's own handlers or scroll performance.
|
|
237
|
+
try {
|
|
238
|
+
window.addEventListener(events[i], fire, { capture: true, passive: true });
|
|
239
|
+
} catch (e) {
|
|
240
|
+
try { window.addEventListener(events[i], fire, true); } catch (e2) { /* noop */ }
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
|
|
199
245
|
/**
|
|
200
246
|
* Get the current theme ('light' or 'dark')
|
|
201
247
|
* @returns {string}
|
package/src/modules/core.js
CHANGED
|
@@ -189,10 +189,56 @@ export const core = {
|
|
|
189
189
|
}
|
|
190
190
|
});
|
|
191
191
|
|
|
192
|
+
// Report the user's first real interaction to the host (see below).
|
|
193
|
+
this._setupInteractionBeacon();
|
|
194
|
+
|
|
192
195
|
// Signal ready to parent
|
|
193
196
|
this._post({ type: 'READY' });
|
|
194
197
|
},
|
|
195
198
|
|
|
199
|
+
/**
|
|
200
|
+
* Tell the host the moment the user FIRST genuinely interacts with the
|
|
201
|
+
* mini-app — a tap, click, key press, or touch — and only once.
|
|
202
|
+
*
|
|
203
|
+
* The host uses this as the SOLE signal to surface the mini-app in the user's
|
|
204
|
+
* chat list — only after real engagement (opening alone, and automatic
|
|
205
|
+
* load-time SDK calls, never count). It works for a fully self-contained
|
|
206
|
+
* app/game that never calls any other SDK method: no `Usion.*` call is
|
|
207
|
+
* required for the host to know the user is engaged.
|
|
208
|
+
*
|
|
209
|
+
* Standalone (non-embedded) apps are unaffected — `_post` no-ops when there
|
|
210
|
+
* is no host. Note: input that produces no DOM gesture (pure device-motion,
|
|
211
|
+
* gamepad) won't trigger this until the first tap/click/key.
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
214
|
+
_setupInteractionBeacon: function() {
|
|
215
|
+
const self = this;
|
|
216
|
+
if (self._interactionBeaconSetup) return;
|
|
217
|
+
self._interactionBeaconSetup = true;
|
|
218
|
+
if (typeof window === 'undefined' || !window.addEventListener) return;
|
|
219
|
+
|
|
220
|
+
const events = ['pointerdown', 'mousedown', 'touchstart', 'keydown'];
|
|
221
|
+
function fire(event) {
|
|
222
|
+
// Only count real user gestures, never programmatically dispatched ones.
|
|
223
|
+
if (event && event.isTrusted === false) return;
|
|
224
|
+
if (self._interactionReported) return;
|
|
225
|
+
self._interactionReported = true;
|
|
226
|
+
for (let i = 0; i < events.length; i++) {
|
|
227
|
+
try { window.removeEventListener(events[i], fire, true); } catch (e) { /* noop */ }
|
|
228
|
+
}
|
|
229
|
+
self._post({ type: 'USER_INTERACTION' });
|
|
230
|
+
}
|
|
231
|
+
for (let i = 0; i < events.length; i++) {
|
|
232
|
+
// Capture phase + passive so we observe the gesture without interfering
|
|
233
|
+
// with the app's own handlers or scroll performance.
|
|
234
|
+
try {
|
|
235
|
+
window.addEventListener(events[i], fire, { capture: true, passive: true });
|
|
236
|
+
} catch (e) {
|
|
237
|
+
try { window.addEventListener(events[i], fire, true); } catch (e2) { /* noop */ }
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
|
|
196
242
|
/**
|
|
197
243
|
* Get the current theme ('light' or 'dark')
|
|
198
244
|
* @returns {string}
|