Skip to content

KcdMp.feed.session.subscribe

Registers a function that receives the connection and the player.

fn(session) is called with the latest value at once when there is one, and again whenever it changes: when the player has joined the server, and about every five seconds while the round-trip time moves. The value never holds anything that is private to the player’s game - it is the server’s name and address, the level, and the player’s id, name and ping.

The frame must list session in its feeds in ui.toml.

KcdMp.feed.session.subscribe(fn)
Parameter Type
fn (session: KcdMpSessionFeed) => void called with each value

() => void - a function that takes the handler off again

The connection and the player, as the session feed carries them.

Field Type
server string the server’s name
address string host:port as the player connected to it
level string the level the server runs
playerId number the player’s id on the server - the game mode’s pid
name string the player’s name
rtt number the round-trip time to the server in milliseconds, 0 until it has been measured
const off = KcdMp.feed.session.subscribe((session) => {
document.querySelector("#who").textContent = session.name + " on " + session.server;
document.querySelector("#ping").textContent = session.rtt + " ms";
});

KcdMp.feed · KcdMp.feed.visibility.subscribe · the Feeds group of the index