Reference · Media

media.close

signature
media.close(str) -> bool

What 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"))
output
truefalse
in a program
route POST /rooms/:id/end {    media.close(`room:${id}`)    redirect("/rooms")}

Edge cases

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!"))
output
falsetruetrue falsefalse

Errors

A name that is not a string, or no argument, is a runtime error. There are no error values.

this one fails
print(media.close(1))
output
line 1: `media.close` takes a stream's name, got 1

Chaining

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())
output
[true, true, false][]

See also

media.rtp, media.streams, media.on

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

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