Reference · Channels

channel.peers

signature
channel.peers(str) -> list

What it does

The ids of the pages in a channel, as a list of twelve-character hex strings, in a fixed order. An id names a page's connection (a page that reconnects has a new one) and is what channel.send takes. This is the only list of who is present: what a join or leave handler records is the rest. Code run for a page or a request lists its tenant's room (a page with no tenant, the room of no tenant); a job, a tick and the top level list every tenant's (since 0.7: every page, to anyone).

Examples

in a program
channel.on("chat", (msg, peer) => {    for id in channel.peers("chat") {        if id != peer.id { channel.send("chat", id, { from: peer.id, text: msg.text }) }    }})

With no page there, the list is empty:

print(channel.peers("game"))print(len(channel.peers("game")))
output
[]0

Edge cases

print(channel.peers("nobody-here"))print(channel.peers("room:1.a-b_c") == [])
output
[]true

Errors

A name that is not a string, or not a channel name (letters, digits, _, -, . and :, at most 64 characters), is a runtime error.

this one fails
print(channel.peers())
output
line 1: `channel.peers` takes a channel's name first, got nothing
this one fails
print(channel.peers("bad name"))
output
line 1: `channel.peers`: a channel's name is letters, digits, `_`, `-`, `.` and `:`, up to 64, got "bad name"

Chaining

The name is its only argument, so name | channel.peers | len counts the pages, and map sends to each.

print("game" | channel.peers | len)print(channel.peers("game") | map((id) => channel.send("game", id, "hi")))
output
0[]

See also

channel.send, channel.broadcast, channel.on, len

Thread
7Useful? Like it, or add to its thread below.

Thread 0 posts

On channel.peers(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo