@usions/sdk 2.32.0 → 2.34.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/README.md +52 -0
- package/package.json +6 -3
- package/src/browser.js +2 -2
- package/src/modules/app-links.js +295 -0
- package/src/modules/call.js +46 -0
- package/src/modules/cloud.js +28 -0
- package/src/modules/core.js +5 -1
- package/src/modules/errors.js +1 -0
- package/src/modules/game-core.js +4 -0
- package/src/modules/game-methods.js +12 -1
- package/src/modules/game-participants.js +28 -0
- package/src/modules/game-players.js +609 -0
- package/src/modules/game-reliability.js +3 -170
- package/src/modules/game-synced-state.js +208 -0
- package/src/modules/index.js +6 -0
- package/src/modules/misc.js +0 -16
- package/src/modules/profile.js +37 -0
- package/src/modules/user.js +12 -0
- package/types/index.d.ts +239 -6
package/types/index.d.ts
CHANGED
|
@@ -43,6 +43,11 @@ export interface UsionConfig {
|
|
|
43
43
|
* `Usion.screen.support()`, which treats absent as all-false. (SDK ≥ 2.31)
|
|
44
44
|
*/
|
|
45
45
|
screenCapture?: ScreenCaptureSupport;
|
|
46
|
+
/**
|
|
47
|
+
* Host capabilities declared in INIT. Absent on older app builds — read
|
|
48
|
+
* `feedShare` via `Usion.canShareToFeed()`. (SDK ≥ 2.33)
|
|
49
|
+
*/
|
|
50
|
+
hostFeatures?: { feedShare?: boolean; feedShareImage?: boolean; feedShareVideo?: boolean; [feature: string]: boolean | undefined };
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
// ─── Payment ─────────────────────────────────────────────────────
|
|
@@ -94,6 +99,12 @@ export interface UserModule {
|
|
|
94
99
|
*/
|
|
95
100
|
isAdult(): boolean | null;
|
|
96
101
|
getProfile(): Promise<UserProfile>;
|
|
102
|
+
/**
|
|
103
|
+
* Open another player's Usion profile (SDK ≥ 2.33) — e.g. when a leaderboard
|
|
104
|
+
* row is tapped. The host shows it over the app, which keeps running; back
|
|
105
|
+
* returns to it. Fire-and-forget; a no-op outside the host or for guest ids.
|
|
106
|
+
*/
|
|
107
|
+
openProfile(userId: string): void;
|
|
97
108
|
}
|
|
98
109
|
|
|
99
110
|
// ─── Storage ─────────────────────────────────────────────────────
|
|
@@ -163,6 +174,52 @@ export interface ShareMediaItem {
|
|
|
163
174
|
duration?: number;
|
|
164
175
|
}
|
|
165
176
|
|
|
177
|
+
/** Input for `Usion.shareToFeed`. */
|
|
178
|
+
export interface ShareToFeedData {
|
|
179
|
+
/** The post's text (required, non-empty). */
|
|
180
|
+
text: string;
|
|
181
|
+
/** Relative in-app path readers open, e.g. `/q/57`. */
|
|
182
|
+
path?: string;
|
|
183
|
+
/** Idempotency key (UUID). Generated when omitted. */
|
|
184
|
+
requestId?: string;
|
|
185
|
+
/**
|
|
186
|
+
* The thing being shared (e.g. the question), shown on the feed as a
|
|
187
|
+
* tappable card that opens `path`; `text` is the user's caption. (SDK ≥ 2.33.0-dev.6)
|
|
188
|
+
*/
|
|
189
|
+
card?: ShareToFeedCard;
|
|
190
|
+
/**
|
|
191
|
+
* The card as a picture (e.g. a rendered question card):
|
|
192
|
+
* `data:image/(png|jpeg|webp);base64,…`, decoded ≤ 5 MB. Send only when
|
|
193
|
+
* `Usion.canShareToFeed('image')` is true (older hosts drop it), and keep
|
|
194
|
+
* `card` alongside as its text/alt. (SDK ≥ 2.33.0-dev.7)
|
|
195
|
+
*/
|
|
196
|
+
image?: string;
|
|
197
|
+
/** MP4 base64 data URL, at most 5 MB decoded; requires canShareToFeed('video'). */
|
|
198
|
+
video?: string;
|
|
199
|
+
/** Signed receipt returned by uploadFeedVideo (3 GiB maximum). */
|
|
200
|
+
videoReceipt?: string;
|
|
201
|
+
/** @deprecated Ignored by current hosts. */
|
|
202
|
+
media?: Array<{ type: 'image' | 'video' | 'audio'; url: string; thumbnailUrl?: string; width?: number; height?: number; duration?: number }>;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** The shared item shown as a card on a feed post. Both fields are trimmed. */
|
|
206
|
+
export interface ShareToFeedCard {
|
|
207
|
+
/** 1–200 Unicode code points. */
|
|
208
|
+
title: string;
|
|
209
|
+
/** Up to 60 Unicode code points; omitted when empty. */
|
|
210
|
+
subtitle?: string;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Result of a confirmed `Usion.shareToFeed`. */
|
|
214
|
+
export interface ShareToFeedResult {
|
|
215
|
+
success: true;
|
|
216
|
+
/** Id of the created (or, on a retry, the existing) post. */
|
|
217
|
+
postId: string;
|
|
218
|
+
/** Legacy hosts may also return a share URL. */
|
|
219
|
+
shareUrl?: string;
|
|
220
|
+
[key: string]: unknown;
|
|
221
|
+
}
|
|
222
|
+
|
|
166
223
|
export interface ShareData {
|
|
167
224
|
text?: string;
|
|
168
225
|
message?: string;
|
|
@@ -404,7 +461,10 @@ export interface MatchResult {
|
|
|
404
461
|
* Finishing order for a 3+ player match, BEST FIRST — how the card ranks
|
|
405
462
|
* everyone. Pass it whenever there is a ranking: it cannot be derived from
|
|
406
463
|
* `scores`, since a high score wins in some games and a low one wins in
|
|
407
|
-
* others. Ids not in the room are ignored;
|
|
464
|
+
* others. Ids not in the room are ignored; scored players and the winner
|
|
465
|
+
* omitted from the order are appended. When scores or standings are supplied,
|
|
466
|
+
* include every actual participant in either field; other room members do
|
|
467
|
+
* not receive match cards. Without either field, the room roster is used.
|
|
408
468
|
* Omit for 1-on-1. (SDK ≥ 2.27)
|
|
409
469
|
*/
|
|
410
470
|
standings?: Array<string | { userId: string }>;
|
|
@@ -489,7 +549,27 @@ export interface SyncedState<S = Record<string, any>> {
|
|
|
489
549
|
destroy(): void;
|
|
490
550
|
}
|
|
491
551
|
|
|
552
|
+
export interface GameParticipant {
|
|
553
|
+
id: string;
|
|
554
|
+
name: string;
|
|
555
|
+
avatar: string | null;
|
|
556
|
+
joined: boolean;
|
|
557
|
+
connected: boolean;
|
|
558
|
+
}
|
|
559
|
+
export interface GameParticipantsResult {
|
|
560
|
+
roomId: string;
|
|
561
|
+
hostId: string;
|
|
562
|
+
source: 'room' | 'group';
|
|
563
|
+
participants: GameParticipant[];
|
|
564
|
+
}
|
|
492
565
|
export interface GameModule {
|
|
566
|
+
/** Minimal profiles for the joined room and its authorized source group. */
|
|
567
|
+
getParticipants(): Promise<GameParticipantsResult>;
|
|
568
|
+
|
|
569
|
+
/** Join the current room and manage WebRTC with platform relay fallback.
|
|
570
|
+
* Resolves before peers connect; without a room, waits for an app invite.
|
|
571
|
+
* One active connection per game. Platform mode, up to 8 players, JSON only. */
|
|
572
|
+
connectPlayers(options?: ConnectPlayersOptions): Promise<PlayersConnection>;
|
|
493
573
|
// Connection
|
|
494
574
|
connect(socketUrl?: string, token?: string): Promise<void>;
|
|
495
575
|
connectDirect(config?: DirectConnectionConfig): Promise<void>;
|
|
@@ -1142,7 +1222,22 @@ export interface SelectionGrid {
|
|
|
1142
1222
|
|
|
1143
1223
|
// ─── Main SDK ────────────────────────────────────────────────────
|
|
1144
1224
|
|
|
1225
|
+
/** Local derived signals, available only while the user permits this mini-app. */
|
|
1226
|
+
export type CallAnalysisCapability = 'headPosition' | 'voiceActivity';
|
|
1227
|
+
export type CallAnalysisSample =
|
|
1228
|
+
| { kind: 'face'; detected: boolean; x: number; y: number }
|
|
1229
|
+
| { kind: 'voice'; speaking: boolean };
|
|
1230
|
+
export interface CallModule {
|
|
1231
|
+
capabilities(): Promise<{ capabilities: CallAnalysisCapability[]; connected: boolean }>;
|
|
1232
|
+
startAnalysis(options: {
|
|
1233
|
+
capabilities: CallAnalysisCapability[];
|
|
1234
|
+
onSample: (sample: CallAnalysisSample) => void;
|
|
1235
|
+
onStopped?: () => void;
|
|
1236
|
+
}): Promise<{ stop(): Promise<void> }>;
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1145
1239
|
export interface UsionSDK {
|
|
1240
|
+
call: CallModule;
|
|
1146
1241
|
version: string;
|
|
1147
1242
|
config: UsionConfig;
|
|
1148
1243
|
|
|
@@ -1218,10 +1313,55 @@ export interface UsionSDK {
|
|
|
1218
1313
|
share(contentType: 'audio' | 'image' | 'video' | 'text' | 'mixed', data: ShareData): void;
|
|
1219
1314
|
shareFile(url: string, options?: ShareFileOptions): Promise<FileTransferResult>;
|
|
1220
1315
|
shareToStory(url: string, options?: StoryShareOptions): Promise<FileTransferResult>;
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1316
|
+
/**
|
|
1317
|
+
* `true` only when the host declared `hostFeatures.feedShare` in its INIT
|
|
1318
|
+
* config, i.e. it can show the confirm sheet and post. `false` outside a host
|
|
1319
|
+
* and on older app builds. Show your "Share to feed" button only when this is
|
|
1320
|
+
* true. `canShareToFeed('image')` additionally requires
|
|
1321
|
+
* `hostFeatures.feedShareImage` — send `image` only when it is true (older
|
|
1322
|
+
* hosts drop it). `'video'` requires `feedShareVideo` (SDK ≥ 2.33.0-dev.9).
|
|
1323
|
+
*/
|
|
1324
|
+
canShareToFeed(feature?: 'image' | 'video' | 'videoUpload'): boolean;
|
|
1325
|
+
/** Upload a supported video (up to 3 GiB); pass its receipt to shareToFeed.
|
|
1326
|
+
* Keep requestId to resume the same file after an interruption. */
|
|
1327
|
+
uploadFeedVideo(file: Blob, options?: { requestId?: string; signal?: AbortSignal; onProgress?: (progress: { loaded: number; total: number }) => void }): Promise<{ receipt: string }>;
|
|
1328
|
+
/**
|
|
1329
|
+
* Post a short text to the signed-in user's Usions News Feed (it also shows
|
|
1330
|
+
* on their profile), stamped with this app and an optional in-app `path`.
|
|
1331
|
+
* Readers see a chip with this app's real icon and name; tapping it opens
|
|
1332
|
+
* this app at `path` (read it via `getLaunchParams().path` / `onHostNavigate`).
|
|
1333
|
+
*
|
|
1334
|
+
* - The host shows a confirm sheet EVERY time — never silent, never a stored grant.
|
|
1335
|
+
* - Public (listed) apps only; text ≤ 1000 characters, with an optional image or MP4 video.
|
|
1336
|
+
* - One call = at most one post: `requestId` is generated when omitted, so a
|
|
1337
|
+
* retry of the same call never duplicates. Pass your own to dedupe retries
|
|
1338
|
+
* across calls.
|
|
1339
|
+
* - `card` (optional): the item being shared, shown as a tappable card; the
|
|
1340
|
+
* post mentions your app automatically.
|
|
1341
|
+
* - Limits: 5 per minute and 30 per day per user per app.
|
|
1342
|
+
*
|
|
1343
|
+
* Rejects with a `UsionError` whose `code` is `CANCELLED` (the user declined),
|
|
1344
|
+
* `RATE_LIMITED`, `NOT_AUTHENTICATED` (guest), `PERMISSION_DENIED` (app not
|
|
1345
|
+
* public), `INVALID_INPUT` (empty text / bad path / bad card / bad image — checked locally before the
|
|
1346
|
+
* host is asked), `REQUEST_TIMEOUT` or `UNKNOWN`. (SDK ≥ 2.33)
|
|
1347
|
+
*
|
|
1348
|
+
* @param contentType Pass `'video'` for a video, otherwise `'text'`.
|
|
1349
|
+
*/
|
|
1350
|
+
shareToFeed(contentType: 'text' | 'image' | 'video' | 'audio' | 'mixed', data: ShareToFeedData): Promise<ShareToFeedResult>;
|
|
1351
|
+
/**
|
|
1352
|
+
* Open another Usion app — or this one — at an optional in-app path (the
|
|
1353
|
+
* same address a feed post or notification carries). The host checks the
|
|
1354
|
+
* app exists and the user may open it; opening yourself navigates in place
|
|
1355
|
+
* (delivered through `onHostNavigate`). Fire-and-forget; a no-op on hosts
|
|
1356
|
+
* that predate it.
|
|
1357
|
+
*
|
|
1358
|
+
* @param serviceId Target app's service id.
|
|
1359
|
+
* @param path Relative in-app path starting with a single `/` (≤ 512 chars,
|
|
1360
|
+
* no `//`, `://`, spaces, backslashes or control characters).
|
|
1361
|
+
* @throws UsionError `INVALID_INPUT` synchronously for an empty `serviceId` or a bad `path`.
|
|
1362
|
+
* (SDK ≥ 2.33)
|
|
1363
|
+
*/
|
|
1364
|
+
openApp(serviceId: string, path?: string): void;
|
|
1225
1365
|
|
|
1226
1366
|
// Logging
|
|
1227
1367
|
log(msg: string): void;
|
|
@@ -1278,6 +1418,8 @@ export interface UsionSDK {
|
|
|
1278
1418
|
notify: NotifyModule;
|
|
1279
1419
|
permissions: PermissionsModule;
|
|
1280
1420
|
screen: UsionScreen;
|
|
1421
|
+
/** Consent-gated native cards in this app's category on the current user's profile. */
|
|
1422
|
+
profile: ProfileModule;
|
|
1281
1423
|
netcode: NetcodeModule;
|
|
1282
1424
|
}
|
|
1283
1425
|
|
|
@@ -1303,11 +1445,34 @@ export interface PermissionResult {
|
|
|
1303
1445
|
permissions: Record<string, boolean>;
|
|
1304
1446
|
}
|
|
1305
1447
|
|
|
1448
|
+
export interface ProfileContentItem {
|
|
1449
|
+
/** Unique within this app's content. 1–80 letters, digits, underscores or hyphens. */
|
|
1450
|
+
id: string;
|
|
1451
|
+
/** Plain text, 1–120 characters. */
|
|
1452
|
+
title: string;
|
|
1453
|
+
/** Plain text, at most 2,000 characters. */
|
|
1454
|
+
description?: string;
|
|
1455
|
+
/** HTTPS image URL, at most 2,048 characters. Upload media before publishing. */
|
|
1456
|
+
imageUrl?: string;
|
|
1457
|
+
}
|
|
1458
|
+
export interface ProfileContent { items: ProfileContentItem[]; }
|
|
1459
|
+
export interface ProfileModule {
|
|
1460
|
+
/** Read only this app's content for the current user. Requires profile_content permission. */
|
|
1461
|
+
getContent(): Promise<ProfileContent>;
|
|
1462
|
+
/** Replace up to 50 cards. Requires profile_content permission; never prompts automatically.
|
|
1463
|
+
* Signed-in profile visitors can see these cards. [] hides this app's category.
|
|
1464
|
+
* Requires an updated mobile/web host. Old hosts reject with REQUEST_TIMEOUT.
|
|
1465
|
+
*/
|
|
1466
|
+
setContent(content: ProfileContent): Promise<ProfileContent>;
|
|
1467
|
+
/** Remove this app's cards. Allowed after permission revocation as well. */
|
|
1468
|
+
clearContent(): Promise<void>;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1306
1471
|
/**
|
|
1307
1472
|
* Ask the user to allow capabilities (the host shows a modal — like asking for
|
|
1308
1473
|
* money). The platform enforces grants: e.g. `notify.send` is dropped until
|
|
1309
1474
|
* `notifications` is granted. Embedded feature; standalone resolves "not
|
|
1310
|
-
* granted". Permission keys
|
|
1475
|
+
* granted". Permission keys: `'notifications'` and `'profile_content'`.
|
|
1311
1476
|
*/
|
|
1312
1477
|
export interface PermissionsModule {
|
|
1313
1478
|
/** Prompt the user to allow one or more permissions. */
|
|
@@ -1379,16 +1544,37 @@ export interface CloudScope {
|
|
|
1379
1544
|
keys(opts?: { serviceId?: string }): Promise<string[]>;
|
|
1380
1545
|
}
|
|
1381
1546
|
|
|
1547
|
+
/** One accepted friend's value from `Usion.cloud.friends.list`. */
|
|
1548
|
+
export interface FriendCloudValue {
|
|
1549
|
+
userId: string;
|
|
1550
|
+
name: string | null;
|
|
1551
|
+
avatar: string | null;
|
|
1552
|
+
value: any;
|
|
1553
|
+
/** ISO 8601 time the friend last wrote the value. */
|
|
1554
|
+
updatedAt: string | null;
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1382
1557
|
/**
|
|
1383
1558
|
* Server-persisted cloud storage. Per-user scope on the module itself
|
|
1384
1559
|
* (cloud saves synced across devices); `shared` is one bucket per app that
|
|
1385
1560
|
* all users read/write. Quotas: 64 KB/value, 200 keys + 1 MB per bucket.
|
|
1561
|
+
* `friends` holds values you own that your accepted friends can read
|
|
1562
|
+
* (4 KB/value, 200 keys).
|
|
1386
1563
|
*/
|
|
1387
1564
|
export interface CloudModule extends CloudScope {
|
|
1388
1565
|
shared: CloudScope & {
|
|
1389
1566
|
/** Atomically increment a shared numeric value (default delta 1). Resolves to the new value. */
|
|
1390
1567
|
incr(key: string, delta?: number, opts?: { serviceId?: string }): Promise<number>;
|
|
1391
1568
|
};
|
|
1569
|
+
/**
|
|
1570
|
+
* Values you own that your accepted friends (mutual consent, blocks
|
|
1571
|
+
* excluded) can read in this app. get/set/remove/keys act on your own
|
|
1572
|
+
* values; `list` reads your friends'. Max 4 KB/value, 200 keys.
|
|
1573
|
+
*/
|
|
1574
|
+
friends: CloudScope & {
|
|
1575
|
+
/** Friends' values for `key`, newest first (max 200). [] for guests. Never includes you. */
|
|
1576
|
+
list(key: string, opts?: { serviceId?: string }): Promise<FriendCloudValue[]>;
|
|
1577
|
+
};
|
|
1392
1578
|
}
|
|
1393
1579
|
|
|
1394
1580
|
export interface Match { roomId: string; players: string[]; serviceId?: string; }
|
|
@@ -1464,6 +1650,7 @@ export interface LobbyModule {
|
|
|
1464
1650
|
* `err.code`, never on message text.
|
|
1465
1651
|
*/
|
|
1466
1652
|
export declare const ERROR_CODES: {
|
|
1653
|
+
readonly PERMISSION_DENIED: 'PERMISSION_DENIED';
|
|
1467
1654
|
readonly NOT_CONNECTED: 'NOT_CONNECTED';
|
|
1468
1655
|
readonly NO_ROOM: 'NO_ROOM';
|
|
1469
1656
|
readonly ROOM_NOT_FOUND: 'ROOM_NOT_FOUND';
|
|
@@ -1510,3 +1697,49 @@ declare const Usion: UsionSDK;
|
|
|
1510
1697
|
|
|
1511
1698
|
export { Usion };
|
|
1512
1699
|
export default Usion;
|
|
1700
|
+
|
|
1701
|
+
/** Connection options for small platform rooms. TURN credentials are supplied by the caller. */
|
|
1702
|
+
export interface ConnectPlayersOptions {
|
|
1703
|
+
roomId?: string;
|
|
1704
|
+
iceServers?: RTCIceServer[];
|
|
1705
|
+
direct?: boolean;
|
|
1706
|
+
/** 1000–30000ms; default 6000. Gameplay uses the relay during negotiation. */
|
|
1707
|
+
directTimeoutMs?: number;
|
|
1708
|
+
}
|
|
1709
|
+
export interface PlayersPeerStatus {
|
|
1710
|
+
playerId: string;
|
|
1711
|
+
transport: 'connecting' | 'webrtc' | 'direct' | 'turn' | 'relay' | 'offline';
|
|
1712
|
+
rttMs: number | null;
|
|
1713
|
+
sent: number;
|
|
1714
|
+
received: number;
|
|
1715
|
+
}
|
|
1716
|
+
export interface PlayersStatus {
|
|
1717
|
+
roomId: string | null;
|
|
1718
|
+
state: 'waiting' | 'connected' | 'offline' | 'closed';
|
|
1719
|
+
peers: PlayersPeerStatus[];
|
|
1720
|
+
}
|
|
1721
|
+
export interface PlayersLog {
|
|
1722
|
+
time: number;
|
|
1723
|
+
event: string;
|
|
1724
|
+
peerId?: string;
|
|
1725
|
+
reason?: string;
|
|
1726
|
+
}
|
|
1727
|
+
export interface PlayersConnection {
|
|
1728
|
+
readonly selfId: string;
|
|
1729
|
+
readonly roomId: string | null;
|
|
1730
|
+
readonly closed: boolean;
|
|
1731
|
+
/** Best-effort JSON updates, up to 4096 UTF-8 bytes. No buffering while offline.
|
|
1732
|
+
* Returns local acceptance, not a delivery acknowledgement. Omit playerId to broadcast.
|
|
1733
|
+
* Late/duplicate updates are discarded; use game.action for durable actions. */
|
|
1734
|
+
send(data: unknown, playerId?: string): boolean;
|
|
1735
|
+
onMessage(callback: (message: {data: any; playerId: string; transport: 'direct' | 'turn' | 'webrtc' | 'relay'}) => void): () => void;
|
|
1736
|
+
onStatusChange(callback: (status: PlayersStatus) => void): () => void;
|
|
1737
|
+
onLog(callback: (entry: PlayersLog) => void): () => void;
|
|
1738
|
+
getStatus(): PlayersStatus;
|
|
1739
|
+
getLogs(): PlayersLog[];
|
|
1740
|
+
forceRelay(playerId?: string): void;
|
|
1741
|
+
retryDirect(playerId?: string): void;
|
|
1742
|
+
invite(): Promise<{success: boolean; roomId: string | null; invited: string[]}>;
|
|
1743
|
+
/** Close networking only; does not leave the platform room or erase game state. */
|
|
1744
|
+
close(): void;
|
|
1745
|
+
}
|