@wvdsh/sdk-js 1.3.16 → 1.3.17
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/dist/index.d.ts +361 -331
- package/dist/index.js +2845 -2751
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,76 @@ import { FunctionReturnType, FunctionArgs } from 'convex/server';
|
|
|
5
5
|
import { LOBBY_VISIBILITY, api, UGC_TYPE, UGC_VISIBILITY, LEADERBOARD_SORT_ORDER, LEADERBOARD_DISPLAY_TYPE, GAME_ENGINE, SDKUser, IFrameEventPayloadMap, IFRAME_MESSAGE_TYPE, SDKConfig, GameLaunchParams } from '@wvdsh/api';
|
|
6
6
|
export { GameLaunchParams } from '@wvdsh/api';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Base class for SDK managers. Provides the shared `sdk` reference and a
|
|
10
|
+
* default no-op `destroy()` so the SDK can safely iterate every manager
|
|
11
|
+
* during teardown without each one having to define an empty stub.
|
|
12
|
+
*
|
|
13
|
+
* Override `destroy()` in any manager that owns ongoing state — Convex
|
|
14
|
+
* subscriptions, intervals, peer connections, monkey-patched globals, etc.
|
|
15
|
+
* — to make sure that state is released when the SDK is torn down.
|
|
16
|
+
*/
|
|
17
|
+
declare abstract class WavedashManager {
|
|
18
|
+
protected sdk: WavedashSDK;
|
|
19
|
+
constructor(sdk: WavedashSDK);
|
|
20
|
+
destroy(): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* AudioManager
|
|
25
|
+
*
|
|
26
|
+
* Mutes & unmutes the game in response to MUTE_CHANGED iframe messages, without
|
|
27
|
+
* the game needing to know anything about it.
|
|
28
|
+
*
|
|
29
|
+
* Web Audio: subclass `AudioContext` so `ctx.destination` resolves to a master
|
|
30
|
+
* GainNode that we control. The master gain wires to the real native destination,
|
|
31
|
+
* so `node.connect(ctx.destination)` and any other game code is unaffected.
|
|
32
|
+
*
|
|
33
|
+
* HTML Media (`<audio>`/`<video>`): override `HTMLMediaElement.prototype.muted`
|
|
34
|
+
* to record the game's intended state, but write `true` to the underlying element
|
|
35
|
+
* whenever the SDK is muted. Tracked elements come from three sources:
|
|
36
|
+
* 1. Pre-existing DOM media (`querySelectorAll`)
|
|
37
|
+
* 2. `new Audio()` constructor shim (covers detached SFX)
|
|
38
|
+
* 3. MutationObserver for any media added to the DOM later (covers innerHTML,
|
|
39
|
+
* framework rendering, createElement + append, etc.)
|
|
40
|
+
*/
|
|
41
|
+
declare class AudioManager extends WavedashManager {
|
|
42
|
+
private _isMuted;
|
|
43
|
+
private contexts;
|
|
44
|
+
private elements;
|
|
45
|
+
private intendedMuted;
|
|
46
|
+
private originalAudioContext;
|
|
47
|
+
private originalWebKitAudioContext;
|
|
48
|
+
private originalAudio;
|
|
49
|
+
private originalMutedDescriptor;
|
|
50
|
+
private mutationObserver;
|
|
51
|
+
constructor(sdk: WavedashSDK);
|
|
52
|
+
isMuted(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Ask the host to mute (true) or unmute (false). Resolves to `true` if the
|
|
55
|
+
* host applied the change, `false` otherwise — notably, the host rejects an
|
|
56
|
+
* unmute when the user muted the game from the Wavedash UI, so games can't
|
|
57
|
+
* override an explicit user mute. The resulting state arrives via the usual
|
|
58
|
+
* MUTE_CHANGED broadcast, so `isMuted()` updates independently of this result.
|
|
59
|
+
*/
|
|
60
|
+
requestMute(muted: boolean): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Toggle mute. Like `requestMute`, the host may reject the unmute half of a
|
|
63
|
+
* toggle if the user muted from the Wavedash UI. Resolves to `true` if the
|
|
64
|
+
* host applied the change.
|
|
65
|
+
*/
|
|
66
|
+
toggleMute(): Promise<boolean>;
|
|
67
|
+
private handleMute;
|
|
68
|
+
/**
|
|
69
|
+
* Track a media element and (if SDK is currently muted) silence it.
|
|
70
|
+
* Idempotent — safe to call multiple times for the same element.
|
|
71
|
+
*/
|
|
72
|
+
private trackElement;
|
|
73
|
+
private installShims;
|
|
74
|
+
private shimAudioContextClass;
|
|
75
|
+
destroy(): void;
|
|
76
|
+
}
|
|
77
|
+
|
|
8
78
|
/**
|
|
9
79
|
* SDK-to-Engine Events
|
|
10
80
|
*
|
|
@@ -262,18 +332,234 @@ interface P2PConfig {
|
|
|
262
332
|
}
|
|
263
333
|
|
|
264
334
|
/**
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
* during teardown without each one having to define an empty stub.
|
|
335
|
+
* File system service
|
|
336
|
+
* Utilities for syncing local IndexedDB files with remote storage.
|
|
268
337
|
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
* — to make sure that state is released when the SDK is torn down.
|
|
338
|
+
* Exposes a specific remote folder for the game to save user-specific files to.
|
|
339
|
+
* TODO: Extend this to game-level assets as well.
|
|
272
340
|
*/
|
|
273
|
-
|
|
274
|
-
|
|
341
|
+
|
|
342
|
+
declare class FileSystemManager extends WavedashManager {
|
|
343
|
+
private remoteStorageOrigin;
|
|
344
|
+
constructor(sdk: WavedashSDK);
|
|
345
|
+
/**
|
|
346
|
+
* Converts a local filesystem path into a full R2 object key.
|
|
347
|
+
* Normalizes the Unity persistentDataPath and prepends the R2 prefix.
|
|
348
|
+
*/
|
|
349
|
+
private toRemoteKey;
|
|
350
|
+
/**
|
|
351
|
+
* Converts a full R2 object key back into the local filesystem path
|
|
352
|
+
* the engine expects. Inverse of toRemoteKey.
|
|
353
|
+
*/
|
|
354
|
+
private toLocalPath;
|
|
355
|
+
/**
|
|
356
|
+
* Uploads a local file to remote storage
|
|
357
|
+
* @param filePath - The path of the local file to upload
|
|
358
|
+
* @returns The path of the remote file that the local file was uploaded to
|
|
359
|
+
*/
|
|
360
|
+
uploadRemoteFile(filePath: string): Promise<string>;
|
|
361
|
+
/**
|
|
362
|
+
* Deletes a remote file from storage
|
|
363
|
+
* @param filePath - The path of the remote file to delete
|
|
364
|
+
* @returns The path of the remote file that was deleted
|
|
365
|
+
*/
|
|
366
|
+
deleteRemoteFile(filePath: string): Promise<string>;
|
|
367
|
+
/**
|
|
368
|
+
* Downloads a remote file to a local location.
|
|
369
|
+
* Throws on failure; the error message is the server's HTTP status (e.g. "404 (Not Found)")
|
|
370
|
+
* or a network-level description if the server didn't respond. See also: {@link remoteFileExists}
|
|
371
|
+
* @param filePath - The path of the remote file to download
|
|
372
|
+
* @returns The path of the local file that the remote file was downloaded to
|
|
373
|
+
*/
|
|
374
|
+
downloadRemoteFile(filePath: string): Promise<string>;
|
|
375
|
+
/**
|
|
376
|
+
* Checks whether a remote file exists by issuing a HEAD request.
|
|
377
|
+
* Does NOT throw for the "file does not exist" case — returns false.
|
|
378
|
+
* Throws only for real errors (network failure, auth failure, server error).
|
|
379
|
+
* @param filePath - The path of the remote file to check
|
|
380
|
+
* @returns true if the remote file exists, false otherwise
|
|
381
|
+
*/
|
|
382
|
+
remoteFileExists(filePath: string): Promise<boolean>;
|
|
383
|
+
/**
|
|
384
|
+
* Lists each file in a remote directory, including its subdirectories.
|
|
385
|
+
* Returns only file paths, no directory paths.
|
|
386
|
+
* An empty or non-existent directory returns an empty array — not an error.
|
|
387
|
+
* @param path - The path of the remote directory to list
|
|
388
|
+
* @returns A list of metadata for each file in the remote directory
|
|
389
|
+
*/
|
|
390
|
+
listRemoteDirectory(path: string): Promise<RemoteFileMetadata[]>;
|
|
391
|
+
downloadRemoteDirectory(path: string): Promise<string>;
|
|
392
|
+
writeLocalFile(filePath: string, data: Uint8Array): Promise<boolean>;
|
|
393
|
+
readLocalFile(filePath: string): Promise<Uint8Array | null>;
|
|
394
|
+
upload(presignedUploadUrl: string, filePath: string): Promise<boolean>;
|
|
395
|
+
download(url: string, filePath: string): Promise<void>;
|
|
396
|
+
private getRemoteStorageOrigin;
|
|
397
|
+
private getRemoteStorageUrl;
|
|
398
|
+
private uploadFromIndexedDb;
|
|
399
|
+
private uploadFromFS;
|
|
400
|
+
private readLocalFileBlob;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Friends service
|
|
405
|
+
*
|
|
406
|
+
* Implements friend-related methods for the Wavedash SDK
|
|
407
|
+
*/
|
|
408
|
+
|
|
409
|
+
declare class FriendsManager extends WavedashManager {
|
|
410
|
+
private userCache;
|
|
411
|
+
private leaderboardPageUserCache;
|
|
275
412
|
constructor(sdk: WavedashSDK);
|
|
413
|
+
/**
|
|
414
|
+
* Returns CDN URL with size transformation for a cached user's avatar.
|
|
415
|
+
* @param userId - The user ID to get the avatar URL for
|
|
416
|
+
* @param size - Pixel size for width and height. Use a value from
|
|
417
|
+
* `AvatarSize` (SMALL=64, MEDIUM=128, LARGE=256) or any custom pixel size.
|
|
418
|
+
* @returns CDN URL with size transformation, or null if user not cached or has no avatar
|
|
419
|
+
*/
|
|
420
|
+
getUserAvatarUrl(userId: GenericId<"users">, size?: number): string | null;
|
|
421
|
+
/**
|
|
422
|
+
* Returns the cached username for a given user ID
|
|
423
|
+
* @param userId - The user ID to get the username for
|
|
424
|
+
* @returns The username, or null if user not cached
|
|
425
|
+
*/
|
|
426
|
+
getUsername(userId: GenericId<"users">): string | null;
|
|
427
|
+
/**
|
|
428
|
+
* List all friends for the logged in user
|
|
429
|
+
* @returns Array<{
|
|
430
|
+
* avatarUrl?: string;
|
|
431
|
+
* isOnline: boolean;
|
|
432
|
+
* userId: Id<"users">;
|
|
433
|
+
* username: string;
|
|
434
|
+
* }>
|
|
435
|
+
*/
|
|
436
|
+
listFriends(): Promise<Friend[]>;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* FullscreenManager
|
|
441
|
+
*
|
|
442
|
+
* Wavedash owns the fullscreen target (a wrapper DIV on the host page that
|
|
443
|
+
* contains both the game iframe and our overlay UI). The SDK inside the iframe
|
|
444
|
+
* therefore can't call `requestFullscreen` directly — it asks the parent to
|
|
445
|
+
* do it via postMessage, and the parent broadcasts state changes back through
|
|
446
|
+
* FULLSCREEN_CHANGED so we can keep a local mirror of `isFullscreen`.
|
|
447
|
+
*
|
|
448
|
+
* User activation: browsers require a fresh user gesture to enter fullscreen.
|
|
449
|
+
* The click happens in the iframe, User Activation v2 propagates transient
|
|
450
|
+
* activation to ancestor frames, and the parent's message handler runs within
|
|
451
|
+
* the ~5s window — so the parent's requestFullscreen call stays activated.
|
|
452
|
+
*
|
|
453
|
+
* Legacy compat: games that call `element.requestFullscreen()` or listen for
|
|
454
|
+
* `fullscreenchange` directly are monkey-patched in the constructor so those
|
|
455
|
+
* calls route through us. The iframe isn't granted the fullscreen feature
|
|
456
|
+
* policy anymore, so without these shims those calls would silently reject.
|
|
457
|
+
*/
|
|
458
|
+
declare class FullscreenManager extends WavedashManager {
|
|
459
|
+
private _isFullscreen;
|
|
460
|
+
private listeners;
|
|
461
|
+
constructor(sdk: WavedashSDK);
|
|
462
|
+
isFullscreen(): boolean;
|
|
463
|
+
/**
|
|
464
|
+
* Ask the host to enter (true) or exit (false) fullscreen. Resolves to
|
|
465
|
+
* `true` if the host reports the operation succeeded, `false` otherwise
|
|
466
|
+
* (e.g. browser rejected for lack of user activation).
|
|
467
|
+
*/
|
|
468
|
+
requestFullscreen(fullscreen: boolean): Promise<boolean>;
|
|
469
|
+
toggleFullscreen(): Promise<boolean>;
|
|
470
|
+
/** Subscribe to state flips. Returns an unsubscribe fn. */
|
|
471
|
+
subscribe(listener: (isFullscreen: boolean) => void): () => void;
|
|
472
|
+
private setState;
|
|
473
|
+
private installCompatShims;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
declare class GameEventManager extends WavedashManager {
|
|
477
|
+
private eventQueue;
|
|
478
|
+
constructor(sdk: WavedashSDK);
|
|
479
|
+
notifyGame(event: WavedashEvent, payload: string | number | object): void;
|
|
480
|
+
private sendGameEvent;
|
|
481
|
+
flushEventQueue(): void;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Heartbeat service
|
|
486
|
+
*
|
|
487
|
+
* Polls connection state and allows the game to update rich user presence
|
|
488
|
+
* Lets the game know if backend connection ever changes.
|
|
489
|
+
* Lets the game update userPresence in the backend
|
|
490
|
+
*/
|
|
491
|
+
|
|
492
|
+
declare class HeartbeatManager extends WavedashManager {
|
|
493
|
+
private deviceFingerprint;
|
|
494
|
+
private deviceFingerprintReady;
|
|
495
|
+
private testConnectionInterval;
|
|
496
|
+
private heartbeatInterval;
|
|
497
|
+
private gamepadPollInterval;
|
|
498
|
+
private inactivityTimeout;
|
|
499
|
+
private isConnected;
|
|
500
|
+
private sentDisconnectedEvent;
|
|
501
|
+
private disconnectedAt;
|
|
502
|
+
private lastHeartbeatTime;
|
|
503
|
+
private lastInputResetAt;
|
|
504
|
+
private heartbeatInFlight;
|
|
505
|
+
private isFirstTick;
|
|
506
|
+
private readonly TEST_CONNECTION_INTERVAL_MS;
|
|
507
|
+
private readonly DISCONNECTED_TIMEOUT_MS;
|
|
508
|
+
private readonly INACTIVITY_TIMEOUT_MS;
|
|
509
|
+
private readonly INPUT_THROTTLE_MS;
|
|
510
|
+
private readonly GAMEPAD_POLL_INTERVAL_MS;
|
|
511
|
+
private readonly GAMEPAD_AXIS_DEADZONE;
|
|
512
|
+
private cachedPresenceData;
|
|
513
|
+
constructor(sdk: WavedashSDK);
|
|
514
|
+
/**
|
|
515
|
+
* Start (or refresh) the heartbeat. Idempotent: if intervals are already
|
|
516
|
+
* running this just reschedules the inactivity timer. No-op if the game
|
|
517
|
+
* hasn't loaded yet or the tab is hidden.
|
|
518
|
+
*/
|
|
519
|
+
start(): void;
|
|
520
|
+
/** Stop the heartbeat and clear the inactivity timer. Idempotent. */
|
|
521
|
+
stop(): void;
|
|
522
|
+
/**
|
|
523
|
+
* Updates user presence in the backend.
|
|
524
|
+
* @param data - Data to send to the backend
|
|
525
|
+
* @returns true if the presence was updated successfully
|
|
526
|
+
*/
|
|
527
|
+
updateUserPresence(data: Record<string, string | number | boolean | null>): Promise<boolean>;
|
|
528
|
+
isCurrentlyConnected(): boolean;
|
|
529
|
+
/** Full teardown — stops intervals and removes all listeners */
|
|
276
530
|
destroy(): void;
|
|
531
|
+
private tickHeartbeat;
|
|
532
|
+
private sendHeartbeat;
|
|
533
|
+
private handleVisibilityChange;
|
|
534
|
+
private handleUserInput;
|
|
535
|
+
/**
|
|
536
|
+
* Polls connected gamepads; any pressed button or out-of-deadzone axis
|
|
537
|
+
* counts as user activity and (re)starts the heartbeat.
|
|
538
|
+
*/
|
|
539
|
+
private pollGamepads;
|
|
540
|
+
/**
|
|
541
|
+
* Tests the connection to the backend
|
|
542
|
+
*/
|
|
543
|
+
private testConnection;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Leaderboard service
|
|
548
|
+
*
|
|
549
|
+
* Implements each of the leaderboard methods of the Wavedash SDK
|
|
550
|
+
*/
|
|
551
|
+
|
|
552
|
+
declare class LeaderboardManager extends WavedashManager {
|
|
553
|
+
private leaderboardCache;
|
|
554
|
+
constructor(sdk: WavedashSDK);
|
|
555
|
+
getLeaderboard(name: string): Promise<Leaderboard>;
|
|
556
|
+
getOrCreateLeaderboard(name: string, sortOrder: LeaderboardSortOrder, displayType: LeaderboardDisplayType): Promise<Leaderboard>;
|
|
557
|
+
getLeaderboardEntryCount(leaderboardId: GenericId<"leaderboards">): number;
|
|
558
|
+
getMyLeaderboardEntries(leaderboardId: GenericId<"leaderboards">): Promise<LeaderboardEntries>;
|
|
559
|
+
listLeaderboardEntriesAroundUser(leaderboardId: GenericId<"leaderboards">, countAhead: number, countBehind: number, friendsOnly?: boolean): Promise<LeaderboardEntries>;
|
|
560
|
+
listLeaderboardEntries(leaderboardId: GenericId<"leaderboards">, offset: number, limit: number, friendsOnly?: boolean): Promise<LeaderboardEntries>;
|
|
561
|
+
uploadLeaderboardScore(leaderboardId: GenericId<"leaderboards">, score: number, keepBest: boolean, ugcId?: GenericId<"userGeneratedContent">): Promise<UpsertedLeaderboardEntry>;
|
|
562
|
+
private updateCachedTotalEntries;
|
|
277
563
|
}
|
|
278
564
|
|
|
279
565
|
/**
|
|
@@ -359,114 +645,29 @@ declare class LobbyManager extends WavedashManager {
|
|
|
359
645
|
private processUserUpdates;
|
|
360
646
|
private processMessageUpdates;
|
|
361
647
|
private processInviteUpdates;
|
|
362
|
-
/**
|
|
363
|
-
* Update P2P connections when lobby membership changes
|
|
364
|
-
* @param newUsers - The updated list of lobby users
|
|
365
|
-
*/
|
|
366
|
-
private updateP2PConnections;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* File system service
|
|
371
|
-
* Utilities for syncing local IndexedDB files with remote storage.
|
|
372
|
-
*
|
|
373
|
-
* Exposes a specific remote folder for the game to save user-specific files to.
|
|
374
|
-
* TODO: Extend this to game-level assets as well.
|
|
375
|
-
*/
|
|
376
|
-
|
|
377
|
-
declare class FileSystemManager extends WavedashManager {
|
|
378
|
-
private remoteStorageOrigin;
|
|
379
|
-
constructor(sdk: WavedashSDK);
|
|
380
|
-
/**
|
|
381
|
-
* Converts a local filesystem path into a full R2 object key.
|
|
382
|
-
* Normalizes the Unity persistentDataPath and prepends the R2 prefix.
|
|
383
|
-
*/
|
|
384
|
-
private toRemoteKey;
|
|
385
|
-
/**
|
|
386
|
-
* Converts a full R2 object key back into the local filesystem path
|
|
387
|
-
* the engine expects. Inverse of toRemoteKey.
|
|
388
|
-
*/
|
|
389
|
-
private toLocalPath;
|
|
390
|
-
/**
|
|
391
|
-
* Uploads a local file to remote storage
|
|
392
|
-
* @param filePath - The path of the local file to upload
|
|
393
|
-
* @returns The path of the remote file that the local file was uploaded to
|
|
394
|
-
*/
|
|
395
|
-
uploadRemoteFile(filePath: string): Promise<string>;
|
|
396
|
-
/**
|
|
397
|
-
* Deletes a remote file from storage
|
|
398
|
-
* @param filePath - The path of the remote file to delete
|
|
399
|
-
* @returns The path of the remote file that was deleted
|
|
400
|
-
*/
|
|
401
|
-
deleteRemoteFile(filePath: string): Promise<string>;
|
|
402
|
-
/**
|
|
403
|
-
* Downloads a remote file to a local location.
|
|
404
|
-
* Throws on failure; the error message is the server's HTTP status (e.g. "404 (Not Found)")
|
|
405
|
-
* or a network-level description if the server didn't respond. See also: {@link remoteFileExists}
|
|
406
|
-
* @param filePath - The path of the remote file to download
|
|
407
|
-
* @returns The path of the local file that the remote file was downloaded to
|
|
408
|
-
*/
|
|
409
|
-
downloadRemoteFile(filePath: string): Promise<string>;
|
|
410
|
-
/**
|
|
411
|
-
* Checks whether a remote file exists by issuing a HEAD request.
|
|
412
|
-
* Does NOT throw for the "file does not exist" case — returns false.
|
|
413
|
-
* Throws only for real errors (network failure, auth failure, server error).
|
|
414
|
-
* @param filePath - The path of the remote file to check
|
|
415
|
-
* @returns true if the remote file exists, false otherwise
|
|
416
|
-
*/
|
|
417
|
-
remoteFileExists(filePath: string): Promise<boolean>;
|
|
418
|
-
/**
|
|
419
|
-
* Lists each file in a remote directory, including its subdirectories.
|
|
420
|
-
* Returns only file paths, no directory paths.
|
|
421
|
-
* An empty or non-existent directory returns an empty array — not an error.
|
|
422
|
-
* @param path - The path of the remote directory to list
|
|
423
|
-
* @returns A list of metadata for each file in the remote directory
|
|
424
|
-
*/
|
|
425
|
-
listRemoteDirectory(path: string): Promise<RemoteFileMetadata[]>;
|
|
426
|
-
downloadRemoteDirectory(path: string): Promise<string>;
|
|
427
|
-
writeLocalFile(filePath: string, data: Uint8Array): Promise<boolean>;
|
|
428
|
-
readLocalFile(filePath: string): Promise<Uint8Array | null>;
|
|
429
|
-
upload(presignedUploadUrl: string, filePath: string): Promise<boolean>;
|
|
430
|
-
download(url: string, filePath: string): Promise<void>;
|
|
431
|
-
private getRemoteStorageOrigin;
|
|
432
|
-
private getRemoteStorageUrl;
|
|
433
|
-
private uploadFromIndexedDb;
|
|
434
|
-
private uploadFromFS;
|
|
435
|
-
private readLocalFileBlob;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* UGC service
|
|
440
|
-
*
|
|
441
|
-
* Implements each of the user generated content methods of the Wavedash SDK
|
|
442
|
-
*/
|
|
443
|
-
|
|
444
|
-
declare class UGCManager extends WavedashManager {
|
|
445
|
-
constructor(sdk: WavedashSDK);
|
|
446
|
-
createUGCItem(ugcType: UGCType, title?: string, description?: string, visibility?: UGCVisibility, filePath?: string): Promise<GenericId<"userGeneratedContent">>;
|
|
447
|
-
updateUGCItem(ugcId: GenericId<"userGeneratedContent">, updates?: UpdateUGCItemArgs): Promise<GenericId<"userGeneratedContent">>;
|
|
448
|
-
deleteUGCItem(ugcId: GenericId<"userGeneratedContent">): Promise<GenericId<"userGeneratedContent">>;
|
|
449
|
-
downloadUGCItem(ugcId: GenericId<"userGeneratedContent">, filePath: string): Promise<GenericId<"userGeneratedContent">>;
|
|
450
|
-
listUGCItems(args?: ListUGCItemsArgs): Promise<PaginatedUGCItems>;
|
|
648
|
+
/**
|
|
649
|
+
* Update P2P connections when lobby membership changes
|
|
650
|
+
* @param newUsers - The updated list of lobby users
|
|
651
|
+
*/
|
|
652
|
+
private updateP2PConnections;
|
|
451
653
|
}
|
|
452
654
|
|
|
453
655
|
/**
|
|
454
|
-
*
|
|
656
|
+
* OverlayManager
|
|
455
657
|
*
|
|
456
|
-
*
|
|
658
|
+
* Owns the iframe ↔ parent interactions for the Wavedash overlay UI:
|
|
659
|
+
* - Shift+Tab inside the iframe toggles the overlay on the host page
|
|
660
|
+
* (the host owns the overlay, so we postMessage up).
|
|
661
|
+
* - When the parent closes the overlay it sends TAKE_FOCUS so keyboard
|
|
662
|
+
* input goes back to the game; we walk the DOM for a focusable target.
|
|
663
|
+
* - `takeFocus()` is also called after load completes so the game starts
|
|
664
|
+
* with keyboard focus without the player clicking first.
|
|
457
665
|
*/
|
|
458
|
-
|
|
459
|
-
declare class LeaderboardManager extends WavedashManager {
|
|
460
|
-
private leaderboardCache;
|
|
666
|
+
declare class OverlayManager extends WavedashManager {
|
|
461
667
|
constructor(sdk: WavedashSDK);
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
getMyLeaderboardEntries(leaderboardId: GenericId<"leaderboards">): Promise<LeaderboardEntries>;
|
|
466
|
-
listLeaderboardEntriesAroundUser(leaderboardId: GenericId<"leaderboards">, countAhead: number, countBehind: number, friendsOnly?: boolean): Promise<LeaderboardEntries>;
|
|
467
|
-
listLeaderboardEntries(leaderboardId: GenericId<"leaderboards">, offset: number, limit: number, friendsOnly?: boolean): Promise<LeaderboardEntries>;
|
|
468
|
-
uploadLeaderboardScore(leaderboardId: GenericId<"leaderboards">, score: number, keepBest: boolean, ugcId?: GenericId<"userGeneratedContent">): Promise<UpsertedLeaderboardEntry>;
|
|
469
|
-
private updateCachedTotalEntries;
|
|
668
|
+
toggleOverlay(): void;
|
|
669
|
+
takeFocus(): void;
|
|
670
|
+
private handleKeyDown;
|
|
470
671
|
}
|
|
471
672
|
|
|
472
673
|
/**
|
|
@@ -586,6 +787,12 @@ declare class P2PManager extends WavedashManager {
|
|
|
586
787
|
private decodeBinaryMessage;
|
|
587
788
|
}
|
|
588
789
|
|
|
790
|
+
declare class PaidContentManager extends WavedashManager {
|
|
791
|
+
isEntitled(contentId: string): Promise<boolean>;
|
|
792
|
+
getEntitlements(): Promise<string[]>;
|
|
793
|
+
triggerPaywall(contentIdentifier: string): Promise<boolean>;
|
|
794
|
+
}
|
|
795
|
+
|
|
589
796
|
declare class StatsManager extends WavedashManager {
|
|
590
797
|
private stats;
|
|
591
798
|
private unlockedAchievements;
|
|
@@ -615,219 +822,18 @@ declare class StatsManager extends WavedashManager {
|
|
|
615
822
|
}
|
|
616
823
|
|
|
617
824
|
/**
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
* Polls connection state and allows the game to update rich user presence
|
|
621
|
-
* Lets the game know if backend connection ever changes.
|
|
622
|
-
* Lets the game update userPresence in the backend
|
|
623
|
-
*/
|
|
624
|
-
|
|
625
|
-
declare class HeartbeatManager extends WavedashManager {
|
|
626
|
-
private deviceFingerprint;
|
|
627
|
-
private deviceFingerprintReady;
|
|
628
|
-
private testConnectionInterval;
|
|
629
|
-
private heartbeatInterval;
|
|
630
|
-
private gamepadPollInterval;
|
|
631
|
-
private inactivityTimeout;
|
|
632
|
-
private isConnected;
|
|
633
|
-
private sentDisconnectedEvent;
|
|
634
|
-
private disconnectedAt;
|
|
635
|
-
private lastHeartbeatTime;
|
|
636
|
-
private lastInputResetAt;
|
|
637
|
-
private heartbeatInFlight;
|
|
638
|
-
private isFirstTick;
|
|
639
|
-
private readonly TEST_CONNECTION_INTERVAL_MS;
|
|
640
|
-
private readonly DISCONNECTED_TIMEOUT_MS;
|
|
641
|
-
private readonly INACTIVITY_TIMEOUT_MS;
|
|
642
|
-
private readonly INPUT_THROTTLE_MS;
|
|
643
|
-
private readonly GAMEPAD_POLL_INTERVAL_MS;
|
|
644
|
-
private readonly GAMEPAD_AXIS_DEADZONE;
|
|
645
|
-
private cachedPresenceData;
|
|
646
|
-
constructor(sdk: WavedashSDK);
|
|
647
|
-
/**
|
|
648
|
-
* Start (or refresh) the heartbeat. Idempotent: if intervals are already
|
|
649
|
-
* running this just reschedules the inactivity timer. No-op if the game
|
|
650
|
-
* hasn't loaded yet or the tab is hidden.
|
|
651
|
-
*/
|
|
652
|
-
start(): void;
|
|
653
|
-
/** Stop the heartbeat and clear the inactivity timer. Idempotent. */
|
|
654
|
-
stop(): void;
|
|
655
|
-
/**
|
|
656
|
-
* Updates user presence in the backend.
|
|
657
|
-
* @param data - Data to send to the backend
|
|
658
|
-
* @returns true if the presence was updated successfully
|
|
659
|
-
*/
|
|
660
|
-
updateUserPresence(data: Record<string, string | number | boolean | null>): Promise<boolean>;
|
|
661
|
-
isCurrentlyConnected(): boolean;
|
|
662
|
-
/** Full teardown — stops intervals and removes all listeners */
|
|
663
|
-
destroy(): void;
|
|
664
|
-
private tickHeartbeat;
|
|
665
|
-
private sendHeartbeat;
|
|
666
|
-
private handleVisibilityChange;
|
|
667
|
-
private handleUserInput;
|
|
668
|
-
/**
|
|
669
|
-
* Polls connected gamepads; any pressed button or out-of-deadzone axis
|
|
670
|
-
* counts as user activity and (re)starts the heartbeat.
|
|
671
|
-
*/
|
|
672
|
-
private pollGamepads;
|
|
673
|
-
/**
|
|
674
|
-
* Tests the connection to the backend
|
|
675
|
-
*/
|
|
676
|
-
private testConnection;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
declare class GameEventManager extends WavedashManager {
|
|
680
|
-
private eventQueue;
|
|
681
|
-
constructor(sdk: WavedashSDK);
|
|
682
|
-
notifyGame(event: WavedashEvent, payload: string | number | object): void;
|
|
683
|
-
private sendGameEvent;
|
|
684
|
-
flushEventQueue(): void;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* FullscreenManager
|
|
689
|
-
*
|
|
690
|
-
* Wavedash owns the fullscreen target (a wrapper DIV on the host page that
|
|
691
|
-
* contains both the game iframe and our overlay UI). The SDK inside the iframe
|
|
692
|
-
* therefore can't call `requestFullscreen` directly — it asks the parent to
|
|
693
|
-
* do it via postMessage, and the parent broadcasts state changes back through
|
|
694
|
-
* FULLSCREEN_CHANGED so we can keep a local mirror of `isFullscreen`.
|
|
695
|
-
*
|
|
696
|
-
* User activation: browsers require a fresh user gesture to enter fullscreen.
|
|
697
|
-
* The click happens in the iframe, User Activation v2 propagates transient
|
|
698
|
-
* activation to ancestor frames, and the parent's message handler runs within
|
|
699
|
-
* the ~5s window — so the parent's requestFullscreen call stays activated.
|
|
700
|
-
*
|
|
701
|
-
* Legacy compat: games that call `element.requestFullscreen()` or listen for
|
|
702
|
-
* `fullscreenchange` directly are monkey-patched in the constructor so those
|
|
703
|
-
* calls route through us. The iframe isn't granted the fullscreen feature
|
|
704
|
-
* policy anymore, so without these shims those calls would silently reject.
|
|
705
|
-
*/
|
|
706
|
-
declare class FullscreenManager extends WavedashManager {
|
|
707
|
-
private _isFullscreen;
|
|
708
|
-
private listeners;
|
|
709
|
-
constructor(sdk: WavedashSDK);
|
|
710
|
-
isFullscreen(): boolean;
|
|
711
|
-
/**
|
|
712
|
-
* Ask the host to enter (true) or exit (false) fullscreen. Resolves to
|
|
713
|
-
* `true` if the host reports the operation succeeded, `false` otherwise
|
|
714
|
-
* (e.g. browser rejected for lack of user activation).
|
|
715
|
-
*/
|
|
716
|
-
requestFullscreen(fullscreen: boolean): Promise<boolean>;
|
|
717
|
-
toggleFullscreen(): Promise<boolean>;
|
|
718
|
-
/** Subscribe to state flips. Returns an unsubscribe fn. */
|
|
719
|
-
subscribe(listener: (isFullscreen: boolean) => void): () => void;
|
|
720
|
-
private setState;
|
|
721
|
-
private installCompatShims;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
/**
|
|
725
|
-
* OverlayManager
|
|
726
|
-
*
|
|
727
|
-
* Owns the iframe ↔ parent interactions for the Wavedash overlay UI:
|
|
728
|
-
* - Shift+Tab inside the iframe toggles the overlay on the host page
|
|
729
|
-
* (the host owns the overlay, so we postMessage up).
|
|
730
|
-
* - When the parent closes the overlay it sends TAKE_FOCUS so keyboard
|
|
731
|
-
* input goes back to the game; we walk the DOM for a focusable target.
|
|
732
|
-
* - `takeFocus()` is also called after load completes so the game starts
|
|
733
|
-
* with keyboard focus without the player clicking first.
|
|
734
|
-
*/
|
|
735
|
-
declare class OverlayManager extends WavedashManager {
|
|
736
|
-
constructor(sdk: WavedashSDK);
|
|
737
|
-
toggleOverlay(): void;
|
|
738
|
-
takeFocus(): void;
|
|
739
|
-
private handleKeyDown;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
/**
|
|
743
|
-
* AudioManager
|
|
744
|
-
*
|
|
745
|
-
* Mutes & unmutes the game in response to MUTE_CHANGED iframe messages, without
|
|
746
|
-
* the game needing to know anything about it.
|
|
747
|
-
*
|
|
748
|
-
* Web Audio: subclass `AudioContext` so `ctx.destination` resolves to a master
|
|
749
|
-
* GainNode that we control. The master gain wires to the real native destination,
|
|
750
|
-
* so `node.connect(ctx.destination)` and any other game code is unaffected.
|
|
751
|
-
*
|
|
752
|
-
* HTML Media (`<audio>`/`<video>`): override `HTMLMediaElement.prototype.muted`
|
|
753
|
-
* to record the game's intended state, but write `true` to the underlying element
|
|
754
|
-
* whenever the SDK is muted. Tracked elements come from three sources:
|
|
755
|
-
* 1. Pre-existing DOM media (`querySelectorAll`)
|
|
756
|
-
* 2. `new Audio()` constructor shim (covers detached SFX)
|
|
757
|
-
* 3. MutationObserver for any media added to the DOM later (covers innerHTML,
|
|
758
|
-
* framework rendering, createElement + append, etc.)
|
|
759
|
-
*/
|
|
760
|
-
declare class AudioManager extends WavedashManager {
|
|
761
|
-
private _isMuted;
|
|
762
|
-
private contexts;
|
|
763
|
-
private elements;
|
|
764
|
-
private intendedMuted;
|
|
765
|
-
private originalAudioContext;
|
|
766
|
-
private originalWebKitAudioContext;
|
|
767
|
-
private originalAudio;
|
|
768
|
-
private originalMutedDescriptor;
|
|
769
|
-
private mutationObserver;
|
|
770
|
-
constructor(sdk: WavedashSDK);
|
|
771
|
-
isMuted(): boolean;
|
|
772
|
-
/**
|
|
773
|
-
* Ask the host to mute (true) or unmute (false). Resolves to `true` if the
|
|
774
|
-
* host applied the change, `false` otherwise — notably, the host rejects an
|
|
775
|
-
* unmute when the user muted the game from the Wavedash UI, so games can't
|
|
776
|
-
* override an explicit user mute. The resulting state arrives via the usual
|
|
777
|
-
* MUTE_CHANGED broadcast, so `isMuted()` updates independently of this result.
|
|
778
|
-
*/
|
|
779
|
-
requestMute(muted: boolean): Promise<boolean>;
|
|
780
|
-
/**
|
|
781
|
-
* Toggle mute. Like `requestMute`, the host may reject the unmute half of a
|
|
782
|
-
* toggle if the user muted from the Wavedash UI. Resolves to `true` if the
|
|
783
|
-
* host applied the change.
|
|
784
|
-
*/
|
|
785
|
-
toggleMute(): Promise<boolean>;
|
|
786
|
-
private handleMute;
|
|
787
|
-
/**
|
|
788
|
-
* Track a media element and (if SDK is currently muted) silence it.
|
|
789
|
-
* Idempotent — safe to call multiple times for the same element.
|
|
790
|
-
*/
|
|
791
|
-
private trackElement;
|
|
792
|
-
private installShims;
|
|
793
|
-
private shimAudioContextClass;
|
|
794
|
-
destroy(): void;
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
/**
|
|
798
|
-
* Friends service
|
|
825
|
+
* UGC service
|
|
799
826
|
*
|
|
800
|
-
* Implements
|
|
827
|
+
* Implements each of the user generated content methods of the Wavedash SDK
|
|
801
828
|
*/
|
|
802
829
|
|
|
803
|
-
declare class
|
|
804
|
-
private userCache;
|
|
805
|
-
private leaderboardPageUserCache;
|
|
830
|
+
declare class UGCManager extends WavedashManager {
|
|
806
831
|
constructor(sdk: WavedashSDK);
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
* @returns CDN URL with size transformation, or null if user not cached or has no avatar
|
|
813
|
-
*/
|
|
814
|
-
getUserAvatarUrl(userId: GenericId<"users">, size?: number): string | null;
|
|
815
|
-
/**
|
|
816
|
-
* Returns the cached username for a given user ID
|
|
817
|
-
* @param userId - The user ID to get the username for
|
|
818
|
-
* @returns The username, or null if user not cached
|
|
819
|
-
*/
|
|
820
|
-
getUsername(userId: GenericId<"users">): string | null;
|
|
821
|
-
/**
|
|
822
|
-
* List all friends for the logged in user
|
|
823
|
-
* @returns Array<{
|
|
824
|
-
* avatarUrl?: string;
|
|
825
|
-
* isOnline: boolean;
|
|
826
|
-
* userId: Id<"users">;
|
|
827
|
-
* username: string;
|
|
828
|
-
* }>
|
|
829
|
-
*/
|
|
830
|
-
listFriends(): Promise<Friend[]>;
|
|
832
|
+
createUGCItem(ugcType: UGCType, title?: string, description?: string, visibility?: UGCVisibility, filePath?: string): Promise<GenericId<"userGeneratedContent">>;
|
|
833
|
+
updateUGCItem(ugcId: GenericId<"userGeneratedContent">, updates?: UpdateUGCItemArgs): Promise<GenericId<"userGeneratedContent">>;
|
|
834
|
+
deleteUGCItem(ugcId: GenericId<"userGeneratedContent">): Promise<GenericId<"userGeneratedContent">>;
|
|
835
|
+
downloadUGCItem(ugcId: GenericId<"userGeneratedContent">, filePath: string): Promise<GenericId<"userGeneratedContent">>;
|
|
836
|
+
listUGCItems(args?: ListUGCItemsArgs): Promise<PaginatedUGCItems>;
|
|
831
837
|
}
|
|
832
838
|
|
|
833
839
|
/**
|
|
@@ -853,7 +859,7 @@ declare class IFrameMessenger {
|
|
|
853
859
|
removeEventListener<T extends PushType>(type: T, listener: PushListener<T>): void;
|
|
854
860
|
private handleMessage;
|
|
855
861
|
postToParent(requestType: (typeof IFRAME_MESSAGE_TYPE)[keyof typeof IFRAME_MESSAGE_TYPE], data: Record<string, string | number | boolean>): boolean;
|
|
856
|
-
requestFromParent<T extends keyof IFrameEventPayloadMap>(requestType: T, data?: Record<string, unknown
|
|
862
|
+
requestFromParent<T extends keyof IFrameEventPayloadMap>(requestType: T, data?: Record<string, unknown>, timeoutMs?: number): Promise<IFrameEventPayloadMap[T]>;
|
|
857
863
|
}
|
|
858
864
|
|
|
859
865
|
/**
|
|
@@ -981,6 +987,7 @@ declare class WavedashSDK extends EventTarget {
|
|
|
981
987
|
fullscreenManager: FullscreenManager;
|
|
982
988
|
overlayManager: OverlayManager;
|
|
983
989
|
audioManager: AudioManager;
|
|
990
|
+
paidContentManager: PaidContentManager;
|
|
984
991
|
private managers;
|
|
985
992
|
private gameplayJwt;
|
|
986
993
|
private gameplayJwtPromise;
|
|
@@ -1260,6 +1267,31 @@ declare class WavedashSDK extends EventTarget {
|
|
|
1260
1267
|
sendLobbyMessage(lobbyId: GenericId<"lobbies">, message: string): boolean;
|
|
1261
1268
|
inviteUserToLobby(lobbyId: GenericId<"lobbies">, userId: GenericId<"users">): Promise<WavedashResponse<boolean>>;
|
|
1262
1269
|
getLobbyInviteLink(copyToClipboard?: boolean): Promise<WavedashResponse<string>>;
|
|
1270
|
+
/**
|
|
1271
|
+
* Returns true if the player owns the given paid content for this game.
|
|
1272
|
+
* Reads the `entitlements` claim from the gameplay JWT — this is a UX hint, not a
|
|
1273
|
+
* security check. The builds server re-verifies the JWT signature and gates
|
|
1274
|
+
* paid asset bytes on every request, so a tampered client return value
|
|
1275
|
+
* doesn't actually unlock anything. Pair with triggerPaywall() to drive
|
|
1276
|
+
* in-game UI.
|
|
1277
|
+
*/
|
|
1278
|
+
isEntitled_EXPERIMENTAL(contentId: string): Promise<WavedashResponse<boolean>>;
|
|
1279
|
+
/**
|
|
1280
|
+
* Returns the full list of paid-content IDs the player owns for this game.
|
|
1281
|
+
* Reads the `entitlements` claim from the gameplay JWT — this is a UX hint,
|
|
1282
|
+
* not a security check (see {@link isEntitled_EXPERIMENTAL}). Useful
|
|
1283
|
+
* for access gating multiple items at once without a call per content ID.
|
|
1284
|
+
*/
|
|
1285
|
+
getEntitlements_EXPERIMENTAL(): Promise<WavedashResponse<string[]>>;
|
|
1286
|
+
/**
|
|
1287
|
+
* Trigger the Wavedash-rendered paywall flow for the given content. Resolves
|
|
1288
|
+
* immediately with data `true` if the player already owns it; otherwise
|
|
1289
|
+
* opens the modal and resolves with whether the user completed the purchase.
|
|
1290
|
+
* After a successful purchase the JWT is refreshed automatically so a
|
|
1291
|
+
* subsequent resource fetch is authenticated with the new purchase, and isEntitled
|
|
1292
|
+
* will return true if the purchase was successful.
|
|
1293
|
+
*/
|
|
1294
|
+
triggerPaywall_EXPERIMENTAL(contentIdentifier: string): Promise<WavedashResponse<boolean>>;
|
|
1263
1295
|
/**
|
|
1264
1296
|
* Updates rich user presence so friends can see what the player is doing in game.
|
|
1265
1297
|
* Supported keys:
|
|
@@ -1277,17 +1309,15 @@ declare class WavedashSDK extends EventTarget {
|
|
|
1277
1309
|
private apiCall;
|
|
1278
1310
|
private apiCallSync;
|
|
1279
1311
|
/**
|
|
1280
|
-
*
|
|
1281
|
-
*
|
|
1282
|
-
*
|
|
1283
|
-
* server can invalidate a stale token.
|
|
1284
|
-
*
|
|
1285
|
-
* Same-origin POST to /auth/refresh on the play domain — the
|
|
1286
|
-
* gameplaySession cookie set by the play server during playKey exchange
|
|
1287
|
-
* authenticates the request, so no cross-origin credentials handling needed.
|
|
1312
|
+
* Fetcher wired into `ConvexClient.setAuth`; other callers use
|
|
1313
|
+
* {@link ensureGameplayJwt}. Same-origin POST to /auth/refresh, authenticated
|
|
1314
|
+
* by the gameplaySession cookie.
|
|
1288
1315
|
*
|
|
1289
|
-
* Concurrent callers share
|
|
1290
|
-
*
|
|
1316
|
+
* Concurrent callers share one in-flight fetch. A forced refresh instead
|
|
1317
|
+
* serializes behind any in-flight fetch (it may predate the event that
|
|
1318
|
+
* required it, e.g. a purchase) and becomes the current promise; only the
|
|
1319
|
+
* current promise notifies the parent, so a superseded refresh can't
|
|
1320
|
+
* broadcast a stale token
|
|
1291
1321
|
*/
|
|
1292
1322
|
private getAuthToken;
|
|
1293
1323
|
/**
|
|
@@ -1295,7 +1325,7 @@ declare class WavedashSDK extends EventTarget {
|
|
|
1295
1325
|
* already running (e.g. from Convex's initial setAuth). Use this anywhere
|
|
1296
1326
|
* you need to authenticate a request outside of the Convex client.
|
|
1297
1327
|
*/
|
|
1298
|
-
ensureGameplayJwt(): Promise<string>;
|
|
1328
|
+
ensureGameplayJwt(forceRefresh?: boolean): Promise<string>;
|
|
1299
1329
|
/**
|
|
1300
1330
|
* Tear down every manager. Called on the parent's `END_SESSION` signal
|
|
1301
1331
|
*/
|