Reference · Media
media.streams
media.streams() -> listWhat it does
Every stream, by name: a list of { name, viewers, video: { frames, fps, kbps, lost }, audio: { frames, fps, kbps, lost } }, sorted by name. viewers is this server's
pages watching; fps and kbps are the rate over the last while, and 0 after 3 s
without frames; lost counts packets that never came. A stream is one
media.rtp made, or one a page has sent a frame of. Code
run for a page or a request lists its tenant's streams and the program's RTP ones; a
job, a tick and the top level list every tenant's (since 0.7: every stream, to
anyone).
Examples
media.rtp("cam", { video: 45004, audio: 45006 })print(media.streams())media.close("cam")[{ name: "cam", viewers: 0, video: { frames: 0, fps: 0, kbps: 0, lost: 0 }, audio: { frames: 0, fps: 0, kbps: 0, lost: 0 } }]route GET /admin/streams = <table> {for s in media.streams() => <tr><td>{s.name}</td><td>{s.viewers}</td><td>{s.video.fps} fps</td></tr>}</table>Edge cases
- With no stream, the list is empty.
- A closed stream is gone from the list at once.
- A stream with only an audio port has a
videoentry too, all zeros. - The order is by name, however the streams were made.
- Each tenant has its own streams of a name, so a job may list
call:42twice: acme's and evil's.
print(media.streams())media.rtp("mic", { audio: 45008 })media.rtp("cam", { video: 45004 })print(media.streams() | map((s) => s.name))print(media.streams() | first | get("video"))print(media.close("cam"), media.close("mic"), media.streams())[]["cam", "mic"]{ frames: 0, fps: 0, kbps: 0, lost: 0 }true true []Errors
It takes no arguments and cannot fail; there are no error values.
print(media.streams() == [])trueChaining
The list pipes into map, filter and find, as any list does.
media.rtp("cam", { video: 45004 })print(media.streams() | find((s) => s.name == "cam") | get("viewers"))print(media.streams() | filter((s) => s.viewers > 0) | len)media.close("cam")00See also
media.rtp, media.close, media.on, channel.peers
Thread 0 posts
On media.streams(): 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