Subscription and Unsubscription
In live streaming mode, the audio and video resources published by the host are merged into one audio mix and one video mix on the server.
Audiences can subscribe to either the original audio/video resources (referred to as single streams
) or the mix streams
. Below, we explain the differences and use cases for these two subscription methods.
Audiences are defined as subscribers only and cannot publish. To publish, they must first switch to host status.
Subscribing to Single Streams
Subscribing to single streams works the same way as in meeting mode, making it suitable for niche live streaming scenarios that require flexibility. For example, audiences may be divided into multiple roles and need to selectively view or listen to specific resources published by hosts. Alternatively, different audiences may have varying display layouts that can be switched at any time. The SDK provides APIs for creating video display views and binding them to streams, allowing developers to customize the display logic.
Audiences should subscribe when they receive the onRemotePublished
notification, which indicates that a host has just published resources. Use the subscribe
method in RCRTCEngine
to subscribe to a host's audio/video resources. If the host has enabled multi-streaming (large/small streams) for video, you can specify whether to subscribe to the large or small stream (default) via the tiny
parameter in subscribe
.
-
Sample code:
engine.subscribe(userId, RCRTCMediaType.audio_video);
Unsubscribing from Single Streams
To unsubscribe from single streams, use the unsubscribe
method in RCRTCEngine
to cancel subscriptions to specific host resources. The unsubscribe method is typically paired with the subscribe method. However, if a user leaves the room, there's no need to call unsubscribe—the SDK handles cancellation automatically when the leaveRoom
method is invoked.
-
Sample code:
engine.unsubscribe(userId, RCRTCMediaType.audio_video);
Subscribing to Mix Streams
In most live streaming scenarios, audiences are numerous and all consume identical content. When multiple hosts are involved, subscribing to single streams can waste significant bandwidth and increase costs. Mix streams address this issue by combining all hosts' audio/video resources into one audio mix and one video mix (audio-only mode produces just an audio mix) based on predefined participant selection, layout, and encoding parameters. By subscribing to these mix streams, audiences consume minimal resources while receiving consistent content, significantly reducing costs. Below are the steps to subscribe to mix streams:
-
Listen for mix stream publishing callbacks:
-
Sample code:
engine.onRemoteLiveMixPublished = (RCRTCMediaType type) {
}
-
-
Subscribe to mix streams:
After detecting the mix stream publishing event, call
subscribeLiveMix
inRCRTCEngine
to subscribe to the specified mix stream resources. The video mix stream supports multi-streaming (large/small streams), which can be controlled via thetiny
parameter insubscribeLiveMix
(defaults to small stream).- Sample code:
engine.subscribeLiveMix(RCRTCMediaType.audio_video);
Unsubscribing from Mix Streams
To unsubscribe from mix streams, use the unsubscribeLiveMix
method in RCRTCEngine
to cancel subscriptions to specific mix stream resources. The unsubscribe method is typically paired with the subscribe method. However, if a user leaves the room, there's no need to call unsubscribe—the SDK handles cancellation automatically when the leaveRoom
method is invoked.
-
Sample code:
engine.unsubscribeLiveMix(RCRTCMediaType.audio_video);