WavedashDocs

Events reference

Events emitted by the Wavedash SDK

The SDK emits events when things happen — a player joins a lobby, a peer connects, the backend goes offline. Your game listens for these to react in real time.

Listening for events

WavedashSDK.lobby_joined.connect(_on_lobby_joined)
WavedashSDK.lobby_message.connect(_on_lobby_message)
WavedashSDK.p2p_connection_established.connect(_on_peer_connected)
WavedashSDK.backend_connected.connect(_on_backend_connected)

In JavaScript, event data is on e.detail. In Godot and Unity, it's passed directly as a Dictionary.

Lobby events

EventFires whenPayload
LOBBY_JOINEDYou join or create a lobbylobbyId, hostId, users, metadata
LOBBY_USERS_UPDATEDA user joins or leaveslobbyId, userId, username, userAvatarUrl, isHost, changeType ("JOINED" or "LEFT")
LOBBY_MESSAGEA chat message arrivesmessageId, lobbyId, userId, username, message, timestamp
LOBBY_DATA_UPDATEDLobby metadata changesThe full metadata object
LOBBY_KICKEDYou're removed from the lobbylobbyId, reason ("KICKED" or "ERROR")
LOBBY_INVITEYou receive a lobby invitenotificationId, lobbyId, sender (object with _id, username, avatarUrl), _creationTime

P2P events

EventFires whenPayload
P2P_CONNECTION_ESTABLISHEDA peer connection is readyuserId, username
P2P_CONNECTION_FAILEDA peer connection failsuserId, username, error
P2P_PEER_DISCONNECTEDA peer disconnectsuserId, username

Stats events

EventFires whenPayload
STATS_STOREDStats are persisted to the serversuccess, message (optional)

Backend events

EventFires whenPayload
BACKEND_CONNECTEDConnected to WavedashisConnected, hasEverConnected, connectionCount, connectionRetries
BACKEND_DISCONNECTEDLost connectionSame as above
BACKEND_RECONNECTINGAttempting to reconnectSame as above

Event constants

All event names are available as WavedashJS.Events:

WavedashJS.Events.LOBBY_JOINED           // "LobbyJoined"
WavedashJS.Events.LOBBY_USERS_UPDATED    // "LobbyUsersUpdated"
WavedashJS.Events.LOBBY_MESSAGE          // "LobbyMessage"
WavedashJS.Events.LOBBY_DATA_UPDATED     // "LobbyDataUpdated"
WavedashJS.Events.LOBBY_KICKED           // "LobbyKicked"
WavedashJS.Events.LOBBY_INVITE           // "LobbyInvite"
WavedashJS.Events.P2P_CONNECTION_ESTABLISHED  // "P2PConnectionEstablished"
WavedashJS.Events.P2P_CONNECTION_FAILED       // "P2PConnectionFailed"
WavedashJS.Events.P2P_PEER_DISCONNECTED      // "P2PPeerDisconnected"
WavedashJS.Events.STATS_STORED           // "StatsStored"
WavedashJS.Events.BACKEND_CONNECTED      // "BackendConnected"
WavedashJS.Events.BACKEND_DISCONNECTED   // "BackendDisconnected"
WavedashJS.Events.BACKEND_RECONNECTING   // "BackendReconnecting"

Deferring events

If your game needs time to load before handling events, pass deferEvents: true to init(). The SDK queues all events until you call readyForEvents().

WavedashJS.init({ deferEvents: true });

// set up listeners, load assets, etc.

WavedashJS.readyForEvents(); // flush the queue