This article describes how to implement the basic features of PK Host.
Refer to the flowcharts for the following functions:
- Joins and leaves the room.
- Co-host across channels.
Integrate the SDK
Refer to the following table to integrate the SDKs into your project:
Core API call sequence
The following diagrams show the core APIs that the Agora Live Demo app uses to implement a PK Host scenario. Refer to them to implement the various functions in your project.
- The host joins the room and sends a PK host invitation.
- The audience chat through text messages and switch channels.
Core API reference
- Agora RTM SDK
|initWithAppId||Creates an RTM Client object.|
|loginByToken||Logs into the Agora RTM system.|
|createChannelWithId||Creates an Agora RTM channel.|
|joinWithCompletion||Joins the RTM channel.|
|sendMessage||Sends a channel message, which can be received by all users in the channel.|
|sendMessage||Sends a peer message. Use this method to send a PK host invitation message to another host.|
|leaveWithCompletion||Leaves the RTM channel.|
|logoutWithCompletion||Logs out of the Agora RTM system.|
- Agora RTC SDK
|sharedEngineWithAppId||Creates an RtcEngine object.|
|setChannelProfile||Sets the channel profile. In a PK host, we set the channel profile as live broadcast.|
|setClientRole||Sets the user role in a live broadcast. In a PK host, we set the role of the host as broadcaster, and other users as audience.|
|setupLocalVideo||Sets the local video view. Call this method on the host's client to configure the view of the host on the local device.|
|joinChannelByToken||Joins the RTC channel.|
|startChannelMediaRelay||Starts relaying media streams across channels. This is the core API for the PK host scenario.|
|setupRemoteVideo||Sets the remote video view. Once the host of the destination channel accepts the PK host invitation, call this method on the original host's client to configure the view of the co-hosting host.|
|stopChannelMediaRelay||Stops relaying media streams across channels.|
|leaveChannel||Leaves the channel. Use this method to quick switch to another live-broadcast channel.|
The Agora Live Demo app uses a third-party SDK for image enhancement. You can refer to the source code in the faceunity file to implement the function.
Network quality detection
reportRtcStats callback to detect and report the network quality in real-time. Triggered once every two seconds during a live broadcast, this callback reports statistics, including the sending and receiving bitrate and packet loss rate.
Mute the local audio and video
muteLocalVideoStream to stop sending local audio or video streams.
enableInEarMonitoring to enable the in-ear monitor function on the host's client.
After joining the channel, call
startAudioMixing on the host's client to play background music.
Open-source sample project
Agora provides an open-source sample project for PK Host on GitHub for you to download as a source code reference.