Reference · Media

media.streams

signature
media.streams() -> list

What 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")
output
[{ name: "cam", viewers: 0, video: { frames: 0, fps: 0, kbps: 0, lost: 0 }, audio: { frames: 0, fps: 0, kbps: 0, lost: 0 } }]
in a program
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

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())
output
[]["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() == [])
output
true

Chaining

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")
output
00

See also

media.rtp, media.close, media.on, channel.peers

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

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