@wvdsh/sdk-js 1.2.3 → 1.3.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.
@@ -0,0 +1,15 @@
1
+ import { WavedashSDK } from './index.js';
2
+ export { BackendConnectionPayload, EngineInstance, Friend, FullscreenChangedPayload, Leaderboard, LeaderboardDisplayType, LeaderboardEntries, LeaderboardSortOrder, Lobby, LobbyDataUpdatedPayload, LobbyInvite, LobbyInvitePayload, LobbyJoinResponse, LobbyJoinedPayload, LobbyKickedPayload, LobbyKickedReason, LobbyMessage, LobbyMessagePayload, LobbyUser, LobbyUserChangeType, LobbyUsersUpdatedPayload, LobbyVisibility, P2PConfig, P2PConnection, P2PConnectionEstablishedPayload, P2PConnectionFailedPayload, P2PMessage, P2PPacketDropReason, P2PPacketDroppedPayload, P2PPeer, P2PPeerDisconnectedPayload, P2PPeerReconnectedPayload, P2PPeerReconnectingPayload, RemoteFileMetadata, StatsStoredPayload, UGCType, UGCVisibility, UpsertedLeaderboardEntry, WavedashConfig, WavedashEvent, WavedashEventMap, WavedashResponse } from './index.js';
3
+ export { GameLaunchParams } from '@wvdsh/api';
4
+ export { GenericId as Id } from 'convex/values';
5
+ import 'convex/browser';
6
+ import 'convex/server';
7
+
8
+ declare global {
9
+ interface Window {
10
+ Wavedash: WavedashSDK;
11
+ }
12
+ }
13
+ declare const Wavedash: WavedashSDK;
14
+
15
+ export { WavedashSDK, Wavedash as default };
package/dist/client.js ADDED
@@ -0,0 +1,11 @@
1
+ // src/client.ts
2
+ var Wavedash = window.Wavedash;
3
+ if (!Wavedash) {
4
+ throw new Error(
5
+ "Wavedash is not initialized. If you're running your game locally use the `wavedash dev` command to ensure the Wavedash SDK is loaded."
6
+ );
7
+ }
8
+ var client_default = Wavedash;
9
+ export {
10
+ client_default as default
11
+ };
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ConvexClient } from 'convex/browser';
2
2
  import { GenericId } from 'convex/values';
3
3
  export { GenericId as Id } from 'convex/values';
4
4
  import { FunctionReturnType } from 'convex/server';
5
- import { PublicApiType, api, GAME_ENGINE, SDKUser, IFrameEventPayloadMap, IFRAME_MESSAGE_TYPE, SDKConfig, GameLaunchParams } from '@wvdsh/api';
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
8
  /**
@@ -33,29 +33,57 @@ declare const WavedashEvents: {
33
33
  readonly FULLSCREEN_CHANGED: "FullscreenChanged";
34
34
  };
35
35
 
36
- type LobbyVisibility = PublicApiType["sdk"]["gameLobby"]["createAndJoinLobby"]["_args"]["visibility"];
36
+ /** Reasons why a user was kicked from a lobby */
37
+ declare const LobbyKickedReason$1: {
38
+ readonly KICKED: "KICKED";
39
+ readonly ERROR: "ERROR";
40
+ };
41
+ /** Change types for lobby user updates */
42
+ declare const LobbyUserChangeType$1: {
43
+ readonly JOINED: "JOINED";
44
+ readonly LEFT: "LEFT";
45
+ };
46
+ /**
47
+ * Reason a P2P packet was dropped. Each reason implies a different
48
+ * game-side remedy:
49
+ * - QUEUE_FULL: throttle your sends, bundle updates into fewer packets, or increase p2p maxIncomingMessages config
50
+ * - PAYLOAD_TOO_LARGE: reduce payload or increase p2p messageSize config
51
+ * - INVALID_PAYLOAD_SIZE: programming error
52
+ * - INVALID_CHANNEL: SDK version skew or malicious peer
53
+ * - MALFORMED: wire data too short to parse; channel will be -1
54
+ * - PEER_NOT_READY: P2P not yet initialized, or peer was never ready / closed mid-send. If P2P hasn't been initialized, initialize it first; otherwise wait for P2P_CONNECTION_ESTABLISHED and watch P2P_PEER_DISCONNECTED/P2P_CONNECTION_FAILED/P2P_PEER_RECONNECTING for reachability.
55
+ */
56
+ declare const P2PPacketDropReason$1: {
57
+ readonly QUEUE_FULL: "QUEUE_FULL";
58
+ readonly PAYLOAD_TOO_LARGE: "PAYLOAD_TOO_LARGE";
59
+ readonly INVALID_PAYLOAD_SIZE: "INVALID_PAYLOAD_SIZE";
60
+ readonly INVALID_CHANNEL: "INVALID_CHANNEL";
61
+ readonly MALFORMED: "MALFORMED";
62
+ readonly PEER_NOT_READY: "PEER_NOT_READY";
63
+ };
64
+
65
+ /**
66
+ * Public types exported from @wvdsh/sdk-js
67
+ */
68
+
69
+ type LobbyVisibility = (typeof LOBBY_VISIBILITY)[keyof typeof LOBBY_VISIBILITY];
70
+ type LeaderboardSortOrder = (typeof LEADERBOARD_SORT_ORDER)[keyof typeof LEADERBOARD_SORT_ORDER];
71
+ type LeaderboardDisplayType = (typeof LEADERBOARD_DISPLAY_TYPE)[keyof typeof LEADERBOARD_DISPLAY_TYPE];
72
+ type UGCType = (typeof UGC_TYPE)[keyof typeof UGC_TYPE];
73
+ type UGCVisibility = (typeof UGC_VISIBILITY)[keyof typeof UGC_VISIBILITY];
37
74
  type LobbyUser = FunctionReturnType<typeof api.sdk.gameLobby.lobbyUsers>[0];
38
75
  type LobbyMessage = FunctionReturnType<typeof api.sdk.gameLobby.lobbyMessages>[0];
39
76
  type Lobby = FunctionReturnType<typeof api.sdk.gameLobby.listAvailable>[0];
40
77
  type LobbyJoinResponse = FunctionReturnType<typeof api.sdk.gameLobby.joinLobby>;
41
78
  type LobbyInvite = FunctionReturnType<typeof api.sdk.gameLobby.getLobbyInvites>[0];
42
79
  type Friend = FunctionReturnType<typeof api.sdk.friends.listFriends>[0];
43
- type UGCType = PublicApiType["sdk"]["userGeneratedContent"]["createUGCItem"]["_args"]["ugcType"];
44
- type UGCVisibility = PublicApiType["sdk"]["userGeneratedContent"]["createUGCItem"]["_args"]["visibility"];
45
- type LeaderboardSortOrder = PublicApiType["sdk"]["leaderboards"]["getOrCreateLeaderboard"]["_args"]["sortOrder"];
46
- type LeaderboardDisplayType = PublicApiType["sdk"]["leaderboards"]["getOrCreateLeaderboard"]["_args"]["displayType"];
47
80
  type Leaderboard = FunctionReturnType<typeof api.sdk.leaderboards.getLeaderboard>;
48
81
  type LeaderboardEntries = FunctionReturnType<typeof api.sdk.leaderboards.listEntriesAroundUser>["entries"];
49
82
  type UpsertedLeaderboardEntry = FunctionReturnType<typeof api.sdk.leaderboards.upsertLeaderboardEntry>["entry"] & {
50
83
  userId: GenericId<"users">;
51
84
  username: string;
52
85
  };
53
- type P2PTurnCredentials = FunctionReturnType<typeof api.sdk.turnCredentials.getOrCreate>;
54
- type P2PSignalingMessage = Omit<FunctionReturnType<typeof api.sdk.p2pSignaling.getSignalingMessages>[0], "data"> & {
55
- data: RTCSessionDescriptionInit | RTCIceCandidateInit;
56
- };
57
86
  type WavedashEvent = (typeof WavedashEvents)[keyof typeof WavedashEvents];
58
-
59
87
  interface WavedashConfig {
60
88
  debug?: boolean;
61
89
  remoteStorageOrigin?: string;
@@ -73,7 +101,7 @@ interface RemoteFileMetadata {
73
101
  }
74
102
  interface EngineInstance {
75
103
  type: (typeof GAME_ENGINE)[keyof typeof GAME_ENGINE];
76
- SendMessage(objectName: string, methodName: WavedashEvent, value?: string | number | boolean): void;
104
+ SendMessage(objectName: string, methodName: WavedashEvent, value?: string | number): void;
77
105
  FS: {
78
106
  readFile(path: string, opts?: Record<string, unknown>): string | Uint8Array;
79
107
  writeFile(path: string, data: string | ArrayBufferView, opts?: Record<string, unknown>): void;
@@ -85,11 +113,14 @@ interface EngineInstance {
85
113
  };
86
114
  unityPersistentDataPath?: string;
87
115
  }
88
- interface WavedashResponse<T> {
89
- success: boolean;
90
- data: T | null;
91
- message?: string;
92
- }
116
+ type WavedashResponse<T> = {
117
+ success: true;
118
+ data: T;
119
+ } | {
120
+ success: false;
121
+ data: null;
122
+ message: string;
123
+ };
93
124
  /** Payload for LobbyJoined event - emitted on successful lobby join or create */
94
125
  interface LobbyJoinedPayload {
95
126
  lobbyId: GenericId<"lobbies">;
@@ -97,23 +128,13 @@ interface LobbyJoinedPayload {
97
128
  users: LobbyUser[];
98
129
  metadata: Record<string, unknown>;
99
130
  }
100
- /** Reasons why a user was kicked from a lobby */
101
- declare const LobbyKickedReason: {
102
- readonly KICKED: "KICKED";
103
- readonly ERROR: "ERROR";
104
- };
105
- type LobbyKickedReason = (typeof LobbyKickedReason)[keyof typeof LobbyKickedReason];
131
+ type LobbyKickedReason = (typeof LobbyKickedReason$1)[keyof typeof LobbyKickedReason$1];
106
132
  /** Payload for LobbyKicked event - emitted when removed from a lobby */
107
133
  interface LobbyKickedPayload {
108
134
  lobbyId: GenericId<"lobbies">;
109
135
  reason: LobbyKickedReason;
110
136
  }
111
- /** Change types for lobby user updates */
112
- declare const LobbyUserChangeType: {
113
- readonly JOINED: "JOINED";
114
- readonly LEFT: "LEFT";
115
- };
116
- type LobbyUserChangeType = (typeof LobbyUserChangeType)[keyof typeof LobbyUserChangeType];
137
+ type LobbyUserChangeType = (typeof LobbyUserChangeType$1)[keyof typeof LobbyUserChangeType$1];
117
138
  /** Payload for LobbyUsersUpdated event - emitted when a user joins or leaves */
118
139
  interface LobbyUsersUpdatedPayload extends LobbyUser {
119
140
  changeType: LobbyUserChangeType;
@@ -155,11 +176,7 @@ interface P2PPeerReconnectedPayload {
155
176
  userId: GenericId<"users">;
156
177
  username: string;
157
178
  }
158
- /**
159
- * Reason a P2P packet was dropped. Each reason implies a different
160
- * game-side remedy.
161
- */
162
- type P2PPacketDropReason = "QUEUE_FULL" | "PAYLOAD_TOO_LARGE" | "INVALID_PAYLOAD_SIZE" | "INVALID_CHANNEL" | "MALFORMED" | "PEER_NOT_READY";
179
+ type P2PPacketDropReason = (typeof P2PPacketDropReason$1)[keyof typeof P2PPacketDropReason$1];
163
180
  /**
164
181
  * Payload for P2PPacketDropped event.
165
182
  *
@@ -185,6 +202,29 @@ interface BackendConnectionPayload {
185
202
  connectionCount: number;
186
203
  connectionRetries: number;
187
204
  }
205
+ /** Payload for FullscreenChanged event - emitted when fullscreen state flips */
206
+ interface FullscreenChangedPayload {
207
+ isFullscreen: boolean;
208
+ }
209
+ type WavedashEventMap = {
210
+ [WavedashEvents.LOBBY_MESSAGE]: LobbyMessagePayload;
211
+ [WavedashEvents.LOBBY_JOINED]: LobbyJoinedPayload;
212
+ [WavedashEvents.LOBBY_KICKED]: LobbyKickedPayload;
213
+ [WavedashEvents.LOBBY_USERS_UPDATED]: LobbyUsersUpdatedPayload;
214
+ [WavedashEvents.LOBBY_DATA_UPDATED]: LobbyDataUpdatedPayload;
215
+ [WavedashEvents.LOBBY_INVITE]: LobbyInvitePayload;
216
+ [WavedashEvents.P2P_CONNECTION_ESTABLISHED]: P2PConnectionEstablishedPayload;
217
+ [WavedashEvents.P2P_CONNECTION_FAILED]: P2PConnectionFailedPayload;
218
+ [WavedashEvents.P2P_PEER_DISCONNECTED]: P2PPeerDisconnectedPayload;
219
+ [WavedashEvents.P2P_PEER_RECONNECTING]: P2PPeerReconnectingPayload;
220
+ [WavedashEvents.P2P_PEER_RECONNECTED]: P2PPeerReconnectedPayload;
221
+ [WavedashEvents.P2P_PACKET_DROPPED]: P2PPacketDroppedPayload;
222
+ [WavedashEvents.STATS_STORED]: StatsStoredPayload;
223
+ [WavedashEvents.BACKEND_CONNECTED]: BackendConnectionPayload;
224
+ [WavedashEvents.BACKEND_DISCONNECTED]: BackendConnectionPayload;
225
+ [WavedashEvents.BACKEND_RECONNECTING]: BackendConnectionPayload;
226
+ [WavedashEvents.FULLSCREEN_CHANGED]: FullscreenChangedPayload;
227
+ };
188
228
  interface P2PPeer {
189
229
  userId: GenericId<"users">;
190
230
  username: string;
@@ -586,7 +626,7 @@ declare class GameEventManager {
586
626
  private sdk;
587
627
  private eventQueue;
588
628
  constructor(sdk: WavedashSDK);
589
- notifyGame(event: WavedashEvent, payload: string | number | boolean | object): void;
629
+ notifyGame(event: WavedashEvent, payload: string | number | object): void;
590
630
  private sendGameEvent;
591
631
  flushEventQueue(): void;
592
632
  }
@@ -654,9 +694,6 @@ declare class OverlayManager {
654
694
  * Implements friend-related methods for the Wavedash SDK
655
695
  */
656
696
 
657
- declare const AVATAR_SIZE_SMALL = 0;
658
- declare const AVATAR_SIZE_MEDIUM = 1;
659
- declare const AVATAR_SIZE_LARGE = 2;
660
697
  declare class FriendsManager {
661
698
  private sdk;
662
699
  private userCache;
@@ -673,9 +710,10 @@ declare class FriendsManager {
673
710
  userAvatarUrl?: string;
674
711
  }>): void;
675
712
  /**
676
- * Returns CDN URL with size transformation for a cached user's avatar
713
+ * Returns CDN URL with size transformation for a cached user's avatar.
677
714
  * @param userId - The user ID to get the avatar URL for
678
- * @param size - Avatar size constant (AVATAR_SIZE_SMALL, AVATAR_SIZE_MEDIUM, or AVATAR_SIZE_LARGE)
715
+ * @param size - Pixel size for width and height. Use a value from
716
+ * `AvatarSize` (SMALL=64, MEDIUM=128, LARGE=256) or any custom pixel size.
679
717
  * @returns CDN URL with size transformation, or null if user not cached or has no avatar
680
718
  */
681
719
  getUserAvatarUrl(userId: GenericId<"users">, size?: number): string | null;
@@ -764,6 +802,54 @@ declare class WavedashSDK extends EventTarget {
764
802
  readonly BACKEND_RECONNECTING: "BackendReconnecting";
765
803
  readonly FULLSCREEN_CHANGED: "FullscreenChanged";
766
804
  };
805
+ LobbyVisibility: {
806
+ readonly PUBLIC: 0;
807
+ readonly FRIENDS_ONLY: 1;
808
+ readonly PRIVATE: 2;
809
+ };
810
+ LeaderboardSortOrder: {
811
+ readonly ASC: 0;
812
+ readonly DESC: 1;
813
+ };
814
+ LeaderboardDisplayType: {
815
+ readonly NUMERIC: 0;
816
+ readonly TIME_SECONDS: 1;
817
+ readonly TIME_MILLISECONDS: 2;
818
+ readonly TIME_GAME_TICKS: 3;
819
+ };
820
+ UGCType: {
821
+ readonly SCREENSHOT: 0;
822
+ readonly VIDEO: 1;
823
+ readonly COMMUNITY: 2;
824
+ readonly GAME_MANAGED: 3;
825
+ readonly OTHER: 4;
826
+ };
827
+ UGCVisibility: {
828
+ readonly PUBLIC: 0;
829
+ readonly FRIENDS_ONLY: 1;
830
+ readonly PRIVATE: 2;
831
+ };
832
+ AvatarSize: {
833
+ readonly SMALL: 64;
834
+ readonly MEDIUM: 128;
835
+ readonly LARGE: 256;
836
+ };
837
+ LobbyKickedReason: {
838
+ readonly KICKED: "KICKED";
839
+ readonly ERROR: "ERROR";
840
+ };
841
+ LobbyUserChangeType: {
842
+ readonly JOINED: "JOINED";
843
+ readonly LEFT: "LEFT";
844
+ };
845
+ P2PPacketDropReason: {
846
+ readonly QUEUE_FULL: "QUEUE_FULL";
847
+ readonly PAYLOAD_TOO_LARGE: "PAYLOAD_TOO_LARGE";
848
+ readonly INVALID_PAYLOAD_SIZE: "INVALID_PAYLOAD_SIZE";
849
+ readonly INVALID_CHANNEL: "INVALID_CHANNEL";
850
+ readonly MALFORMED: "MALFORMED";
851
+ readonly PEER_NOT_READY: "PEER_NOT_READY";
852
+ };
767
853
  protected lobbyManager: LobbyManager;
768
854
  protected statsManager: StatsManager;
769
855
  protected heartbeatManager: HeartbeatManager;
@@ -795,6 +881,25 @@ declare class WavedashSDK extends EventTarget {
795
881
  * If deferEvents is true, call this manually after your pre-game setup is complete.
796
882
  */
797
883
  readyForEvents(): void;
884
+ private listenerWrappers;
885
+ /**
886
+ * Subscribe to a Wavedash event with a payload-typed listener.
887
+ * Returns an unsubscribe function.
888
+ *
889
+ * const unsubscribeLobbyJoined = Wavedash.on(Wavedash.Events.LOBBY_JOINED, (payload) => {
890
+ * // payload: LobbyJoinedPayload
891
+ * });
892
+ * unsubscribeLobbyJoined(); // later
893
+ */
894
+ on<K extends keyof WavedashEventMap>(event: K, listener: (payload: WavedashEventMap[K]) => void): () => void;
895
+ /**
896
+ * Remove a listener previously registered with {@link on}.
897
+ */
898
+ off<K extends keyof WavedashEventMap>(event: K, listener: (payload: WavedashEventMap[K]) => void): void;
899
+ addEventListener<K extends keyof WavedashEventMap>(type: K, listener: (ev: CustomEvent<WavedashEventMap[K]>) => void, options?: boolean | AddEventListenerOptions): void;
900
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
901
+ removeEventListener<K extends keyof WavedashEventMap>(type: K, listener: (ev: CustomEvent<WavedashEventMap[K]>) => void, options?: boolean | EventListenerOptions): void;
902
+ removeEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;
798
903
  loadScript(src: string): Promise<unknown>;
799
904
  updateLoadProgressZeroToOne(progress: number): void;
800
905
  loadComplete(): void;
@@ -845,7 +950,7 @@ declare class WavedashSDK extends EventTarget {
845
950
  * Get avatar URL for a cached user with size transformation.
846
951
  * Users are cached when seen via listFriends() or lobby membership.
847
952
  * @param userId - The user ID to get the avatar URL for
848
- * @param size - Avatar size constant (AVATAR_SIZE_SMALL=0, AVATAR_SIZE_MEDIUM=1, AVATAR_SIZE_LARGE=2)
953
+ * @param size - Avatar size constant (Wavedash.AvatarSize.SMALL=0, Wavedash.AvatarSize.MEDIUM=1, Wavedash.AvatarSize.LARGE=2)
849
954
  * @returns CDN URL with size transformation, or null if user not cached or has no avatar
850
955
  */
851
956
  getUserAvatarUrl(userId: GenericId<"users">, size?: number): string | null;
@@ -1048,7 +1153,12 @@ declare class WavedashSDK extends EventTarget {
1048
1153
  */
1049
1154
  private setupSessionEndListeners;
1050
1155
  }
1156
+ declare global {
1157
+ interface Window {
1158
+ Wavedash: WavedashSDK;
1159
+ }
1160
+ }
1051
1161
 
1052
1162
  declare function setupWavedashSDK(): WavedashSDK;
1053
1163
 
1054
- export { AVATAR_SIZE_LARGE, AVATAR_SIZE_MEDIUM, AVATAR_SIZE_SMALL, type BackendConnectionPayload, type EngineInstance, type Friend, type Leaderboard, type LeaderboardDisplayType, type LeaderboardEntries, type LeaderboardSortOrder, type Lobby, type LobbyDataUpdatedPayload, type LobbyInvite, type LobbyInvitePayload, type LobbyJoinResponse, type LobbyJoinedPayload, type LobbyKickedPayload, LobbyKickedReason, type LobbyMessage, type LobbyMessagePayload, type LobbyUser, LobbyUserChangeType, type LobbyUsersUpdatedPayload, type LobbyVisibility, type P2PConfig, type P2PConnection, type P2PConnectionEstablishedPayload, type P2PConnectionFailedPayload, type P2PMessage, type P2PPacketDropReason, type P2PPacketDroppedPayload, type P2PPeer, type P2PPeerDisconnectedPayload, type P2PPeerReconnectedPayload, type P2PPeerReconnectingPayload, type P2PSignalingMessage, type P2PTurnCredentials, type RemoteFileMetadata, type StatsStoredPayload, type UGCType, type UGCVisibility, type UpsertedLeaderboardEntry, type WavedashConfig, type WavedashEvent, WavedashEvents, type WavedashResponse, WavedashSDK, setupWavedashSDK };
1164
+ export { type BackendConnectionPayload, type EngineInstance, type Friend, type FullscreenChangedPayload, type Leaderboard, type LeaderboardDisplayType, type LeaderboardEntries, type LeaderboardSortOrder, type Lobby, type LobbyDataUpdatedPayload, type LobbyInvite, type LobbyInvitePayload, type LobbyJoinResponse, type LobbyJoinedPayload, type LobbyKickedPayload, type LobbyKickedReason, type LobbyMessage, type LobbyMessagePayload, type LobbyUser, type LobbyUserChangeType, type LobbyUsersUpdatedPayload, type LobbyVisibility, type P2PConfig, type P2PConnection, type P2PConnectionEstablishedPayload, type P2PConnectionFailedPayload, type P2PMessage, type P2PPacketDropReason, type P2PPacketDroppedPayload, type P2PPeer, type P2PPeerDisconnectedPayload, type P2PPeerReconnectedPayload, type P2PPeerReconnectingPayload, type RemoteFileMetadata, type StatsStoredPayload, type UGCType, type UGCVisibility, type UpsertedLeaderboardEntry, type WavedashConfig, type WavedashEvent, type WavedashEventMap, type WavedashResponse, WavedashSDK, setupWavedashSDK };