Skip to main content

Standard Low-Latency Live Streaming Process

Before you begin, please confirm you've completed Activate RTC Service, Import SDK, and Initialize SDK.

tip

To initiate RTC calls between multiple participants, all users must join the same RTC room. For live streaming scenarios, select audio_video or audio as the resource type (for video/audio or audio-only live streams). Room roles include broadcaster (live_broadcaster) and audience (live_audience). Below are instructions for both roles.

Broadcaster End

Users join the room as broadcasters (live_broadcaster).

Step 1.1: Set Up Listeners

Local Event Listeners

Set room join callback:

engine.onRoomJoined = (int code, String? errMsg) {
if (code != 0) {
// Room joined successfully
} else {
// Failed to join room
}
};

Set resource publish callback:

engine.onPublished = (RCRTCMediaType type, int code, String? errMsg) {
// type: Published resource type
if (code != 0) {
// Publish succeeded
} else {
// Publish failed
}
}

Set resource unpublish callback:

engine.onUnpublished = (RCRTCMediaType type, int code, String? errMsg) {
// type: Unpublished resource type
if (code != 0) {
// Unpublish succeeded
} else {
// Unpublish failed
}
}

Set resource subscription callback:

engine.onSubscribed = (String userId, RCRTCMediaType type, int code, String? errMsg) {
// userId: Remote user ID
// type: Subscribed resource type
if (code != 0) {
// Subscribe succeeded
} else {
// Subscribe failed
}
}

Set resource unsubscription callback:

engine.onUnsubscribed = (String userId, RCRTCMediaType type, int code, String? errMsg) {
// userId: Remote user ID
// type: Unsubscribed resource type
if (code != 0) {
// Unsubscribe succeeded
} else {
// Unsubscribe failed
}
}

Remote Event Listeners

Set remote user join callback:

engine.onUserJoined = (String userId) {
// userId: Remote user ID
}

Set remote user leave callback:

engine.onUserLeft = (String userId) {
// userId: Remote user ID
}

Set remote resource publish callback:

engine.onRemotePublished = (String roomId, String userId, RCRTCMediaType type) {
// roomId: Room ID
// userId: Remote user ID
// type: Published resource type
}

Set remote resource unpublish callback:

engine.onRemoteUnpublished = (String roomId, String userId, RCRTCMediaType type) {
// roomId: Room ID
// userId: Remote user ID
// type: Unpublished resource type
}

Step 1.2: Join Room

  1. Create RCRTCRoomSetup with broadcaster role and room type:

    RCRTCRoomSetup setup = RCRTCRoomSetup.create(
    // Choose audio_video (video/audio) or audio (audio-only)
    type: RCRTCMediaType.audio_video,
    role: RCRTCRole.live_broadcaster,
    );
  2. Call joinRoom to create/join a live room:

    engine.joinRoom('Room ID', setup);
tip

Clients join rooms using the "Room ID" passed to joinRoom. Rooms are automatically created by RC when they don't exist and destroyed after a period with no broadcasters (audiences don't count).

Step 1.3: Publish Resources

  1. After joining, enable camera and publish resources:

    /// Enable camera
    engine.enableCamera(true);
    /// Publish audio/video
    engine.publish(RCRTCMediaType.audio_video);
  2. Create RCRTCView and set local video view:

    /// Create preview window
    RCRTCView view = await RCRTCView.create();
    /// Set preview
    engine.setLocalView(view);

Step 1.4: Subscribe to Other Broadcasters

  1. Subscribe to other broadcasters' resources (for co-hosting scenarios). Remote publishes trigger onRemotePublished:

    engine.subscribe(userId, RCRTCMediaType.audio_video);
  2. Create and set remote video view:

    /// Create preview window
    RCRTCView view = await RCRTCView.create();
    /// Set preview
    engine.setRemoteView(userId, view);

Audience End

Users join as audience (live_audience).

Step 2.1: Set Up Listeners

Set mixed stream publish callback:

engine.onRemoteLiveMixPublished = (RCRTCMediaType type) {
}

Set mixed stream unpublish callback:

engine.onRemoteLiveMixUnpublished = (RCRTCMediaType type) {
}

Step 2.2: Join Room

  1. Create RCRTCRoomSetup with audience role:

    RCRTCRoomSetup setup = RCRTCRoomSetup.create(
    // Choose audio_video or audio
    type: RCRTCMediaType.audio_video,
    role: RCRTCRole.live_audience,
    );
  2. Join the live room:

    engine.joinRoom('Room ID', setup);

Step 2.3: Watch Live Stream

  1. After mixed stream publish event, subscribe:

    engine.subscribeLiveMix(RCRTCMediaType.audio_video);
  2. Create and set mixed stream view:

    /// Create preview window
    RCRTCView view = await RCRTCView.create();
    /// Set preview
    engine.setLiveMixView(view);