rocket_launch

Getting Started

Quick Start

Install splive, authenticate with the Rust API, join a room, connect realtime events, and start LiveKit media.

Install the package

yaml
dependencies:
  splive: ^2.0.0
bash
flutter pub get

Create the SDK client

dart
import 'package:splive/splive.dart';

final sdk = SpliveSdk();

The default constructor uses SpliveEndpoints.serverUrl. A custom Rust endpoint can be passed with baseUrl.

Login

dart
final auth = await sdk.auth.login(
  usernameOrEmail: 'john_doe',
  password: 'strong-password',
);

final rustUserId = auth.user.id;

Load or create a room

dart
final rooms = await sdk.loadRooms(
  groupId: 'RUST_GROUP_UUID',
);

final room = await sdk.createRoom(
  groupId: 'RUST_GROUP_UUID',
  name: 'Community Stage',
  roomType: 'voice',
);

Join and connect the room socket

dart
await sdk.joinRoom(
  roomId: room.id,
  userId: rustUserId,
);

await sdk.connectRoomSocket(
  roomId: room.id,
  userId: rustUserId,
  username: auth.user.username,
);

Listen and send chat

dart
final eventsSubscription = sdk.roomEvents.listen((event) {
  print(event);
});

final messagesSubscription = sdk.roomMessages.listen((message) {
  print('${message.username}: ${message.message}');
});

await sdk.sendRoomMessage(
  roomId: room.id,
  message: 'Hello everyone!',
);

Connect LiveKit media

dart
await sdk.connect(
  SpliveSessionConfig(
    serverUrl: mediaUrl,
    accessToken: mediaToken,
    roomId: room.id,
    userId: rustUserId,
    displayName: auth.user.username,
    enableMicrophoneOnConnect: false,
  ),
);
Generate LiveKit participant tokens on a trusted backend. Never place the LiveKit API secret in Flutter.

Leave and dispose

dart
await eventsSubscription.cancel();
await messagesSubscription.cancel();

await sdk.leaveRoom(roomId: room.id);
await sdk.disconnectRoomSocket();
await sdk.disconnect();
await sdk.dispose();