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.
Syntax
Section titled “Syntax”KcdMp.feed.session.subscribe(fn)| Parameter | Type | |
|---|---|---|
fn |
(session: KcdMpSessionFeed) => void |
called with each value |
Returns
Section titled “Returns”() => void - a function that takes the handler off again
KcdMpSessionFeed
Section titled “KcdMpSessionFeed”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 |
Example
Section titled “Example”const off = KcdMp.feed.session.subscribe((session) => { document.querySelector("#who").textContent = session.name + " on " + session.server; document.querySelector("#ping").textContent = session.rtt + " ms";});See also
Section titled “See also”KcdMp.feed · KcdMp.feed.visibility.subscribe · the Feeds group of the index
