new Network(gameId: string, options?: NetworkOptions)gameId: A unique identifier for your game. Can be a UUID or your Poki game ID.options: (Optional) Configuration optionsinterface NetworkOptions { signalingServer?: string; // Custom signaling server URL stunServer?: string; // Custom STUN server URL turnServer?: string; // Custom TURN server URL }
Creates a new lobby.
interface LobbyOptions {
public?: boolean; // Make lobby visible in listings
maxPlayers?: number; // Maximum number of players allowed
password?: string; // Optional password protection
customData?: any; // Custom lobby data
canUpdateBy?: 'anyone' | 'leader' | 'creator'; // Who can update lobby settings
}Joins an existing lobby.
Lists available lobbies with optional MongoDB-style filtering.
interface Lobby {
code: string; // Lobby identifier
playerCount: number; // Current number of players
public: boolean; // Whether lobby is listed
customData: any; // Custom lobby data
createdAt: Date; // Creation timestamp
updatedAt: Date; // Last update timestamp
leader: string; // Current leader's peer ID
canUpdateBy: string; // Who can update settings
creator: string; // Creator's peer ID
hasPassword: boolean; // Password protection status
maxPlayers: number; // Player limit
}Sends data to a specific peer.
channel: Either 'reliable' or 'unreliable'peerId: Target peer's IDdata: Data to send (string, object, or ArrayBuffer)
Sends data to all connected peers.
Disconnects everything and cleans up resources.
Subscribe to events using network.on(eventName, callback):
'ready': Network is ready to create/join lobbies'error': Network error occurred'connected': New peer connected'disconnected': Peer disconnected'rtcerror': WebRTC error occurred (callback receivesRTCErrorEvent)
'lobby': Lobby created/joined'leave': Left lobby'update': Lobby settings updated
'message': Received data from peer
interface Peer {
id: string; // Unique peer identifier
latency?: {
last: number; // Most recent latency measurement (in ms)
average: number; // Average latency over time
jitter: number; // Variation in latency
max: number; // Maximum observed latency
min: number; // Minimum observed latency
};
}