onPlayerJoin

The callback first runs for all existing players, then for any new players that join. This is useful for “catching up” a new player with existing players or getting the full list in a new game scene.

Signature

function onPlayerJoin(callback: (player: PlayerState) => void): void

Parameters

NameTypeDescription
callback(player: PlayerState) => voidFunction called with the PlayerState object of the joining player.

Usage

onPlayerJoin((player) => {
  console.log(`${player.id} joined!`);
});