polite-dog-12152
08/13/2025, 12:52 PMtall-airline-16756
08/13/2025, 12:52 PMtall-airline-16756
08/13/2025, 12:53 PMRoom
class. Let me walk you through how you can set it up:
1. Keep an Ear Out for These Events:
◦ `disconnected`: This one pops up when the room disconnects. Just use room.on("disconnected")
to catch it.
◦ `reconnecting`: This fires when the SDK is trying to reconnect. Handle it with room.on("reconnecting")
.
◦ `reconnected`: When the room successfully reconnects, this event is triggered. Use room.on("reconnected")
for that.
1. *Here’s a Sample to Get You Started:*`import asyncio
import logging
from livekit import rtc
room = rtc.Room()
@room.on("disconnected")
def on_disconnected(reason):
logging.info(f"Disconnected from room: {reason}")
@room.on("reconnecting")
def on_reconnecting():
logging.info("Attempting to reconnect...")
@room.on("reconnected")
def on_reconnected():
logging.info("Reconnected to the room")
async def main():
token = generate_your_token()
await room.connect("ws://your-livekit-server:7880", token)
# Your application logic here
await asyncio.sleep_forever()
if name == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.run(main())`
2. A Few Friendly Tips:
◦ The disconnected
event comes with a reason
parameter, so you know exactly why the connection dropped—super handy for logging or debugging.
◦ When reconnecting
fires, it’s a great moment to let your users know you’re working on getting them back online.
◦ And once reconnected
happens, you can update your UI so everyone knows things are back to normal.
By using these events, you’re making sure your app handles disconnections smoothly and keeps your users in the loop, which is always a win!
Sources: livekit-rtc/livekit/rtc/_proto/room_pb2.pyipolite-dog-12152
08/13/2025, 12:53 PMtall-airline-16756
08/13/2025, 12:54 PMDeleteRoom
API to delete the room, which will disconnect everyone inside. Here’s a quick example in Go:
_, _ = roomClient.DeleteRoom(context.Background(), &livekit.DeleteRoomRequest{
Room: "myroom",
})
2. Automatic Disconnection:
Set the room’s EmptyTimeout
so it automatically closes after being empty for a bit. This way, the room shuts down when no participants are around.
Both of these options help make sure the room closes properly and frees up resources when it’s empty. If you want a hand setting any of this up, just let me know—I’m happy to help!
Sources: pkg/rtc/room.go | Managing rooms | LiveKit Docs | Rust SDKs | livekit/livekit_composite | DeepWiki | src/room/Room.ts | Sources/LiveKit/Core/Room.swiftpolite-dog-12152
08/13/2025, 12:56 PMtall-airline-16756
08/13/2025, 12:57 PMRoomEvent.TranscriptionReceived
event in your app to grab those transcription segments as they come in.
2. Set Up Database Schema:
You’ll want to create a database schema to hold your transcription data. For example, in SQLite:
CREATE TABLE participants (
id TEXT PRIMARY KEY,
identity TEXT NOT NULL,
name TEXT
);
CREATE TABLE transcriptions (
id TEXT PRIMARY KEY,
participant_id TEXT NOT NULL,
segment_id TEXT NOT NULL,
text TEXT NOT NULL,
language TEXT,
final BOOLEAN,
first_received_time INTEGER,
last_received_time INTEGER,
FOREIGN KEY(participant_id) REFERENCES participants(id)
);
3. Implement Custom Function:
Next, write a function that processes and saves the transcription data to your database. Here’s an example in JavaScript:
`async function storeTranscription(transcription) {
const db = new sqlite3.Database('transcriptions.db');
await db.run(CREATE TABLE IF NOT EXISTS participants (id TEXT PRIMARY KEY, identity TEXT NOT NULL, name TEXT)
);
await db.run(CREATE TABLE IF NOT EXISTS transcriptions (id TEXT PRIMARY KEY, participant_id TEXT NOT NULL, segment_id TEXT NOT NULL, text TEXT NOT NULL, language TEXT, final BOOLEAN, first_received_time INTEGER, last_received_time INTEGER, FOREIGN KEY(participant_id) REFERENCES participants(id))
);
const participantStmt = db.prepare('INSERT OR IGNORE INTO participants VALUES (?, ?, ?)');
participantStmt.run(transcription.participant_identity, transcription.participant_identity, transcription.participant?.name || '');
participantStmt.finalize();
const transcribeStmt = db.prepare(INSERT OR REPLACE INTO transcriptions VALUES (?, ?, ?, ?, ?, ?, ?, ?)
);
for (const segment of transcription.segments) {
transcribeStmt.run(transcription.track_sid, transcription.participant_identity, segment.id, segment.text, segment.language, segment.final, segment.start_time, segment.end_time);
}
transcribeStmt.finalize();
db.close();
}`
4. Handle Real-Time Data:
Set up event listeners to catch and process transcription data as it arrives:
room.on(RoomEvent.TranscriptionReceived, (event) => {
const transcription = new Transcription(event.participant.identity, event.track_sid, event.segments);
storeTranscription(transcription);
});
5. Best Practices:
◦ Wrap your database actions in transactions to keep things consistent.
◦ Add retry logic to handle any hiccups during database operations.
◦ Use INSERT OR IGNORE
or INSERT OR REPLACE
to gracefully manage duplicates.
If you’d like, I’m here to help you tweak this for your specific database setup or answer any questions you have along the way. Just let me know!
Sources: lib/src/context/transcription_context.dart | Sending text | LiveKit Docspolite-dog-12152
08/13/2025, 1:13 PMtall-airline-16756
08/13/2025, 1:14 PMRoomServiceClient
to get a list of participants in a room. Here's a quick example:
const roomService = new RoomServiceClient(livekitHost, apiKey, apiSecret);
const participants = await roomService.listParticipants(room);
const participantCount = participants.length;
2. Client-Side:
On the client side, you can check the participants through the SDK’s room state. For instance, in Python:
if room.num_participants > 0:
print("There are participants in the room")
3. Real-Time Updates:
Want to stay updated as participants join or leave? You can subscribe to participant events. Here’s how you might do it in React Native:
const participants = useParticipants();
useEffect(() => {
setParticipantCount(participants.length);
}, [participants]);
4. Command-Line Interface (CLI):
If you prefer the command line, the LiveKit CLI lets you list participants in a room like this:
lk room participants list --room <room-name>
If you want a hand setting any of this up, just give me a shout—I’m here to help!
Sources: src/components/RoomInfo.tsx | docs/interfaces/RoomState.html | livekit-rtc/livekit/rtc/room.py | src/components/stream-player.tsx