Back end
Calls
Back end
calls.md

Calls

Examplea whole program
// Who may be in a room's call: here, anyone in the lobby and nobody anywhere else.
server call(room: string): bool = room == "lobby"
state call: call? = none
state name = "Guest"
state notes: string[] = []
action join
call = rtc.join("lobby", {audio: true, video: true, name, levels: true})?
action leave
call?.leave()
call = none
action mute
if call
call.mute(call.me.audio)?
action camera
if call
call.camera(!call.me.video)?
action share
if call
call.share(!call.me.screen)?
action wave
call?.send({wave: name})
on rtc.message(m: {room: string, from: string, data: json})
notes.push(`${call?.peers?.find(p => p.id == m.from)?.name ?? "someone"} waved`)
component Tile(who: peer)
column gap=6 padding=8 border-radius=12 background=card border=(who.speaking ? "2px solid #0a84ff" : "2px solid transparent")
if who.video
video of=who width=224 border-radius=8
else
row width=224 height=126 align-items=center justify-content=center background=line border-radius=8
text who.name.slice(0, 1) font-size=40
if who.screen
video of=who screen width=224 border-radius=8
row gap=6 align-items=center
text (who.me ? `${who.name} (you)` : who.name)
if !who.audio
icon "mic-off" size=14
if who.state != "connected"
text who.state color=dim font-size=12
column gap=12 padding=16
if call
row gap=8 flex-wrap=wrap
Tile who=call.me
for p in call.peers key=p.id
Tile who=p
row gap=8
button (call.me.audio ? "Mute" : "Unmute") press=mute
button (call.me.video ? "Camera off" : "Camera on") press=camera
button (call.me.screen ? "Stop sharing" : "Share screen") press=share
button "Wave" press=wave
button "Leave" press=leave
text (call.error ?? failure(mute) ?? failure(camera) ?? failure(share) ?? "") color=danger
for n in notes
text n color=dim
else
row gap=8
input value=name placeholder="Your name"
button "Join the call" press=join disabled=pending(join)
text (failure(join) ?? "") color=danger

Mental model#

The guard: server call#

Joining: rtc.join#

The call#

A peer#

video of=#

Messages#

Proving the peers: verify#

Ringing#

Examplea whole program
server call(room: string): bool = auth.me()? != none
state call: call? = none
state who = ""
action start
call = rtc.join("team", {audio: true})?
// The one calling, in the call: offers it to an account.
action ringThem
call?.ring([who])
// Answering is joining the room, with whatever the page brings.
action answer(room: string)
call = rtc.join(room, {audio: true})?
action no(id: string)
rtc.decline(id)
column gap=8 padding=16
if call
input value=who placeholder="An account's id"
button "Ring" press=ringThem
for r in call.rings key=r.user
text `${r.user}: ${r.state}`
else
button "Start a call" press=start
// On any page of the app: the calls offered to this person now.
for r in rtc.rings() key=r.id
row gap=8
text `${r.name} is calling`
button "Answer" press=answer(r.room)
button "Decline" press=no(r.id)
Examplea whole program
server call(room: string): bool = auth.me()? != none
state call: call? = none
state who = ""
action allow
notify.enable()?
action start
call = rtc.join("team", {audio: true})?
// Answer, on a device, opens the app at this address (or brings its window forward).
action ringThem
call?.ring([who], {url: "/#/call/team"})
// …and this window is told: it joins.
on rtc.answer(r: {id: string, room: string, from: string, name: string})
call = rtc.join(r.room, {audio: true})?
column gap=8 padding=16
button "Ring me on my devices" press=allow
if call
input value=who placeholder="An account's id"
button "Ring" press=ringThem
else
button "Start a call" press=start
for r in rtc.rings() key=r.id
text `${r.name} is calling`

Devices#

What the runtime takes care of#

How many#

Deploying#

Only through a relay: relay#

More than one process#

Pitfalls#

The wire#

Where a new call goes#

In the source#

esc
1072 sections of 111 pages, ranked as you type.A heading's words count for more than what stands under it.
↑↓move
↵open
ranked by BM25, in the page