Live Stream Core
English | 简体中文

Product Features
Voice Chat Room
- Supports seat management
- Supports microphone management
- Supports custom seat layout
- Supports custom seat styles
Video Live Streaming
- Allows hosts to start/stop live streams
- Enables audiences to watch/stop watching streams
- Supports audience mic connections
- Facilitates host linking
- Enables host PK battles
- Supports previewing room video streams
Environment Preparation
Flutter
- Flutter 3.27.4 or higher.
- Dart 3.6.2 or higher.
Android
- Android Studio 3.5 or higher.
- Android devices with Android 5.0 or higher.
iOS
- Xcode 15.0 or higher.
- Ensure your project has a valid developer signature configured.
Getting Started
Adding Dependencies
Follow the documentation to add the live_stream_core
package as a pubspec dependency.
Activating Services
To use the interactive live streaming barrage feature, ensure that you have activated the service.
-
Activate the Service
You can activate the service and obtain theSDKAppID
andSDKSecretKey
in the Console. -
Configure SDKAppID and SDKSecretKey
Open theexample/lib/debug/generate_test_user_sig.dart
file and fill in the obtainedSDKAppID
andSDKSecretKey
:static int sdkAppId = 0; // Replace with your activated SDKAppID static String secretKey = ''; // Replace with your activated SDKSecretKey
Example Experience
If you want to quickly integrate or experience the interactive barrage effect, you can refer to the example code to integrate it into your application or directly run the example program for a hands-on experience.
APIs
Creating a Voice Chat Room Core Component Instance
You need to first create a SeatGridController
and then assign it to the voice chat room core component SeatGridWidget
.
SeatGridController
provides APIs, whileSeatGridWidget
is used to display the seat UI.
You can addSeatGridWidget
anywhere you need to display the seat UI.
final controller = SeatGridController();
SeatGridWidget(controller: controller);
Logging In
To ensure you can use the API functionalities of the live streaming core component, you need to perform the login operation first.
const String userId = 'replace with your userId';
final result = await TUIRoomEngine.login(
'Replace with your activated SDKAppID',
userId,
'Replace with your userSig');
Starting a Voice Chat Room
You can use the startVoiceRoom
API to start a voice chat room.
import 'package:live_stream_core/live_stream_core.dart';
import 'package:rtc_room_engine/rtc_room_engine.dart';
final roomInfo = TUIRoomInfo(roomId: 'replace with your roomId');
roomInfo.name = 'replace with your roomName';
roomInfo.seatMode = TUISeatMode.applyToTake;
roomInfo.isSeatEnabled = true;
roomInfo.roomType = TUIRoomType.livingRoom;
final result = await controller.startVoiceRoom(roomInfo);
Ending a Voice Chat Room
You can use the stopVoiceRoom
API to end a voice chat room.
import 'package:live_stream_core/live_stream_core.dart';
final result = await controller.stopVoiceRoom();
Joining a Voice Chat Room
You can use the joinVoiceRoom
API to join a voice chat room.
import 'package:live_stream_core/live_stream_core.dart';
final result = await controller.joinVoiceRoom('replace with your roomId');
Leaving a Voice Chat Room
You can use the leaveVoiceRoom
API to leave a voice chat room.
import 'package:live_stream_core/live_stream_core.dart';
final result = await controller.leaveVoiceRoom();
Setting the Seat Mode
You can use the updateRoomSeatMode
API to set the seat mode.
There are two seat modes: Free to Take (freeToTake) and Apply to Take (applyToTake).
In Free to Take mode, audience members can directly take a seat without the host's approval. In Apply to Take mode, audience members must first apply to the host and obtain approval before taking a seat.
import 'package:live_stream_core/live_stream_core.dart';
import 'package:rtc_room_engine/rtc_room_engine.dart';
const seatMode = TUISeatMode.freeToTake;
final result = await controller.updateRoomSeatMode(seatMode);
Applying for a Seat
You can use the takeSeat
API to apply for a seat.
When using seat-related APIs, the seat index
seatIndex
ranges from[0, maxSeatCount)
.
ThemaxSeatCount
is related to your package's maximum number of multi-guests.
// API Definition
Future<RequestCallback> takeSeat(int seatIndex, int timeout) async;
// API Usage
import 'package:live_stream_core/live_stream_core.dart';
final result = await controller.takeSeat(1, 30);
Voluntarily Leaving a Seat
You can use the leaveSeat
API to voluntarily leave a seat.
import 'package:live_stream_core/live_stream_core.dart';
final result = await controller.leaveSeat();
Moving Seats
You can use the moveToSeat
API to switch seat positions while on the seat.
import 'package:live_stream_core/live_stream_core.dart';
final destinationIndex = 2; // Replace with the seat index you want to move to
final result = await controller.moveToSeat(destinationIndex);
Locking a Seat
You can use the lockSeat
API to lock a seat.
The
lockSeat
API supports the following capabilities in voice chat room scenarios:
- Lock a specific seat to prevent taking it: Set
lockSeat
inTUISeatLockParams
totrue
.- Lock a specific seat to disable audio: Set
lockAudio
inTUISeatLockParams
totrue
.
// API Definition
Future<TUIActionCallback> lockSeat(int index, TUISeatLockParams lockMode) async;
// API Usage
import 'package:live_stream_core/live_stream_core.dart';
import 'package:rtc_room_engine/rtc_room_engine.dart';
final lockMode = TUISeatLockParams();
lockMode.lockSeat = true;
final result = await controller.lockSeat(3, lockMode);
Inviting a User to a Seat
You can use the takeUserOnSeatByAdmin
API to invite an audience member to a specific seat.
// API Definition
Future<RequestCallback> takeUserOnSeatByAdmin(int seatIndex, String userId, int timeout) async;
// API Usage
import 'package:live_stream_core/live_stream_core.dart';
final result = await controller.takeUserOnSeatByAdmin(4, 'replace with the userId of the audience you want to invite', 30);
Kicking a User Off a Seat
You can use the kickUserOffSeatByAdmin
API to kick a user with the specified userId
off the seat.
import 'package:live_stream_core/live_stream_core.dart';
final result = await controller.kickUserOffSeatByAdmin('replace with the userId of the audience you want to kick off from seat');
Responding to Seat Requests
You can use the responseRemoteRequest
API to approve or reject seat requests from a user with the specified userId
.
import 'package:live_stream_core/live_stream_core.dart';
final result = await controller.responseRemoteRequest('replace with userId', true);
Canceling a Seat Request
You can use the cancelRequest
API to cancel a seat request from a user with the specified userId
.
This API can cancel your own seat request or an invitation request to a specific user.
import 'package:live_stream_core/live_stream_core.dart';
final result = await controller.responseRemoteRequest('replace with userId', true);
Turning On the Microphone
You can use the startMicrophone
API to turn on the microphone device.
import 'package:live_stream_core/live_stream_core.dart';
final result = await controller.startMicrophone();
Turning Off the Microphone
You can use the stopMicrophone
API to turn off the microphone device.
import 'package:live_stream_core/live_stream_core.dart';
controller.stopMicrophone();
Muting the Audio Stream
You can use the muteMicrophone
API to mute the local audio stream.
import 'package:live_stream_core/live_stream_core.dart';
final result = await controller.muteMicrophone();
Unmuting the Audio Stream
You can use the unmuteMicrophone
API to unmute the local audio stream.
import 'package:live_stream_core/live_stream_core.dart';
final result = await controller.unmuteMicrophone();
Customizing Seat Layout
You can use the setLayoutMode
API to customize the seat layout.
The
setLayoutMode
API provides three built-in layouts: Focus (focus), Grid (grid), and Vertical (vertical), and also supports custom layouts (free).
// API Definition
void setLayoutMode(LayoutMode layoutMode, SeatWidgetLayoutConfig? layoutConfig);
// API Usage
import 'package:live_stream_core/live_stream_core.dart';
controller.setLayoutMode(LayoutMode.grid, null); // Example: Using the built-in grid layout
final rowConfig = SeatWidgetLayoutRowConfig(
count: 2,
seatSpacing: 20.0,
seatSize: const Size(80, 80),
alignment: SeatWidgetLayoutRowAlignment.spaceBetween);
final layoutConfig = SeatWidgetLayoutConfig(
rowConfigs: [rowConfig, rowConfig]);
controller.setLayoutMode(LayoutMode.free, layoutConfig); // Example: Using a custom layout
Customizing Seat Styles
You can use the seatWidgetBuilder
parameter of SeatGridWidget
to customize the UI style of specific seats.
// seatWidgetBuilder Definition
typedef SeatWidgetBuilder = Widget Function(
BuildContext context,
ValueNotifier<TUISeatInfo> seatInfoNotifier,
ValueNotifier<int> volumeNotifier);
// Usage Example
import 'package:live_stream_core/live_stream_core.dart';
import 'package:rtc_room_engine/rtc_room_engine.dart';
SeatGridWidget(
controller: controller,
onSeatWidgetTap: (TUISeatInfo seatInfo) {
// debugPrint('click seatWidget index:${seatInfo.index}');
},
seatWidgetBuilder: (
BuildContext context,
ValueNotifier<TUISeatInfo> seatInfoNotifier,
ValueNotifier<int> volumeNotifier) {
// Return your custom seat widget
return Container();
}
)
Creating a Video Live Streaming Core Control Instance
You need to first create a controller LiveCoreController
and then assign it to the video live streaming core component LiveCoreWidget
.
LiveCoreController provides APIs, while LiveCoreWidget displays the video UI. You can add LiveCoreWidget anywhere you need to display video content.
final controller = LiveCoreController();
LiveCoreWidget(controller: controller);
Starting a Live Room
You can use the startLiveStream
API for hosts to start a live room.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
import 'package:rtc_room_engine/rtc_room_engine.dart';
final roomInfo = TUIRoomInfo(roomId: 'replace with your roomId');
roomInfo.name = 'replace with your roomName'
roomInfo.isSeatEnabled = true;
roomInfo.roomType = TUIRoomType.livingRoom;
roomInfo.seatMode = TUISeatMode.applyToTake;
final result = await controller.startLiveStream(roomInfo);
Ending a Live Room
You can use the stopLiveStream
API for hosts to end a live room.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final result = await controller.stopLiveStream();
Joining a Live Room
You can use the joinLiveStream
API for viewers to join a live room.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final result = await controller.joinLiveStream('replace with your roomId');
Leaving a Live Room
You can use the joinLiveStream
API for viewers to leave a live room.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final result = await controller.leaveLiveStream();
Starting Camera (Preview/Video Streaming)
You can use the startCamera
API to enable the local camera.
If called before starting the live room, it only previews the local video; If called after starting the live room, it streams the local video to the live room.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final useFrontCamera = true; // // Set to false to use rear camera
final result = await controller.startCamera(useFrontCamera);
Switching Between Front/Rear Camera
You can use the switchCamera
API to switch between front and rear cameras.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final isFront = true; // true switches to front camera, false to rear camera
controller.switchCamera(isFront);
Turning Off Camera
You can use the stopCamera
API to disable the local camera.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
controller.stopCamera();
Enabling/Disabling Video Mirroring
You can use the enableMirror
API to enable/disable video mirroring.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final enable = true; // true enables mirroring, false disables
controller.enableMirror();
Enabling Local Microphone
You can use the openLocalMicrophone
API to enable the local microphone.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final result = await controller.openLocalMicrophone();
Muting Local Audio Stream
You can use the muteLocalAudio
API to mute the local audio stream.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
controller.muteLocalAudio();
Unmuting Local Audio Stream
You can use the unmuteMicrophone
API to unmute the local audio stream.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final result = await controller.unmuteMicrophone();
Closing Local Microphone
You can use the closeLocalMicrophone
API to close the local microphone.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
controller.closeLocalMicrophone();
Audience Requesting to Co-Guest
You can use the requestIntraRoomConnection
API for audiences to request co-guesting.
// API Definition
Future<TUIActionCallback> requestIntraRoomConnection(String userId, int timeout, bool openCamera)
// API Usage
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final userId = 'replace with the userId of room owner';
fianl openCamera = true; // true enables video co-hosting, false enables audio-only
final result = await controller.requestIntraRoomConnection(userId, 30, openCamera);
Audience Canceling Co-Guest Request
You can use the cancelIntraRoomConnection
API to cancel co-host requests.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final userId = 'replace with the userId of room owner';
final result = await controller.cancelIntraRoomConnection(userId);
Host Responding to Co-Guest Request
You can use the respondIntraRoomConnection
API to accept/reject co-guest requests.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final result = await controller.cancelIntraRoomConnection('replace with userId', true);
Host Ending Co-Guest Connection
You can use the disconnectUser
API to end co-guesting with a audience.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final result = await controller.disconnectUser('replace with userId');
Audience Ending Co-Guest Connection
You can use the terminateIntraRoomConnection
API for audiences to end co-guestting.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final result = await controller.terminateIntraRoomConnection();
Host Requesting Cross-Room Connection
You can use the requestCrossRoomConnection
API for hosts to connect across rooms.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final roomId = 'replace with the roomId of anchor you want to invite';
final result = await controller.requestCrossRoomConnection(roomId);
Canceling Cross-Room Connection Request
You can use the cancelCrossRoomConnection
API to cancel connection requests.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final roomId = 'replace with the roomId of anchor you want to invite';
final result = await controller.requestCrossRoomConnection(roomId);
Responding to Cross-Room Request
You can use the respondToCrossRoomConnection
API to handle connection requests.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final roomId = 'replace with the roomId of anchor who sent you the co-host reuqest';
final isAccepted = true; // true accepts, false rejects
final result = await controller.respondToCrossRoomConnection(roomId, isAccepted);
Ending Cross-Room Connection
You can use the terminateCrossRoomConnection
API to end connections.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final result = await controller.terminateCrossRoomConnection();
Host Requesting PK Battle
You can use the requestBattle
API to initiate PK battles.
Recommended to only invite connected hosts
// API Definition
Future<TUIValueCallBack<BattleRequestCallback>> requestBattle(TUIBattleConfig config, List<String> userIdList, int timeout)
// API Usage
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
import 'package:rtc_room_engine/rtc_room_engine.dart';
final config = TUIBattleConfig();
config.duration = 10; // PK duration in seconds (max 300)
List<String> inviteeIds = List.empty(); // Replace with connected hosts' userIds
final result = await controller.requestBattle(config, inviteeIds, 30);
Canceling PK Request
You can use the cancelBattle
API to cancel PK requests.
// API Definition
Future<TUIActionCallback> cancelBattle(String battleId, List<String> userIdList)
// API Usage
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final battleId = 'replace with the battleId you get from api requestBattle';
List<String> inviteeIds = List.empty(); // Replace with previously invited hosts
final result = await controller.cancelBattle(battleId, inviteeIds);
Responding to PK Request
You can use the ``respondToBattle``` API to handle PK requests.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final battleId = 'replace with the battleId which you received from callback onBattleRequestReceived';
final isAccepted = true; // true accepts, false rejects
final result = await controller.respondToBattle(battleId, isAccepted);
Ending PK Battle
You can use the terminateBattle
API to end PK battles.
a. Ends PK if only two hosts are battling b. Leaves current PK in multi-host battles; ends when duration expires or condition a is met
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final result = await controller.terminateBattle('battleId');
Start Preloading Room Video Stream
You can use the startPreloadVideoStream
interface to preload video streams for specified rooms.
a.
viewId
can be obtained through theVideoView
component's onViewCreated callback b. Pass a self-constructed TUIPlayCallback to listen for playback status, or pass null otherwise
// API Definition
void startPreloadVideoStream(String roomId, bool isMuteAudio, int viewId, TUIPlayCallback? playCallback)
// API Usage
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final roomId = 'replace with your roomId';
final isMuteAudio = false; // true: mute audio while playing video stream, false: normal playback
final viewId = 0; // Replace with integer obtained from VideoView's onViewCreated
controller.startPreloadVideoStream(roomId, isMuteAudio, viewId, null);
Stop Preloading Room Video Stream
You can use the stopPreloadVideoStream
interface to stop preloading video streams for specified rooms.
import 'package:live_stream_core/live_core_widget/live_core_widget.dart';
final roomId = 'replace with your roomId';
controller.stopPreloadVideoStream(roomId);
Recommended Resources
If you want to quickly integrate a fully-featured interactive live streaming UI into your application, you can integrate the Interactive Live Streaming (tencent_live_uikit) component.
Feedback and Support
For any inquiries or feedback, please contact: info_rtc@tencent.com.
Libraries
- common/constants/constants
- common/constants/index
- common/index
- common/language/gen/live_core_localizations
- common/language/gen/live_core_localizations_en
- common/language/gen/live_core_localizations_zh
- common/language/index
- common/logger/index
- common/logger/logger
- common/platform/index
- common/platform/live_core_widget_method_channel
- common/platform/live_core_widget_platform_interface
- common/reporter/data_reporter
- common/reporter/index
- common/resources/colors
- common/resources/images
- common/resources/index
- common/screen/index
- common/screen/screen_adapter
- live_core_widget/index
- live_core_widget/live_core_controller
- live_core_widget/live_core_widget
- live_core_widget/live_core_widget_define
- live_core_widget/manager/api/index
- live_core_widget/manager/api/live_stream
- live_core_widget/manager/api/live_stream_service
- live_core_widget/manager/index
- live_core_widget/manager/live_stream_manager
- live_core_widget/manager/module/battle_manager
- live_core_widget/manager/module/co_guest_manager
- live_core_widget/manager/module/co_host_manager
- live_core_widget/manager/module/index
- live_core_widget/manager/module/layout_manager
- live_core_widget/manager/module/media_manager
- live_core_widget/manager/module/room_manager
- live_core_widget/manager/module/user_manager
- live_core_widget/manager/observer/index
- live_core_widget/manager/observer/live_battle_observer
- live_core_widget/manager/observer/live_connection_observer
- live_core_widget/manager/observer/live_core_widget_observer_list
- live_core_widget/manager/observer/live_layout_observer
- live_core_widget/manager/observer/room_engine_observer
- live_core_widget/state/battle_state
- live_core_widget/state/co_guest_state
- live_core_widget/state/co_host_state
- live_core_widget/state/index
- live_core_widget/state/layout_state
- live_core_widget/state/media_state
- live_core_widget/state/room_state
- live_core_widget/state/user_state
- live_core_widget/widget/index
- live_core_widget/widget/live_stream_widget_container
- live_core_widget/widget/mix_stream_decoration/index
- live_core_widget/widget/mix_stream_decoration/mix_stream_decoration_widget
- live_core_widget/widget/mix_stream_decoration/mix_stream_decoration_widget_layout_delegate
- live_core_widget/widget/mix_stream_decoration/mix_stream_decoration_widgets_container
- live_core_widget/widget/normal_stream_video_decoration/index
- live_core_widget/widget/normal_stream_video_decoration/live_stream_widget
- live_core_widget/widget/normal_stream_video_decoration/normal_stream_widgets_container
- live_core_widget/widget/normal_stream_video_decoration/video_widget_json_layout_delegate
- live_core_widget/widget/video_widget/video_widget
- live_stream_core
- seat_grid_widget/index
- seat_grid_widget/manager/api/index
- seat_grid_widget/manager/api/seat_grid_widget_interface
- seat_grid_widget/manager/api/seat_grid_widget_service
- seat_grid_widget/manager/index
- seat_grid_widget/manager/module/index
- seat_grid_widget/manager/module/media_manager
- seat_grid_widget/manager/module/room_manager
- seat_grid_widget/manager/module/seat_manager
- seat_grid_widget/manager/module/user_manager
- seat_grid_widget/manager/module/widget_manager
- seat_grid_widget/manager/observer/index
- seat_grid_widget/manager/observer/room_engine_observer
- seat_grid_widget/manager/observer/seat_grid_widget_observer_list
- seat_grid_widget/manager/seat_grid_widget_manager
- seat_grid_widget/seat_grid_controller
- seat_grid_widget/seat_grid_define
- seat_grid_widget/seat_grid_widget
- seat_grid_widget/state/index
- seat_grid_widget/state/media_state
- seat_grid_widget/state/room_state
- seat_grid_widget/state/seat_state
- seat_grid_widget/state/user_state
- seat_grid_widget/state/widget_state
- seat_grid_widget/widget/animated/index
- seat_grid_widget/widget/animated/sound_wave_animated_widget
- seat_grid_widget/widget/default_seat_widget
- seat_grid_widget/widget/index