Interactive live broadcast

8.1 Create an interactive live broadcast object

Create an XHLiveManager object

The class which the object belongs to needs to implement the ILiveListener interface.
XHLiveManager::addChatroomGetListListener(this);
m_pLiveManager = new XHLiveManager(this);

8.2 Callback function description

/**
* Someone has joined the live room to be a broadcaster
* @param liveID live room ID
* @param actorID user ID
*/
virtual void onActorJoined(string liveID, string actorID) = 0;

/**
* Someone has left the live room
* @param liveID live room ID
* @param actorID user ID
*/
virtual void onActorLeft(string liveID, string actorID) = 0;

/**
* Room creator received an application to join the live broadcast
* @param liveID
* @param applyUserID
*/
virtual void onApplyBroadcast(string liveID, string applyUserID) = 0;

/**
* Applicant receives the reply to join the live broadcast
* @param liveID
* @param result
*/
virtual void onApplyResponsed(string liveID, bool bAgree) = 0;

/**
* The viewer received an invitation to join the live broadcast
* @param liveID live room ID
* @param applyUserID the user ID who invites you
*/
virtual void onInviteBroadcast(string liveID, string applyUserID) = 0;

/**
* The room creator received a reply from the user who is being invited
* @param liveID live room ID
* @param result result
*/
virtual void onInviteResponsed(string liveID) = 0;

/**
* Some abnormal conditions may cause the live to go wrong. Please leave the live broadcast after receiving the callback.
* @param liveID live room ID
* @param error error information
*/
virtual void onLiveError(string liveID, string error) = 0;

/**
* The number of members has changed
* @param number
*/
virtual void onMembersUpdated(int number) = 0;

/**
* You are kicked
*/
virtual void onSelfKicked() = 0;

/**
* You are being muted
*/
virtual void onSelfMuted(int seconds) = 0;

/**
* You are forced to stop live.
* @param liveID live room ID
*/
virtual void onCommandToStopPlay(string liveID) = 0;

/**
* Receive a message
* @param message
*/
virtual void onReceivedMessage(CIMMessage* pMessage) = 0;

/**
* Receive a private message
* @param message
*/
virtual void onReceivePrivateMessage(CIMMessage* pMessage) = 0;
virtual int getRealtimeData(string strUserId, uint8_t* data, int len) = 0;
/**
* Receive video data
* @param data
*/
virtual int getVideoRaw(string strUserId, int w, int h, uint8_t* videoData, int videoDataLen) = 0;

8.3 The description of getting a list of live room

The usage without AEC

/**
* Get the live list
*/
void getLiveList()
{
XHLiveManager::getLiveList("", CHATROOM_LIST_TYPE_LIVE);
}
After calling this method, the corresponding chatroomQueryAllListOK callback function will be called.
/*
* Save the live room
*/
string strInfo = "{\"id\":\"";
strInfo += strLiveId;
strInfo += "\",\"creator\":\"";
strInfo += m_pUserManager->m_ServiceParam.m_strUserId;
strInfo += "\",\"name\":\"";
strInfo += strName.GetBuffer(0);
strInfo += "\"}";
m_pLiveManager->saveToList(m_pUserManager->m_ServiceParam.m_strUserId, CHATROOM_LIST_TYPE_LIVE, strLiveId, strInfo);

The usage with AEC

/**
* Get the live list
*/
void getLiveList()
{
list<ChatroomInfo> listData;
CInterfaceUrls::demoRequestLiveList(listData, m_pUserManager);
chatroomQueryAllListOK(listData);
}
/*
* Save the live room
*/
string strInfo = "{\"id\":\"";
strInfo += strLiveId;
strInfo += "\",\"creator\":\"";
strInfo += m_pUserManager->m_ServiceParam.m_strUserId;
strInfo += "\",\"name\":\"";
strInfo += strName.GetBuffer(0);
strInfo += "\"}";
CInterfaceUrls::demoSaveToList(m_pUserManager->m_ServiceParam.m_strUserId, CHATROOM_LIST_TYPE_LIVE, strLiveId, strInfo);

8.4 XHVoipManager API Description

/**
* Add getting live list callback function
* @param pChatroomGetListListener
*/
static void addChatroomGetListListener(IChatroomGetListListener* pChatroomGetListListener);
/**
* Get the live list
* @param strUserId user ID
* @param listType list type
*/
static void getLiveList(string strUserId, int listType);

/**
* Set the media type
* @param mediaTypeEnum Audio and video exist at the same time, or only one of them is turned on.
*/
void setRtcMediaType(LIVE_MEDIA_TYPE mediaTypeEnum);

/**
* Create a live room
*/
string createLive(string strName, int chatroomType, int channelType);

/**
* Start a live room
* @param liveID live room ID
*/
bool startLive(string liveID);

/**
* Watch the live room
* @param liveID live room ID
*/
bool watchLive(string liveID);

/**
* Audience apply to be a broadcaster
* @param toID The creater ID
*/
void applyToBroadcaster(string toID);

/**
* The creater agrees to be a broadcaster
* @param toID The user who the creater agrees to be a broadcaster
*/
void agreeApplyToBroadcaster(string toID);

/**
* The creater refuses someone to be a broadcaster
* @param toID The user who the creater refuses to be a broadcaster
*/
void refuseApplyToBroadcaster(string toID);

/**
* The creater invites someone to be a broadcaster
* @param toID the Invitee ID
*/
void inviteToBroadcaster(string toID);

/**
* The audience has agreed to be a broadcaster
* @param toID Inviter ID
*/
void agreeInviteToBroadcaster(string toID);

/**
* The audience has refused to be a broadcaster
* @param toID Inviter ID
*/
void refuseInviteToBroadcaster(string toID);

/**
* Stop to be a broadcaster
* @param toID someone who will be stopped to be a broadcaster
*/
void commandToAudience(string toID);

/**
* Leave the live room
*/
void leaveLive();

/**
* Switch to the big video preview
* @param userID the user ID which will be switched
*/
void changeToBig(string userID);

/**
* Switch to the small video preview
* @param userID the user ID which will be switched
*/
void changeToSmall(string userID);

/**
* Dynamically switch audio:the audio can be switched at any time during the live broadcast, and the status is automatically reset after the live broadcast ends.
*/
void setAudioEnable(bool bEnable);

/**
* Dynamically switch video:the video can be switched at any time during the live broadcast, and the status is automatically reset after the live broadcast ends.
*/
void setVideoEnable(bool bEnable);

/**
* Send a message
* @param message message
* @return Return the sent message object
*/
CIMMessage* sendMessage(string strMessage);

/**
* Send a private message
* Private messages can only be received by the target user
* @param message message
* @param toID Target user ID
* @return Return the sent message object
*/
CIMMessage* sendPrivateMessage(string toID, string strMessage);

/**
* Mute somebody in the live room
* @param chatroomID meeting room ID
* @param memberID the member who is mute
* @param muteSeconds mute time
*/
bool muteMember(string liveId, string memberID, int muteSeconds);

/**
* Unmute somebody in the live room
* @param chatroomID meeting room ID
* @param memberID the member who is unmute
* @param callback Result callback
*/
bool unMuteMember(string liveId, string memberID);

/**
* Kick out users in the meeting room
* @param chatroomID chatroom ID
* @param memberID the member who is being kicked out
*/
bool kickMember(string liveId, string memberID);

/**
* Save the live room to the list
* @param userId
* @param type
* @param meetingId
* @param data
*/
bool saveToList(string userId, int type, string liveId, string data);

/**
* Delete the live room from the list
* @param userId userId
* @param type type
* @param meetingId meetingId
*/
void deleteFromList(string userId, int type, string liveId);

**
* Push RTMP stream
* @param rtmpurl Push address
*/
void pushRtmp(string rtmpurl);

/**
* Stop pushing RTMP stream
*/
void stopPushRtmp();

/**
* Insert audio data
* @param audioData
* @param dataLen
*/
void insertAudioRaw(uint8_t* audioData, int dataLen);

/**
* Insert video data
* @param videoData
* @param dataLen
* @param isBig
*/
void insertVideoRaw(uint8_t* videoData, int dataLen, int isBig);

/**
* Crop the video data
*/
int cropVideoRawNV12(int w, int h, uint8_t* videoData, int dataLen, int yuvProcessPlan, int rotation, int needMirror, uint8_t* outVideoDataBig, uint8_t* outVideoDataSmall);

/**
* Query the audio data
*/
void querySoundData(uint8_t** pData, int* nLength);