@usions/sdk 2.17.0 → 2.18.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 +1 -1
- package/src/browser.js +24 -2
- package/src/modules/core.js +12 -1
- package/src/modules/game-methods.js +11 -0
- package/types/index.d.ts +16 -2
package/package.json
CHANGED
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.18.0', // injected from package.json at build
|
|
73
73
|
config: {},
|
|
74
74
|
_initialized: false,
|
|
75
75
|
_initCallback: null,
|
|
@@ -263,14 +263,25 @@ var Usion = (function () {
|
|
|
263
263
|
* to a specific screen — e.g. when the user taps a notification sent via
|
|
264
264
|
* `Usion.notify.send({ path })`, the app reopens and `getLaunchParams().path`
|
|
265
265
|
* returns that same path so the app can route to it.
|
|
266
|
-
*
|
|
266
|
+
*
|
|
267
|
+
* `mode` is how the app was launched: `'single'` (opened from Explore / the
|
|
268
|
+
* Game hub, played solo) or `'multiplayer'` (opened from a game invite in a
|
|
269
|
+
* chat, played with another person). The host declares it authoritatively;
|
|
270
|
+
* branch on it to skip lobby/matchmaking UI in single-player or wire up
|
|
271
|
+
* netcode in multiplayer. When the host doesn't declare a mode (legacy hosts
|
|
272
|
+
* or a standalone URL), it falls back to "a room means multiplayer".
|
|
273
|
+
* @returns {{ path: string|null, ref: string|null, roomId: string|null, mode: 'single'|'multiplayer' }}
|
|
267
274
|
*/
|
|
268
275
|
getLaunchParams: function() {
|
|
269
276
|
var c = this.config || {};
|
|
277
|
+
var mode = (c.mode === 'single' || c.mode === 'multiplayer')
|
|
278
|
+
? c.mode
|
|
279
|
+
: (c.roomId ? 'multiplayer' : 'single');
|
|
270
280
|
return {
|
|
271
281
|
path: c.launchPath || null,
|
|
272
282
|
ref: c.ref || c.launchRef || null,
|
|
273
283
|
roomId: c.roomId || null,
|
|
284
|
+
mode: mode,
|
|
274
285
|
};
|
|
275
286
|
},
|
|
276
287
|
|
|
@@ -2507,6 +2518,17 @@ var Usion = (function () {
|
|
|
2507
2518
|
} catch (e) { /* non-fatal */ }
|
|
2508
2519
|
};
|
|
2509
2520
|
|
|
2521
|
+
/**
|
|
2522
|
+
* Whether this app was launched in multiplayer mode (opened from a game
|
|
2523
|
+
* invite in a chat) rather than single-player (opened from Explore / the
|
|
2524
|
+
* Game hub). Convenience wrapper over Usion.getLaunchParams().mode — use it
|
|
2525
|
+
* to branch setup, e.g. skip matchmaking and run solo when false.
|
|
2526
|
+
* @returns {boolean}
|
|
2527
|
+
*/
|
|
2528
|
+
game.isMultiplayer = function() {
|
|
2529
|
+
return Usion.getLaunchParams().mode === 'multiplayer';
|
|
2530
|
+
};
|
|
2531
|
+
|
|
2510
2532
|
/**
|
|
2511
2533
|
* Get connection status
|
|
2512
2534
|
* @returns {boolean}
|
package/src/modules/core.js
CHANGED
|
@@ -260,14 +260,25 @@ export const core = {
|
|
|
260
260
|
* to a specific screen — e.g. when the user taps a notification sent via
|
|
261
261
|
* `Usion.notify.send({ path })`, the app reopens and `getLaunchParams().path`
|
|
262
262
|
* returns that same path so the app can route to it.
|
|
263
|
-
*
|
|
263
|
+
*
|
|
264
|
+
* `mode` is how the app was launched: `'single'` (opened from Explore / the
|
|
265
|
+
* Game hub, played solo) or `'multiplayer'` (opened from a game invite in a
|
|
266
|
+
* chat, played with another person). The host declares it authoritatively;
|
|
267
|
+
* branch on it to skip lobby/matchmaking UI in single-player or wire up
|
|
268
|
+
* netcode in multiplayer. When the host doesn't declare a mode (legacy hosts
|
|
269
|
+
* or a standalone URL), it falls back to "a room means multiplayer".
|
|
270
|
+
* @returns {{ path: string|null, ref: string|null, roomId: string|null, mode: 'single'|'multiplayer' }}
|
|
264
271
|
*/
|
|
265
272
|
getLaunchParams: function() {
|
|
266
273
|
var c = this.config || {};
|
|
274
|
+
var mode = (c.mode === 'single' || c.mode === 'multiplayer')
|
|
275
|
+
? c.mode
|
|
276
|
+
: (c.roomId ? 'multiplayer' : 'single');
|
|
267
277
|
return {
|
|
268
278
|
path: c.launchPath || null,
|
|
269
279
|
ref: c.ref || c.launchRef || null,
|
|
270
280
|
roomId: c.roomId || null,
|
|
281
|
+
mode: mode,
|
|
271
282
|
};
|
|
272
283
|
},
|
|
273
284
|
|
|
@@ -567,6 +567,17 @@ export function applyGameMethods(game, Usion) {
|
|
|
567
567
|
} catch (e) { /* non-fatal */ }
|
|
568
568
|
};
|
|
569
569
|
|
|
570
|
+
/**
|
|
571
|
+
* Whether this app was launched in multiplayer mode (opened from a game
|
|
572
|
+
* invite in a chat) rather than single-player (opened from Explore / the
|
|
573
|
+
* Game hub). Convenience wrapper over Usion.getLaunchParams().mode — use it
|
|
574
|
+
* to branch setup, e.g. skip matchmaking and run solo when false.
|
|
575
|
+
* @returns {boolean}
|
|
576
|
+
*/
|
|
577
|
+
game.isMultiplayer = function() {
|
|
578
|
+
return Usion.getLaunchParams().mode === 'multiplayer';
|
|
579
|
+
};
|
|
580
|
+
|
|
570
581
|
/**
|
|
571
582
|
* Get connection status
|
|
572
583
|
* @returns {boolean}
|
package/types/index.d.ts
CHANGED
|
@@ -31,6 +31,12 @@ export interface UsionConfig {
|
|
|
31
31
|
launchPath?: string;
|
|
32
32
|
/** Referral code the app was opened with, if any. */
|
|
33
33
|
ref?: string;
|
|
34
|
+
/**
|
|
35
|
+
* How the app was launched: `'single'` (from Explore / the Game hub, solo)
|
|
36
|
+
* or `'multiplayer'` (from a game invite in a chat). Read via
|
|
37
|
+
* `Usion.getLaunchParams().mode`. (SDK ≥ 2.18)
|
|
38
|
+
*/
|
|
39
|
+
mode?: 'single' | 'multiplayer';
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
// ─── Payment ─────────────────────────────────────────────────────
|
|
@@ -256,6 +262,12 @@ export interface GameModule {
|
|
|
256
262
|
connectDirect(config?: DirectConnectionConfig): Promise<void>;
|
|
257
263
|
disconnect(): void;
|
|
258
264
|
isConnected(): boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Whether the app was launched multiplayer (from a chat game invite) vs
|
|
267
|
+
* single-player (from Explore / the Game hub). Wrapper over
|
|
268
|
+
* `Usion.getLaunchParams().mode === 'multiplayer'`. (SDK ≥ 2.18)
|
|
269
|
+
*/
|
|
270
|
+
isMultiplayer(): boolean;
|
|
259
271
|
|
|
260
272
|
// Room & actions
|
|
261
273
|
//
|
|
@@ -774,9 +786,11 @@ export interface UsionSDK {
|
|
|
774
786
|
/**
|
|
775
787
|
* Launch parameters the host opened this app with. `path` is the deep-link
|
|
776
788
|
* target (e.g. from a tapped `Usion.notify` notification); route to it after
|
|
777
|
-
* init so the user lands on the right screen.
|
|
789
|
+
* init so the user lands on the right screen. `mode` is `'single'` (opened
|
|
790
|
+
* from Explore / the Game hub, solo) or `'multiplayer'` (opened from a game
|
|
791
|
+
* invite in a chat) — branch game setup on it. (mode: SDK ≥ 2.18)
|
|
778
792
|
*/
|
|
779
|
-
getLaunchParams(): { path: string | null; ref: string | null; roomId: string | null };
|
|
793
|
+
getLaunchParams(): { path: string | null; ref: string | null; roomId: string | null; mode: 'single' | 'multiplayer' };
|
|
780
794
|
|
|
781
795
|
// Payments
|
|
782
796
|
requestPayment(amount: number, reason: string, data?: PaymentOptions): Promise<PaymentResponse>;
|