Co-hosting across channels refers to the process where the Agora SDK relays the media stream of a host from a live interactive streaming channel (source channel) to a maximum of four live interactive streaming channels (destination channels). It has the following benefits:
- All hosts in the relay channels can see and hear each other.
- The audiences in the relay channels can see and hear all hosts.
Co-hosting across channels applies to scenarios such as an online singing contest, where hosts of different channels interact with each other.
Before relaying media streams across channels, ensure that you have implemented the basic real-time communication functions in your project. For details, see Start Live Interactive Streaming.
The Agora Unity SDK support co-hosting across channels with the following methods:
During the relay, the SDK reports the states and events of the channel media relay with the
OnChannelMediaRelayEventHandler callbacks. Refer to the following codes and their corresponding states to implement your code logic:
|State codes||Event codes||The media stream relay state|
|RELAY_STATE_RUNNING(2) and RELAY_OK(0)||RELAY_EVENT_PACKET_SENT_TO_DEST_CHANNEL(4)||The channel media relay starts.|
|RELAY_STATE_FAILURE(3)||/||Exceptions occur for the media stream relay. Refer to the error parameter for troubleshooting.|
|RELAY_STATE_IDLE(0) and RELAY_OK(0)||/||The channel media relay stops.|
- Any host in a live interactive streaming channel can call the
StartChannelMediaRelaymethod to enable channel media stream relay. The SDK relays the media streams of the host who calls the method.
- During the media stream relay, if the host of the destination channel drops offline or leaves the channel, the host of the source channel receives the
API call sequence
Follow the API call sequence to implement your code logic:
Starts the channel media relay:
ChannelMediaInfo srcChannelInfo = new ChannelMediaInfo(srcChannelName, srcToken, workerSrcUid); ChannelMediaInfo destChannelInfo = new ChannelMediaInfo(destChannelName, destToken, destUid); ChannelMediaRelayConfiguration mediaRelayConfiguration = new ChannelMediaRelayConfiguration(); // Sets the source channel information. mediaRelayConfiguration.srcInfo = srcChannelInfo; // Sets the destination channel information. mediaRelayConfiguration.destInfos = destChannelInfo; mRtcEngine.StartChannelMediaRelay(mediaRelayConfiguration);
Adds or deletes the media relay channels:
ChannelMediaInfo srcChannelInfo = new ChannelMediaInfo(srcChannelName, srcToken, workerSrcUid); ChannelMediaInfo destChannelInfo = new ChannelMediaInfo(destChannelName, destToken, destUid); ChannelMediaRelayConfiguration mediaRelayConfiguration = new ChannelMediaRelayConfiguration(); // Sets the source channel information. mediaRelayConfiguration.srcInfo = srcChannelInfo; // Sets the destination channel information. mediaRelayConfiguration.destInfos = destChannelInfo; mRtcEngine.UpdateChannelMediaRelay(mediaRelayConfiguration);
StartChannelMediaRelaymethod, you can call the
UpdateChannelMediaRelaymethod to add or delete the relay channels.
- The Agora RTC SDK supports relaying media streams to a maximum of four destination channels. To add or delete a destination channel, call
- This feature supports integer user IDs only.
- When setting the souce channel information (
srcInfo), ensure that you set
0, and the
uidthat you use to generate the token should also be set as
- To call
StartChannelMediaRelayagain after it succeeds, you must call
StopChannelMediaRelayto quit the current relay.