Reference · Media
media.close
media.close(str) -> boolWhat it does
Ends a stream by name: it stops taking RTP, lets its ports go (waiting up to a second
for that, so another stream can take them at once), stops taking frames from pages
sending it, and tells the pages watching, whose <quillo-media> turns data-state
ended. It gives true if there was such a stream, false otherwise. Code run for a
page or a request ends its tenant's stream of that name; a job, a tick and the top level
end every tenant's (since 0.7).
Examples
media.rtp("cam", { video: 45004 })print(media.close("cam"))print(media.close("cam"))truefalseroute POST /rooms/:id/end { media.close(`room:${id}`) redirect("/rooms")}Edge cases
- Closing a name that is not a stream, or one closed already, gives false, not an error.
- The ports are free again: a stream of another name may take them right after.
- A page that was watching stays
endeduntil it reconnects, even if a stream of that name is made again. - The stream's name is not checked for its letters: any string asks, and an unknown one is false.
- A tenant's request cannot end another tenant's stream, nor the program's RTP stream its pages watch for want of one of their own: it gives false.
print(media.close("never-made"))media.rtp("a", { video: 45004 })print(media.close("a"))media.rtp("b", { video: 45004 })print(media.close("b"), media.close("a"))print(media.close("not a name!"))falsetruetrue falsefalseErrors
A name that is not a string, or no argument, is a runtime error. There are no error values.
print(media.close(1))line 1: `media.close` takes a stream's name, got 1Chaining
The name is its only argument, so a list of names can be closed with map; the bool
says which were there.
media.rtp("x", { video: 45004 })media.rtp("y", { video: 45006 })print(["x", "y", "z"] | map(media.close))print(media.streams())[true, true, false][]See also
media.rtp, media.streams, media.on
Thread 0 posts
On media.close(): 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