Reference · Channels
channel.peers
channel.peers(str) -> listWhat 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
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")))[]0Edge cases
- A channel nobody joined, and one no
channel.onhandles, give[], not an error. - The ids are connections, not people: one visitor with two tabs is two ids, and a reconnected page a new one.
- The list is of this server's pages: behind a balancer, another server's pages are not in it.
with_tenant(name, () => channel.peers("chat"))lists one tenant's room from a job.
print(channel.peers("nobody-here"))print(channel.peers("room:1.a-b_c") == [])[]trueErrors
A name that is not a string, or not a channel name (letters, digits, _, -, .
and :, at most 64 characters), is a runtime error.
print(channel.peers())line 1: `channel.peers` takes a channel's name first, got nothingprint(channel.peers("bad name"))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")))0[]See also
channel.send, channel.broadcast, channel.on, len
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