@wvdsh/sdk-js 1.2.4 → 1.3.1

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;
@@ -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
  *
@@ -189,6 +206,25 @@ interface BackendConnectionPayload {
189
206
  interface FullscreenChangedPayload {
190
207
  isFullscreen: boolean;
191
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
+ };
192
228
  interface P2PPeer {
193
229
  userId: GenericId<"users">;
194
230
  username: string;
@@ -658,9 +694,6 @@ declare class OverlayManager {
658
694
  * Implements friend-related methods for the Wavedash SDK
659
695
  */
660
696
 
661
- declare const AVATAR_SIZE_SMALL = 0;
662
- declare const AVATAR_SIZE_MEDIUM = 1;
663
- declare const AVATAR_SIZE_LARGE = 2;
664
697
  declare class FriendsManager {
665
698
  private sdk;
666
699
  private userCache;
@@ -677,9 +710,10 @@ declare class FriendsManager {
677
710
  userAvatarUrl?: string;
678
711
  }>): void;
679
712
  /**
680
- * 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.
681
714
  * @param userId - The user ID to get the avatar URL for
682
- * @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.
683
717
  * @returns CDN URL with size transformation, or null if user not cached or has no avatar
684
718
  */
685
719
  getUserAvatarUrl(userId: GenericId<"users">, size?: number): string | null;
@@ -768,6 +802,54 @@ declare class WavedashSDK extends EventTarget {
768
802
  readonly BACKEND_RECONNECTING: "BackendReconnecting";
769
803
  readonly FULLSCREEN_CHANGED: "FullscreenChanged";
770
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
+ };
771
853
  protected lobbyManager: LobbyManager;
772
854
  protected statsManager: StatsManager;
773
855
  protected heartbeatManager: HeartbeatManager;
@@ -789,9 +871,11 @@ declare class WavedashSDK extends EventTarget {
789
871
  overlayManager: OverlayManager;
790
872
  private gameplayJwt;
791
873
  private gameplayJwtPromise;
874
+ private setupWarningTimeout;
792
875
  ugcHost: string;
793
876
  uploadsHost: string;
794
877
  constructor(sdkConfig: SDKConfig);
878
+ private clearSetupWarning;
795
879
  init(config?: WavedashConfig): boolean;
796
880
  /**
797
881
  * Signal that the game is ready to receive events (LobbyJoined, LobbyMessage, etc).
@@ -799,6 +883,25 @@ declare class WavedashSDK extends EventTarget {
799
883
  * If deferEvents is true, call this manually after your pre-game setup is complete.
800
884
  */
801
885
  readyForEvents(): void;
886
+ private listenerWrappers;
887
+ /**
888
+ * Subscribe to a Wavedash event with a payload-typed listener.
889
+ * Returns an unsubscribe function.
890
+ *
891
+ * const unsubscribeLobbyJoined = Wavedash.on(Wavedash.Events.LOBBY_JOINED, (payload) => {
892
+ * // payload: LobbyJoinedPayload
893
+ * });
894
+ * unsubscribeLobbyJoined(); // later
895
+ */
896
+ on<K extends keyof WavedashEventMap>(event: K, listener: (payload: WavedashEventMap[K]) => void): () => void;
897
+ /**
898
+ * Remove a listener previously registered with {@link on}.
899
+ */
900
+ off<K extends keyof WavedashEventMap>(event: K, listener: (payload: WavedashEventMap[K]) => void): void;
901
+ addEventListener<K extends keyof WavedashEventMap>(type: K, listener: (ev: CustomEvent<WavedashEventMap[K]>) => void, options?: boolean | AddEventListenerOptions): void;
902
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
903
+ removeEventListener<K extends keyof WavedashEventMap>(type: K, listener: (ev: CustomEvent<WavedashEventMap[K]>) => void, options?: boolean | EventListenerOptions): void;
904
+ removeEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;
802
905
  loadScript(src: string): Promise<unknown>;
803
906
  updateLoadProgressZeroToOne(progress: number): void;
804
907
  loadComplete(): void;
@@ -849,7 +952,7 @@ declare class WavedashSDK extends EventTarget {
849
952
  * Get avatar URL for a cached user with size transformation.
850
953
  * Users are cached when seen via listFriends() or lobby membership.
851
954
  * @param userId - The user ID to get the avatar URL for
852
- * @param size - Avatar size constant (AVATAR_SIZE_SMALL=0, AVATAR_SIZE_MEDIUM=1, AVATAR_SIZE_LARGE=2)
955
+ * @param size - Avatar size constant (Wavedash.AvatarSize.SMALL=0, Wavedash.AvatarSize.MEDIUM=1, Wavedash.AvatarSize.LARGE=2)
853
956
  * @returns CDN URL with size transformation, or null if user not cached or has no avatar
854
957
  */
855
958
  getUserAvatarUrl(userId: GenericId<"users">, size?: number): string | null;
@@ -1052,7 +1155,12 @@ declare class WavedashSDK extends EventTarget {
1052
1155
  */
1053
1156
  private setupSessionEndListeners;
1054
1157
  }
1158
+ declare global {
1159
+ interface Window {
1160
+ Wavedash: WavedashSDK;
1161
+ }
1162
+ }
1055
1163
 
1056
1164
  declare function setupWavedashSDK(): WavedashSDK;
1057
1165
 
1058
- export { AVATAR_SIZE_LARGE, AVATAR_SIZE_MEDIUM, AVATAR_SIZE_SMALL, 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, 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 };
1166
+ 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 };