排麦组件1. 排麦模式1.1 举手连麦1.1.1 学生可举手申请连麦,需老师确认才可连麦1.1.2 老师可以邀请学生连麦,需学生同意才可连麦1.2 自由连麦1.2.1 学生可自由连麦,无需老师确认1.3 自动连麦1.3.1 学生进入房间后自动连麦2. 排麦事件2.0 请求连麦2.1 同意学生举手连麦2.2 取消连麦2.3 主动下麦2.4 邀请学生上麦2.5 取消邀请2.6 接受老师邀请2.7 拒绝老师连麦邀请2.8 上麦更新2.9 学生举手2.10 学生取消举手2.11 踢人下麦2.12 设置连麦模式(可设置举手连麦,自由连麦,自动连麦,仅只有老师端)2.13 全体下麦(老师)3.2 学生排麦状态通知(上麦和下麦的回调通知)3.3 移除监听3.3 监听排麦其它相关事件
聊天组件的核心类是CCBarleyManager;
//在工程需要的地方引入头文件//1、类的实例化+ (instancetype)sharedBarley;//2、与BaseSDK建立联系- (void)addBasicClient:(CCStreamerBasic *)basic;点击自由连麦、举手,以及自动连麦都必须要调用该接口
应用模式:举手连麦,自由连麦,自动连麦。
/*! @method @abstract 开始连麦(改为排麦中) @return 操作结果 */- (BOOL)handsUp:(CCComletionBlock)completion;举手状态由互动者端发起,通知老师端,老师端可以同意或者不同意。
应用模式:举手连麦,自由连麦,自动连麦。
/*! @method @abstract 同意举手学生连麦 @param userID 学生ID @param completion 结果 @return 操作结果 */- (BOOL)certainHandup:(NSString *)userID completion:(CCComletionBlock)completion;点击自由连麦、举手,以及自动连麦都必须要调用该接口
应用模式:举手连麦,自由连麦,自动连麦。
/*! @method @abstract 取消排麦 @return 操作结果 */- (BOOL)handsUpCancel:(CCComletionBlock)completion;点击自由连麦、举手,以及自动连麦都必须要调用该接口
应用模式:举手连麦,自由连麦,自动连麦。
/*! @method @abstract 结束连麦 @return 操作结果 */- (BOOL)handsDown:(CCComletionBlock)completion;老师端发送邀请,接收端是互动者。
应用模式:举手连麦
/*! @method @abstract 老师邀请没有举手学生连麦(只对老师有效) @param userID 学生ID @return 操作结果 */- (BOOL)inviteUserSpeak:(NSString *)userID completion:(CCComletionBlock)completion;取消邀请由老师端发起
应用模式:举手连麦,自由连麦,自动连麦。
/*! @method @abstract 老师取消对学生的上麦邀请 @param userID 学生ID @param completion 结果 @return 操作结果 */- (BOOL)cancleInviteUserSpeak:(NSString *)userID completion:(CCComletionBlock)completion;学生端接受老师的上麦邀请,同意上麦。
应用模式:举手连麦
/*! @method @abstract 同意老师的上麦邀请 @param completion 结果 @return 操作结果 */- (BOOL)acceptTeacherInvite:(CCComletionBlock)completion;拒绝老师连麦邀请由学生端发起
应用模式:举手连麦,自由连麦,自动连麦。
/*! @method @abstract 拒绝老师的连麦邀请 @param completion 结果 @return 操作结果 */- (BOOL)refuseTeacherInvite:(CCComletionBlock)completion;上麦更新是在两种情况下执行
1.推流成功之后为更新自己上麦状态,通知其他人订阅,需调用。
2.学生不能创建本地流或者推流失败,需将其麦序让出。
应用模式:举手连麦,自由连麦,自动连麦。
/*! @method @abstract 更新连麦状态 @param userID 用户id @param roomID 房间id @param result 推流结果 @param streamID 流id @param completion 回调block @return 操作结果 */- (BOOL)updateUserState:(NSString *)userID roomID:(NSString *)roomID publishResult:(BOOL)result streamID:(NSString *)streamID completion:(CCComletionBlock)completion;举手状态由互动者端发起,通知老师端,老师端可以同意或者不同意。
应用模式:举手连麦,自由连麦,自动连麦。
/*! @method @abstract 学生举手 @return 状态 */- (BOOL)handup;举手状态由互动者端发起,通知老师端,老师端可以同意或者不同意。
应用模式:举手连麦,自由连麦,自动连麦。
/*! @method @abstract 学生取消举手 @return 状态 */- (BOOL)cancleHandup;老师端发起踢人下麦
应用模式:举手连麦,自由连麦,自动连麦。
/*! @method @abstract 将连麦者踢下麦 @param userID 连麦者userID @return 操作结果 */- (BOOL)kickUserFromSpeak:(NSString *)userID completion:(CCComletionBlock)completion;老师端设置连麦模式
应用模式:举手连麦,自由连麦,自动连麦。
/*! @method @abstract 切换连麦模式 @param type 模式 @return 操作结果 */- (BOOL)setSpeakMode:(CCClassType)type completion:(CCComletionBlock)completion;老师端调用全体下麦
/** @method @abstract 切换房间上麦状态(全部踢下麦) @param completion 回调 @return 操作结果 */- (BOOL)changeRoomAllKickDown:(CCComletionBlock)completion;````下面所有的场景都以demo为例,如场景:CCPlayViewController控制器,具体可参考demo实现;这里需要控制器实现‘’CCStreamerBasicDelegate'协议的4个流相关事件,如下:```objc/** @brief Triggers when client is disconnected from conference server. */- (void)onServerDisconnected;/** @brief Triggers when a stream is added. @param stream The stream which is added. */- (void)onStreamAdded:(CCStream*)stream;/** @brief Triggers when a stream is removed. @param stream The stream which is removed. */- (void)onStreamRemoved:(CCStream*)stream;/** @brief Triggers when an error happened on a stream. @detail This event only triggered for a stream that is being publishing or subscribing. SDK will not try to recovery the certain stream when this event is triggered. If you still need this stream, please re-publish or re-subscribe. @param stream The stream which is corrupted. It might be a LocalStream or RemoteStream. @param error The error happened. Currently, errors are reported by MCU. */- (void)onStreamError:(NSError *)error forStream:(CCStream *)stream;具体实现请参考demo实现;
在需要的控制器使用时添加监听事件
-(void)addObserver{ //添加排麦房间状态监听 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveSocketEvent:) name:CCNotiReceiveSocketEvent object:nil]; //这块监听是监听上麦状态事件,逻辑可以根据需要设置 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startPublish) name:CCNotiNeedStartPublish object:nil]; //这块监听是监听下麦状态事件,逻辑可以根据需要设置 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopPublish) name:CCNotiNeedStopPublish object:nil]; //用户需要退出通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needLogout) name:CCNotiNeedLoginOut object:nil];} 'startPublish'、'stopPublish'、'needLogout' - '监听事件请参考demo实现' 'receiveSocketEvent:' - '下面会讲述'在控制器生命周期结束或不展现时移除监听;
-(void)removeObserver{ [[NSNotificationCenter defaultCenter] removeObserver:self];}这里主要监听房间状态及交互事件
- (void)receiveSocketEvent:(NSNotification *)noti{ CCSocketEvent event = (CCSocketEvent)[noti.userInfo[@"event"] integerValue]; id value = noti.userInfo[@"value"]; if (event == CCSocketEvent_LianmaiStateUpdate) { //连麦状态变化 } else if (event == CCSocketEvent_KickFromRoom) { //被踢出房间 } else if (event == CCSocketEvent_LianmaiModeChanged) { //连麦模式变化 } else if (event == CCSocketEvent_ReciveLianmaiInvite) { //在举手连麦模式中收到老师的连麦邀请 //这块监听是监听邀请状态事件,逻辑可以根据需要设置 } else if (event == CCSocketEvent_ReciveCancleLianmaiInvite) { //老师取消了连麦邀请 //这块监听是监听取消邀请状态事件,逻辑可以根据需要设置 } else if (event == CCSocketEvent_HandupStateChanged) { //收到举手状态改变 } else if(event == CCSocketEvent_UserListUpdate) { //在线列表 }}