Voice guide
A bot can sit in a voice room and send (and receive) audio, just like a person. A lodge's voice runs one of two ways:
LiveKit: everyone in a room connects to Yuva's media server, a LiveKit server. The bot asks the Bot API for a short-lived room ticket and joins as an ordinary LiveKit participant; any LiveKit client library works.
Mesh (lodges not moved yet, self-hosted servers without LiveKit): every pair of people in the room has its own WebRTC peer connection, and the server only relays the signalling. See the mesh below.
Every seat in the peer list says which one with sfu (true = LiveKit). The server decides; a client cannot choose.
The SDKs do all of this for you and pick the right path by themselves (Python, TypeScript, JavaScript): use yuva-bot 2.0.0 (JavaScript) or yuva-bot 0.2.0 (Python) or newer. Read on if you want to know what happens or write your own client.
2026-11-12: LiveKit voice. Lodges whose voice moves to LiveKit no longer take mesh clients. A bot that joins without
"sfu": truegets HTTP 409 ("Bu sunucunun sesi LiveKit üzerinden. yuva-bot 2.0.0 (JS) veya 0.2.0 (Python) gerekir."). Custom clients written to the old offer/answer and m-line contract stop working in those lodges at once; there is no grace period. Update the SDK, or add the LiveKit path below to your client.
Rights#
Joining needs the speak right in that voice room (after room overrides). A moderator can mute the bot (modMuted: true in the peer list: others stop hearing it), move it to another room, or disconnect it; taking away speak or removing the bot from the lodge also drops its seat.
Lifecycle#
POST /lodges/{lodgeId}/voice/join{ channelId, sfu: true }. The response lists the room's peers, including the bot.sfu: truesays your client can do LiveKit; send it even if you only expect mesh lodges, so your client keeps working when a lodge moves.POST /lodges/{lodgeId}/voice/media. The answer is{ "media": { "url", "token", "room", "expiresAt" } }in a LiveKit lodge,{ "media": null }in a mesh lodge.LiveKit: connect to
media.urlwithmedia.tokenand publish one microphone track (below). Mesh: follow the mesh.Every 5 seconds:
POST /lodges/{lodgeId}/voice/beat{ channelId, muted, deafened, sfu: true }. The response is the current peer list. A seat without a beat for 20 seconds is dropped, also while the LiveKit connection is up: the beat holds the seat, LiveKit only carries the sound.POST /lodges/{lodgeId}/voice/leavewhen done, and disconnect from LiveKit (or close every peer connection).
If a beat answers with an error ("Bir yetkili seni sesten çıkardı.", "Bu odada konuşamazsın.", "Bu sunucuda değilsin.", "Başka bir cihazdan sese bağlandın."), the seat is gone: disconnect and stop. A 409 means the lodge's voice runs on LiveKit and the beat or join lacked "sfu": true. A moderator's move shows up as the bot's own peer entry having a different channelId: follow it by joining with the new channelId (and, in a LiveKit lodge, asking /voice/media again for the new room's ticket).
If the bot's own seat ever shows an sfu different from what its last /voice/media answer said, the lodge has switched: ask /voice/media again and move to the other path.
A bot has one seat per lodge. If it may run more than one process with the same token, send the same random session string (up to 100 characters) in every join, beat, media, drain, signals and leave body of one process. A join with a new session takes the seat over: the old process's beats then fail with "Başka bir cihazdan sese bağlandın." and it must stop, not rejoin. Both use the bot's user id as LiveKit identity, so when the new process connects to the room the old one is in, LiveKit closes the old connection (disconnect reason DUPLICATE_IDENTITY). Without session there is no such check.
LiveKit#
The ticket from /voice/media is a LiveKit access token for one room (media.room), valid to connect until media.expiresAt (ms since the epoch; about two minutes). Once connected the LiveKit client renews it itself; ask /voice/media again only for a new connection: after a move, a dropped connection, or a lodge switch.
Identity is the bot's user id, the participant name its display name.
What the token allows: subscribing, and publishing one source, the microphone. Camera and screen tracks are refused for bots. Don't set metadata.
Publish a single audio track with source
microphone: Opus, 48 kHz; mono is plenty. The app plays every participant's microphone track as their voice.Muting: unpublish the track (or mute it) while you send nothing, and send
muted: truein beats so people see the mic-off icon. The SDKs publish only while a file is playing.Moderator mute: the server takes the publish right away (
modMuted: truein the peer list) and the server drops your track; publishing fails until the mute is lifted. Wait formodMuted: falsebefore publishing again.Move, disconnect, removal: the server removes the participant from the room. Beat right away: an error means the seat is gone, a different
channelIdmeans a move (join it, ask a new ticket, connect). If the seat is still where it was, the connection merely dropped: ask a new ticket and reconnect.Listening: the token allows subscribing to the room's audio, if your bot wants to hear it. Send
deafened: falsein beats then; the SDKs never listen and saydeafened: true.
/voice/signals and /voice/drain play no part in a LiveKit lodge; there is nothing to send and nothing arrives.
The mesh#
In a mesh lodge (/voice/media answered null):
GET /voice/icefor the ICE servers. TURN credentials expire (expiresAt); fetch again for new connections after that.Use each beat's peer list to open links to newcomers and close links to people who left.
About every 500 ms (1–2 s once links are up):
POST /lodges/{lodgeId}/voice/drain{ channelId, ack }and handle the signals in order, then send their ids asackon the next drain.
Signals#
POST /lodges/{lodgeId}/voice/signals { channelId, toId, kind, payload }, where payload is a JSON string:
| kind | payload |
|---|---|
offer | { "type": "offer", "sdp": "…", "gen": 123456 } |
answer | { "type": "answer", "sdp": "…", "gen": 123456 } |
ice | { "candidate": "candidate:…", "sdpMid": "0", "sdpMLineIndex": 0, "usernameFragment": "…", "gen": 123456 } |
watch | "true" / "false": screen-share viewers only; a bot can ignore it. |
gen names one peer connection ("link"): whoever makes the offer picks a random integer from 1 to 2147483647, the answer and every ICE candidate of that link repeat it. Drop answers and candidates whose gen is not the current link's.
Who dials whom#
Joining: whoever joins dials (sends an offer to) everyone already in the room.
Someone joins after you: they dial you; answer. If no offer came within ~5 seconds, the app dials you itself.
Every offer starts a fresh link. Links never renegotiate: on an offer, close any existing connection to that peer and answer with a new one.
Glare (both sides offered at once): the side with the lower user id (plain string comparison) is polite. If you have an unanswered offer out to a peer and an offer from them arrives: when your id is greater, ignore their offer (they will take yours); when it is lower, drop your link and answer theirs.
Media layout#
The app's offers carry these m-lines, in order: microphone audio, a negotiated data channel ("yuva", id 0), screen video, screen sound audio, camera video. They are all bundled on the first m-line's transport (a=group:BUNDLE; ICE candidates come for that m-line only, and from Firefox the others are a=bundle-only with port 0), so answer with BUNDLE, as the SDKs do. When you answer, put your audio on the first audio transceiver (the microphone slot) and leave the rest receive-only or inactive. When you offer, a single audio transceiver is enough: the app treats it as your microphone. Make it sendrecv, even if you ignore what you receive: the app adds its microphone before it applies your offer, and the browser files a sendonly m-line under a second audio slot (screen sound), which it never plays. Opus is the codec.
Muting#
Send muted: true in beats while you are not playing anything (others see the mic-off icon), false while you speak. deafened tells people the bot does not listen.