Create broadcast rooms, connect to LiveKit, monitor room lifecycle, query live rooms, and access recordings.
SDK v7.x · Last verified March 2026 · iOS · Android · Web
Speed run — just the code
import { RoomRepository, PostRepository } from '@amityco/ts-sdk';import { Room as LiveKitRoom } from 'livekit-client';// 1. Create a room with live chat enabledconst room = await RoomRepository.createRoom({ title: 'Friday AMA', channelEnabled: true,});// 2. Publish a livestream postawait PostRepository.createPost({ targetType: 'community', targetId: communityId, dataType: 'livestream', data: { streamId: room.roomId },});// 3. Get broadcaster credentials & connectconst bd = await RoomRepository.getBroadcastData(room.roomId);const lk = new LiveKitRoom();await lk.connect(bd.coHostUrl, bd.coHostToken);await lk.localParticipant.setCameraEnabled(true);await lk.localParticipant.setMicrophoneEnabled(true);// 4. Stop & get recordingawait lk.disconnect();await RoomRepository.stop(room.roomId);
Full walkthrough below ↓
Platform note — code samples below use TypeScript. Every method has an equivalent in the iOS (Swift) and Android (Kotlin) SDKs — see the linked SDK reference in each step.
This guide covers the host’s journey: create a room, wire up the broadcast, monitor lifecycle transitions, query live rooms for a “Live Now” section, and access recordings after the stream ends.
Prerequisites: SDK + Video SDK installed and authenticated → Video Getting Started. A communityId is required — rooms are community-only.
Get broadcaster credentials and connect to LiveKit
Fetch the LiveKit URL and token, then connect the host’s camera and microphone.
TypeScript
import { Room as LiveKitRoom, RoomEvent } from 'livekit-client';const broadcastData = await RoomRepository.getBroadcastData(room.roomId);const liveKitRoom = new LiveKitRoom();liveKitRoom.on(RoomEvent.Connected, () => console.log('Connected!'));liveKitRoom.on(RoomEvent.Disconnected, (reason) => console.log('Disconnected:', reason));await liveKitRoom.connect(broadcastData.coHostUrl, broadcastData.coHostToken);await liveKitRoom.localParticipant.setCameraEnabled(true);await liveKitRoom.localParticipant.setMicrophoneEnabled(true);// Room status is now LIVE
Stopping the room before disconnecting LiveKit — Always call liveKitRoom.disconnect() first, then RoomRepository.stop(roomId). Reversing the order can leave orphaned media tracks.
Forgetting to end rooms when the stream stops — If the broadcaster disconnects without calling stop(), the room stays in live status and appears in “Live Now” feeds as a ghost stream. Always call stop in your cleanup logic.
// ❌ Bad — broadcaster crashes, room stays livewindow.onbeforeunload = () => { /* nothing */ };// ✅ Good — end room on disconnectwindow.onbeforeunload = () => { RoomRepository.stop(roomId);};
Not refreshing the LiveKit token — LiveKit tokens expire. If you don’t handle token refresh, the video connection drops mid-stream. Implement a token renewal callback.
Creating rooms without channelEnabled: true — Without this flag, no live chat channel is created and viewers can’t comment during the stream. Almost all livestream UIs need live chat.
Not observing the room lifecycle — The status transitions (idle → live → ended → recorded) are asynchronous. Hardcoding delays instead of observing the room live object results in brittle UI states.
Polling for recordings too aggressively — Recordings take a few minutes to process. Use the room’s live object with a dataUpdated listener to detect when status === 'recorded' rather than polling every second.