开发者中心

名称: 上海璟梦信息科技有限公司 IM SDK 集成文档
版本: V1.0.0
日期: 2021-10-10

1.集成指南

1.1SDK集成

1.1.1 申请appid

1.1.2 导入jar包

1)  将jar包添加到工程libs目录

1.1.3 配置AndroidManifest.xml

1)添加SDK相关权限

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

2)添加AppId

<meta-data
	android:name="CL_IM_SDK_APP_ID"
  	android:value="替换为你们自己的appId" />

1.1.4 添加混淆配置

-keep class com.chuanglan.** { *;}
-keep class com.network.okhttp.** { *;}
-keep class com.network.okio.** { *;}
-keep class org.apache.mina.** { *;}
-keep class com.google.protobuf.** { *;}
-keep class org.slf4j.** { *;}

2.消息码(回调code)

public class MessageCode {

    /** 用户模块**/
    //登录回调
    public final static int LOGIN_RESP = 0x0000;
    //登出回调
    public final static int LOGOUT_RESP = 0x0001;
    //查找用户回调
    public final static int FIND_USER_INFO_RESP = 0x0003;
    //设置用户属性回调
    public final static int MODIFY_USER_INFO_RESP = 0x0004;
    //错误回调,返回BaseResp对象(BaseResp.msgCode和CmdMsgCode.User模块请求码对应)
    public final static int USER_UNUSUAL_RESP = 0x1001
    
    /** 好友模块**/
    // 添加好友请求回调
    public final static int ADD_FRIEND_RESP = 0x0007;
    //添加好友请求应答回调
    public final static int PASS_ADD_FRIEND_RESP = 0x0008;
    //删除好友回调
    public final static int DELETE_FRIEND_RESP = 0x0009;
    //查询好友列表
    public final static int QUERY_FRIEND_LIST_RESP = 0x0010;
    //获取黑名单列表
    public final static int GET_BLOCKED_FRIEND_LIST_RESP = 0x0011;
    //加入黑名单
    public final static int ADD_BLOCKED_FRIEND_RESP = 0x0012;
    //移出黑名单
    public final static int REMOVE_BLOCKED_FRIEND_RESP = 0x0013;
    //收到好友请求
    public final static int FRIEND_REQUEST_RECEIVED = 0x0014;
    //取消呼叫
    public final static int CANCEL_AV_CALL_RESP = 0x0015;
    //拒绝接听好友呼叫
    public final static int REFUSE_AV_CALL_RESP = 0x0016;
    //设置好友备注
    public final static int SET_FRIEND_MARK_NAME_RESP = 0x0017;
    //好友聊天置顶
    public final static int SET_FRIEND_TOP_RESP = 0x0018;
    //设置好友免打扰
    public final static int SET_FRIEND_DISTURB_RESP = 0x0019;
    //收到好友删除
    public final static int DELETE_FRIEND_REQUEST_RECEIVED = 0x0022;
    //收到好友拒接呼叫
    public final static int REFUSE_AV_CALL_REQ_RECEIVED = 0x0023;
    //收到好友取消呼叫
    public final static int CANCEL_AV_CALL_REQ_RECEIVED = 0x0024;
    //收到添加好友请求应答
    public final static int PASS_ADD_FRIEND_REQ_RECEIVED = 0x0025;
    //错误回调,返回BaseResp对象(BaseResp.msgCode和CmdMsgCode.Friend模块请求码对应)
    public final static int FRIEND_UNUSUAL_RESP = 0x0026;

    /**消息模块**/
    //收到消息
    public final static int RECEIVE_MESSAGE_RESP = 0x0100;
    //获取未读消息(注意消息去重)
    public final static int GET_UNREAD_MESSAGE_RESP = 0x0120;
    //发送消息报告回调(已发送、已接收、已读报告)
    public final static int REPORT_MESSAGE_STATUES_RESP = 0x0130;
    //发送消息取号回调(获取messageId)
    public final static int SEND_MESSAGE_RESP = 0x140;
    //获取未读消息数
    public final static int GET_UNREAD_MESSAGE_COUNT_RESP = 0x0150;
    //上传单个文件回调
    public final static int SINGLE_FILE_UPLOAD_RESP = 0x0200;
    //获取历史消息
    public final static int GET_HISTORY_MESSAGE_RESP = 0x0210;
    //收到消息报告回调
    public final static int MESSAGE_REPORT_STATUS_RESP = 0x0211;
    //消息被撤回
    public final static int MESSAGE_RECALL_RESP = 0x0212;
    //收到通知消息
    public final static int NOTIFY_MESSAGE_RESP = 0x0213;
    //消息发送失败
    public final static int MESSAGE_SEND_FAIL = 0x0214;
    //错误回调,返回BaseResp对象(BaseResp.msgCode和CmdMsgCode.Message模块请求码对应)
    public final static int MESSAGE_UNUSUAL_RESP = 0x0215;

    /**群组模块**/
    //创建群组回调
    public final static int CREATE_GROUP_RESP = 0x0300;
    //退出群聊
    public final static int QUIT_GROUP_RESP = 0x0301;
    //修改群名称
    public final static int MODIFY_GROUP_NAME_RESP = 0x0302;
    //修改群介绍公告
    public final static int MODIFY_GROUP_INTRO_RESP = 0x0303;
    //修改群通知
    public final static int MODIFY_GROUP_NOTICE_RESP = 0x0304;
    //邀请好友加入群聊
    public final statc int GROUP_INVITE_USER_RESP = 0x0305;
    //邀请好友应答
    public final static int GROUP_INVITE_USER_ACK_RESP = 0x0306;
   	//查询群成员列表
    public final static int QUERY_GROUP_USER_RESP = 0x0307;
    //查询群列表
    public final static int QUERY_GROUP_LIST_RESP = 0x0308;
    //添加群文件
    public final static int ADD_GROUP_FILE_RESP = 0x0309;
    //删除群文件
    public final static int DELETE_GROUP_FILE_RESP = 0x0310;
    //查找群文件列表
    public final static int FIND_LIST_GROUP_FILE_RESP = 0x311;
    //查询群信息
    public final static int QUERY_GROUP_INFO_RESP = 0x0312;
    //设置群聊免打扰
    public final static int SET_GROUP_DISTURB_RESP = 0x0313;
    //收到群邀请请求
    public final static int GROUP_INVITE_USER_REQ = 0x0314;
    //移除群成员
    public final static int REMOVE_GROUP_USER_RESP = 0x0315;
    //设置群成员角色
    public final static int SET_GROUP_USER_ROLE_RESP = 0x0316;
    //群禁言
    public final static int MUTE_GROUP_RESP = 0x0317;
    //设置群聊置顶
    public final static int SET_GROUP_TOP_RESP = 0x0318;
    //查找群用户信息
    public final static int FIND_GROUP_USER_INFO_RESP = 0x0319;
    //解散群组
    public final static int DISBAND_GROUP_RESP = 0x0320;
    //修改群昵称
    public final static int MODIFY_GROUP_NICKNAME_RESP = 0x0321;
    //群成员禁言/解禁
    public final static int MODIFY_GROUP_USER_MUTE_RESP = 0x0322;
    //获取群消息已读成员列表
    public final static int GET_GROUP_USER_READ_LIST_RESP = 0x0323;
    //拒接群呼叫
    public final static int GROUP_REFUSE_AV_CALL_RESP = 0x0324;
    //收到成员拒接呼叫
    public final static int GROUP_REFUSE_AV_CALL_REQ_RECEIVED = 0x0325;
    //错误回调,返回BaseResp对象(BaseResp.msgCode和CmdMsgCode.Group模块请求码对应)
    public final static int GROUP_UNUSUAL_RESP = 0x0326;


    /**客户端发送消息错误码**/
    //发送文件超过5MB
    public final static int SEND_FILE_TOO_LARGE = 0x0400;
    //发送文件失败
    public final static int SEND_FILE_FAIL = 0x0401;
    //发送失败
    public final static int SEND_FAIL = 0x0402;
    //发送音频超过60秒
    public final static int SEND_VOICE_TOO_LARGE = 0x0403;

    /**服务端错误码**/
    //TOKEN信息过期
    public final static int ERR_TOKEN_EXPIRED = 483;
    //需要用户重新连接
    public final static int ERR_NEED_CONNECT = 484;
    //用户被禁用或用户不存在
    public final static int ERR_APP_INIT_CODE = 485;
    //请重新登陆
    public final static int ERR_RELOGIN = 488;
    //群主不能移除自己
    public final static int ERR_GROUP_REMOVE_OWEN = 466;
}
//MsgCode及CommandType
public final class CmdMsgCode {

    /**
     * 用户模块
     */
    public static class User {
        //登录请求
        public static final int MSG_CODE_USER_LOGIN_REQ = 5;
        //查找用户请求
        public static final int MSG_CODE_FIND_USER_INFO_REQ = 9;
        //设置用户属性请求
        public static final int MSG_CODE_MODIFY_USER_INFO_REQ = 13;
        //登出请求
        public static final int MSG_CODE_USER_LOGOUT_REQ = 17;
    }

    /**
     * 好友模块
     */
    public static class Friend {
        //添加好友请求
        public static final int MSG_CODE_USER_ADD_FRIEND_REQ = 1;
        //添加好友应答请求
        public static final int MSG_CODE_USER_PASS_FRIEND_REQ = 3;
        //删除好友请求
        public static final int MSG_CODE_USER_DELETE_FRIEND_REQ = 5;
        //获取好友列表请求
        public static final int MSG_CODE_USER_QUERY_FRIEND_REQ = 7;
        //拉黑好友
        public static final int MSG_CODE_USER_ADD_BLACK_FRIEND_REQ = 9;
        //移除好友黑名单
        public static final int MSG_CODE_USER_REMOVE_BLACK_FRIEND_REQ = 11;
        //获取好友黑名单列表
        public static final int MSG_CODE_USER_GET_BLACK_FRIEND_LIST_REQ = 13;
        //设置好友免打扰
        public static final int MSG_CODE_USER_SET_FRIEND_DISTURB_REQ = 15;
        // 取消呼叫
        public static final int MSG_CODE_USER_CANCEL_AV_CALL_REQ = 17;
        // 拒绝呼叫
        public static final int MSG_CODE_USER_REFUSE_AV_CALL_REQ = 19;
        // 设置好友备注
        public static final int MSG_CODE_USER_SET_FRIEND_MARKNAME_REQ = 21;
        // 设置置顶聊天
        public static final int MSG_CODE_USER_SET_FRIEND_TOP_REQ = 23;
    }

    /**
     * 消息模块
     */
    public static class Message {
        //消息发送
        public static final int MSG_CODE_USER_SEND_MESSAGE_REQ = 1;
        //用户消息状态报告
        public static final int MSG_CODE_USER_REPORT_MESSAGE_STATUS_REQ = 3;
        //获取未读消息数
        public static final int MSG_CODE_USER_GET_UNREAD_MESSAGE_COUNT_REQ = 5;
        //获取未读消息
        public static final int MSG_CODE_USER_GET_UNREAD_MESSAGE_REQ = 7;
        //获取未读系统消息
        public static final int MSG_CODE_USER_GET_UNREAD_SYSTEM_MESSAGE_REQ = 9;
        // 获取历史消息
        public static final int MSG_CODE_USER_GET_HISTORY_MESSAGE_REQ = 11;

    }

    /**
     * 群组模块
     */
    public static class Group {
        //创建群组
        public static final int MSG_CODE_CREATE_GROUP_REQ = 1;
        //退出群组
        public static final int MSG_CODE_QUIT_GROUP_REQ = 3;
        //修改群主题(群名称)
        public static final int MSG_CODE_MODIFY_GROUP_NAME_REQ = 5;
        //修改群介绍
        public static final int MSG_CODE_MODIFY_GROUP_INTRO_REQ = 7;
        //修改群通知
        public static final int MSG_CODE_MODIFY_GROUP_NOTICE_REQ = 9;
        //添加群文件
        public static final int MSG_CODE_ADD_GROUP_FILE_REQ = 11;
        //删除群文件
        public static final int MSG_CODE_DELETE_GROUP_FILE_REQ = 13;
        //获取群文件列表
        public static final int MSG_CODE_LIST_GROUP_FILE_REQ = 15;
        //群邀请
        public static final int MSG_CODE_GROUP_INVITE_REQ = 17;
        //群邀请应答
        public static final int MSG_CODE_GROUP_INVITE_ACK_REQ = 19;
        //获取群成员
        public static final int MSG_CODE_QUERY_GROUP_USER_REQ = 21;
        // 改变群主 设为管理员等
        public static final int MSG_CODE_SET_GROUP_USER_ROLE_REQ = 23;
        // 获取群组列表
        public static final int MSG_CODE_QUERY_GROUP_LIST_REQ = 25;
        // 设置群消息免打扰
        public static final int MSG_CODE_SET_GROUP_USER_DISTURB_REQ = 27;
        // 移除群成员
        public static final int MSG_CODE_GROUP_REMOVE_USER_REQ = 29;
        // 获取群信息
        public static final int MSG_CODE_QUERY_GROUP_INFO_REQ = 31;
        // 拒绝呼叫
        public static final int MSG_CODE_GROUP_REFUSE_AV_CALL_REQ = 33;
        // 设置群昵称
        public static final int MSG_CODE_SET_GROUP_USER_NICKNAME_REQ = 35;
        // 解散群
        public static final int MSG_CODE_DISSOLVE_GROUP_REQ = 37;
        // 设置置顶聊天
        public static final int MSG_CODE_SET_GROUP_USER_TOP_REQ = 39;
        // 获取群组已读消息的详细信息
        public static final int MSG_CODE_ACQUIRE_GROUP_READ_MESSAGE_INFO_REQ = 41;
        // 群禁言
        public static final int MSG_CODE_MUTE_GROUP_REQ = 43;
        // 禁言群用户
        public static final int MSG_CODE_GROUP_USER_MUTE_REQ = 45;
        // 根据userId和groupId查询群用户信息
        public static final int MSG_CODE_GET_GROUP_USER_INFO_REQ = 47;
    }

    /**
     * 文件模块
     */
    public static class File {
        //单个文件上传,最大为5M
        public static final int MSG_CODE_SINGLE_FILE_REQ = 1;
    }
}

3.接口调用

一、系统模块(ACCESS)

1.初始化

CLVideoLive.getInstance().setAppId(it.appId)
CLVideoLive.getInstance().setAppKey(it.appSecret)

二、用户模块在(USER)

1、登录

使用场景:在新设备上初次登录,以及被踢、切换账号与注销登录后下一次登录,需要使用手动登录。对应用户手动输入登录账号密码的场景。

// 设置监听回调(各模块监听可设置唯一全局监听后自定义分发,也可多页面设置监听,注意监听移除时机)
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.ACCESS, LoginActivity.this);
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.USER, LoginActivity.this);


private void initLogin() {
    CLInitInfo clInitInfo = new CLInitInfo();
    clInitInfo.setAppUserId("接入IM服务唯一用户Id");

    CLVideoLive.getInstance().initLogin(getApplicationContext(), clInitInfo);
}

在登录界面实现CLMessageCallback接口:

    @Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.LOGIN_RESP:
                CLLoginResp clLoginResp = (CLLoginResp) message;
                if (clLoginResp.getCode() == VideoConstants.SUCCESS) {
                    CLUserInfo clUserInfo = clLoginResp.getUserInfo()
                    Log.d(TAG, "登录成功 -onMessage: " + clLoginResp.toString());
                } else {
                    if (clLoginResp.code == MessageCode.ERR_RELOGIN
                    || clLoginResp.code == MessageCode.ERR_APP_INIT_CODE
                    || clLoginResp.code == MessageCode.ERR_NEED_CONNECT
                    || clLoginResp.code == MessageCode.ERR_TOKEN_EXPIRED) {
                        //当前code下需重新调用初始化登录方法initLogin(),code详情查看消息码
                    }
                    Log.d(TAG, "登录失败 -onMessage: " + clLoginResp.toString());
                }
                break;
            default:
                break;
        }
    }

	@Override
    public void onStatus(int status, String msg) {
        tvConnectHint.setVisibility(View.VISIBLE);
        switch (status) {
            case ConnectionState.CONNECTION_CREATE:
                Log.d(TAG, "建立连接中...");
                break;
            case ConnectionState.CONNECTION_SUCCESS:
                Log.d(TAG, "连接成功,正在登录...");
                break;
            case ConnectionState.CONNECTION_FAIL:
                Log.d(TAG, "连接失败,请检测网络");
                break;
            default:
                Log.d(TAG, "连接状态:" + status + "-" + msg);
                break;
        }
    }

登录页面销毁移除监听回调:

    @Override
    protected void onDestroy() {
        super.onDestroy();
        CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.USER, this);
        CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.ACCESS, this);
    }

2、自动登录

使用场景:已登录用户重启应用时进行自动登录连接IM服务;
注意:登录失败后此接口失效,需重新调用登录接口(如多设备登录后被踢下线、账号被后台禁用等失败场景)

CLVideoLive.getInstance().autoLogin(getApplicationContext(), "接入IM服务唯一用户Id");

//监听回调实现步骤同初始化登录
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.ACCESS, this);
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.USER, this);

3、用户登出

CLVideoLive.getInstance().logout();

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.USER,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.USER, this);

//页面实现CLMessageCallback接口
@Override
public void onMessage(int msgCode, Object message) {
    switch (msgCode) {
        case MessageCode.LOGOUT_RESP:
             CLLogoutResp clLogoutResp = (CLLogoutResp) message;
             if (clLogoutResp.getCode() == VideoConstants.SUCCESS) {
                 Toast.makeText(getContext(), "退出成功", Toast.LENGTH_SHORT).show();
             }
             break;
         default:
             break;
     }
}

4、设置用户属性

//clUserInfo对象为登录后获取实例
CLUserInfo clUserInfo = new CLUserInfo();
//修改用户生日(如:20221215)
clUserInfo.setBirthday(birthday);
CLVideoLive.getInstance().modifyUserInfo(clUserInfo);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.USER,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.USER, this);

@Override
    public void onMessage(int msgCode, Object message) {
        LogUtils.d(VideoConstants.LOG_TAG, "message", message);
        switch (msgCode) {
            case MessageCode.MODIFY_USER_INFO_RESP:
               	CLModifyUserInfoResp clModifyUserInfoResp = (CLModifyUserInfoResp) message;
                if (clModifyUserInfoResp.getCode() == VideoConstants.SUCCESS) {
                	Toast.makeText(getContext(), "设置成功", Toast.LENGTH_SHORT).show();
             	}
                break;
            default:
                break;
        }
    }

5、查找用户信息

CLFindUserReq clFindUserReq = new CLFindUserReq();
clFindUserReq.setAppUserId("用户唯一Id");

CLVideoLive.getInstance().findUserInfo(clFindUserReq);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.USER,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.USER, this);

@Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.FIND_USER_INFO_RESP:
                CLFindUserResp clFindUserResp = (CLFindUserResp) message;
                if (clFindUserResp.getCode() == VideoConstants.SUCCESS) {
                    Log.d(TAG, "onMessage: " + clFindUserResp.toString());
                    if(null != clFindUserResp.getUserInfo() && !TextUtils.isEmpty(clFindUserResp.getUserInfo().getAppUserId())) {
                    	//展示用户信息clFindUserResp.getUserInfo()
                    } else {
                        Toast.makeText(getApplicationContext(), "用户不存在!", Toast.LENGTH_SHORT).show();
                    }
                }
                break;
            default:
                break;
        }
    }

三、好友模块(FRIEND)

1、添加好友

CLAddFriendReq clAddFriendReq = new CLAddFriendReq();
clAddFriendReq.setToAppUserId(friendAddItem.getAppUserId())
              .setToNickName(friendAddItem.getFriendName())
              .setCustom("自定义信息")
              .setMessage("加好友吗?小兄弟!");
CLVideoLive.getInstance().addFriend(clAddFriendReq);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.FRIEND,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.FRIEND, this);

		@Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
          	case MessageCode.ADD_FRIEND_RESP:
                CLAddFriendResp clAddFriendResp = (CLAddFriendResp) message;
                if (clAddFriendResp.getCode() == VideoConstants.SUCCESS) {
                    Toast.makeText(getApplicationContext(), "好友请求已发送~", Toast.LENGTH_SHORT).show();
                }
                break;
          	//收到好友请求(此监听code可设置全局监听实时收取好友请求消息)
            case MessageCode.FRIEND_REQUEST_RECEIVED:
                CLNewFriendRequestReceived clFriendRequstReceived = (CLNewFriendRequestReceived) message;
                Log.d(TAG, "onMessage: + FRIEND_REQUEST_RECEIVED " + clFriendRequstReceived.getReceiveNickname());
                break;
            default:
                break;
        }
    }

2、同意/拒绝好友请求

CLPassAddFriendReq clPassAddFriendReq = new CLPassAddFriendReq();
clPassAddFriendReq.setMessage("我同意啦")
			// 0拒绝,1同意
      .setPassType(1)
      .setToAppUserId("好友用户Id");
CLVideoLive.getInstance().passAddFriend(clPassAddFriendReq);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.FRIEND,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.FRIEND, this);

	@Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.PASS_ADD_FRIEND_RESP:
                CLPassAddFriendResp clPassAddFriendResp = (CLPassAddFriendResp) message;
                if (clPassAddFriendResp.getCode() == VideoConstants.SUCCESS) {
                    Toast.makeText(getApplicationContext(), "应答成功", Toast.LENGTH_LONG).show();
                } else {
                    Log.d(TAG, "onMessage: " + clPassAddFriendResp.toString());
                }
                break;
            default:
                break;
        }
    }

3、删除好友

CLDeleteFriendReq clDeleteFriendReq = new CLDeleteFriendReq();
clDeleteFriendReq.setToAppUserId("好友Id")
                .setToNickName("好友昵称");
CLVideoLive.getInstance().deleteFriend(clDeleteFriendReq);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.FRIEND,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.FRIEND, this);

	@Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.DELETE_FRIEND_RESP:
                CLDeleteFriendResp clDeleteFriendResp = (CLDeleteFriendResp) message;
                if (clDeleteFriendResp.getCode() == VideoConstants.SUCCESS) {
                    Log.d("TAG", "delete friend success.");
                }
                break;
            default:
                break;
        }
    }

4、查询好友列表

CLQueryFriendListReq clQueryFriendListReq = new CLQueryFriendListReq();
clQueryFriendListReq.setPage(0)//	页码
										.setPageSize(10);//	页大小
CLVideoLive.getInstance().queryFriendList(clQueryFriendListReq);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.FRIEND,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.FRIEND, this);

@Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.QUERY_FRIEND_LIST_RESP:
                CLQueryFriendListResp clQueryFriendListResp = (CLQueryFriendListResp) message;
                break;
            default:
                break;
        }
    }

5、黑名单

1.获取黑名单列表

CLBlockedFriendListReq clBlockedFriendListReq = new CLBlockedFriendListReq();
clBlockedFriendListReq.setPage(0)//页码
                .setPageSize(10);//页大小	

CLVideoLive.getInstance().getBlockedFriendList(clBlockedFriendListReq);

2.拉入黑名单

CLBlockedFriendReq clBlockedFriendReq = new CLBlockedFriendReq();
clBlockedFriendReq.setBlackAppUserId("好友Id")
                .setBlackNickName("好友昵称");

CLVideoLive.getInstance().addBlockedFriend(clBlockedFriendReq);

2.移出黑名单

CLBlockedFriendReq clBlockedFriendReq = new CLBlockedFriendReq();
clBlockedFriendReq.setBlackAppUserId("好友Id")
                .setBlackNickName("好友昵称");

CLVideoLive.getInstance().removeBlockedFriend(clBlockedFriendReq);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.FRIEND,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.FRIEND, this);

	@Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.GET_BLOCKED_FRIEND_LIST_RESP:
                CLBlockedFriendListResp clBlockedFriendListResp = (CLBlockedFriendListResp) message;
                Log.d(TAG, "黑名单列表 onMessage:" + clBlockedFriendListResp.toString());
                addUserInfo(clBlockedFriendListResp);
                break;
            case MessageCode.ADD_BLOCKED_FRIEND_RESP:
                CLBlockedFriendResp clBlockedFriendResp = (CLBlockedFriendResp) message;
                if (clBlockedFriendResp.getCode() == VideoConstants.SUCCESS) {
                    Log.d(TAG, "拉入黑名单成功 onMessage: " + clBlockedFriendResp.getMsg());
                }
                break;
            case MessageCode.REMOVE_BLOCKED_FRIEND_RESP:
                CLBlockedFriendResp clBlockedFriendResp = (CLBlockedFriendResp) message;
                if (clBlockedFriendResp.getCode() == VideoConstants.SUCCESS) {
                    Log.d(TAG, "移出黑名单成功 onMessage: " + clBlockedFriendResp.getMsg());
                }
                break;
            default:
                break;
        }
    }

6、设置好友聊天置顶

CLSetFriendTopReq clSetFriendTopReq = new CLSetFriendTopReq();
//置顶:1 关闭:0
clSetFriendTopReq.setIsTop(1)
                .setFriendAppUserId("好友Id");
CLVideoLive.getInstance().setFriendTop(clSetFriendTopReq);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.FRIEND,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.FRIEND, this);

	@Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.SET_FRIEND_TOP_RESP:
                CLSetFriendTopResp clSetFriendTopResp = (CLSetFriendTopResp) message;
                if (clSetFriendTopResp.getCode() == VideoConstants.SUCCESS) {
                    Log.d(TAG, "设置成功 onMessage: ");
                }
                break;
        }
    }

7、设置好友免打扰

CLSetFriendDisturbReq clSetFriendDisturbReq = new CLSetFriendDisturbReq();
//免打扰开启:1 关闭:0
clSetFriendDisturbReq.setDisturb(1)
                .setFriendAppUserId("好友Id");
CLVideoLive.getInstance().setFriendDisturb(clSetFriendDisturbReq);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.FRIEND,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.FRIEND, this);

	@Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.SET_FRIEND_DISTURB_RESP:
                CLSetFriendDisturbResp clSetFriendDisturbResp = (CLSetFriendDisturbResp) message;
                if (clSetFriendDisturbResp.getCode() == VideoConstants.SUCCESS) {
                    Log.d(TAG, "设置成功 onMessage: ");
                }
                break;
        }
    }

8、设置好友备注

CLSetFriendMarkReq clSetFriendMarkReq = new CLSetFriendMarkReq();
clSetFriendMarkReq.setFriendAppUserId("好友Id")
                .setMarkName("备注名");
CLVideoLive.getInstance().setFriendMarkName(clSetFriendMarkReq);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.FRIEND,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.FRIEND, this);

	@Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.SET_FRIEND_MARK_NAME_RESP:
                CLSetFriendMarkResp clSetFriendMarkResp = (CLSetFriendMarkResp) message;
                if (clSetFriendMarkResp.getCode() == VideoConstants.SUCCESS) {
                    Log.d(TAG, "设置成功 onMessage: ");
                }
                break;
        }
    }

9、音视频呼叫操作

1.取消呼叫

CLCancelAvCallReq clCancelAvCallReq = new CLCancelAvCallReq();
clCancelAvCallReq.setMessageId("消息Id")
                 .setToAppUserId("好友Id");
CLVideoLive.getInstance().cancelAvCall(clCancelAvCallReq);

2.拒绝呼叫请求

CLRefuseAvCallReq clRefuseAvCallReq = new CLRefuseAvCallReq();
clRefuseAvCallReq.setMessageId("消息Id")
                 .setFriendAppUserId("好友Id");
CLVideoLive.getInstance().refuseAvCall(clRefuseAvCallReq);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.FRIEND,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.FRIEND, this);

@Override
public void onMessage(int msgCode, Object message) {
       switch (msgCode) {
       		case MessageCode.CANCEL_AV_CALL_REQ_RECEIVED://收到取消呼叫
            case MessageCode.REFUSE_AV_CALL_REQ_RECEIVED://收到拒绝呼叫
            case MessageCode.CANCEL_AV_CALL_RESP://取消呼叫返回
            case MessageCode.REFUSE_AV_CALL_RESP://拒绝呼叫返回
                stopPush();
            	break;
       }
}

四、消息模块(MESSAGE)

主要类介绍

1、消息类CLMessage

//关键字段介绍
public class CLMessage extends BaseResp {
    /**
     * 消息Id
     **/
    private String messageId;
    /**
     * 发送者appUserId
     **/
    private String appUserId;
    /**
     * 聊天属性:1单聊,2群聊
     **/
    private ChatMessageType messageType;
    /**
     * 消息类型:见ChatMessageBodyType类介绍
     **/
    private ChatMessageBodyType contentType;
    /**
     * 消息内容:
     * 发送文件时为本地文件绝对路径,发送成功自动转换为文件下载地址
     * 若设置文件url,注意contentCustom字段设置为true
     **/
    private String content;
    /**
     * 消息会话id :单聊为接收者的appUserId, 群聊为groupId
     **/
    private String sessionId;
    /**
     * 会话唯一Id(区别于sessionId,单聊为好友的appUserId, 群聊为groupId)
     **/
    private String conversationId;
    /**
     * 发送时间戳
     **/
    private long timestamp;
    /**
     * 扩展内容 消息类型为8,9,10时map中存放“roomId: 房间Id号”和“roomSecret: 房间密钥”
     **/
    private Map<String, String> ext;
    /**
     * 消息方位:发送、接收
     **/
    private ChatMsgDirection direction;
    /**
     * 消息类型为群聊时,语音或视频呼叫组播发送的群用户
     **/
    private List<String> targetAppUserId;
    /**
     * 0表示非阅后即焚消息,1表示阅后即焚消息
     **/
    private int isBurn;
    /**
     * 1表示消息已送达状态报告,2表示消息已接收状态报告,3表示消息已读状态报告
     **/
    private int readReport;
    /**
     * 发送消息状态码,等于0时表示发送成功,非0时发送失败,见MessageCode类客户端发送错误码
     **/
    private int sendCode;
    /**
     * 语音消息消息时长,单位为秒,只有消息类型为VOICE 需要设置
     **/
    private double voiceDuration;
    /**
     * content为附件时是否自定义内容,无需文件服支持
     **/
    private boolean contentCustom;
    
    //....
}

2、消息方位类CLMessage.ChatMsgDirection

public enum ChatMsgDirection {
        /**
         * 发送
         */
        SEND(1),
        /**
         * 接收
         */
        RECEIVED(2);
}

3、聊天属性类CLMessage.ChatMessageType

public enum ChatMessageType {
        /**
         * 单聊
         */
        CHAT(1),
        /**
         * 群聊
         */
        GROUP(2),
}

4、消息类型类CLMessage.ChatMessageBodyType

public enum ChatMessageBodyType {
        /**
         * 撤回消息
         */
        RECALL(0),
        /**
         * 文本消息
         */
        TEXT(1),
        /**
         * 图片消息
         */
        IMAGE(2),
        /**
         * 语音消息
         */
        VOICE(3),
        /**
         * 视频消息
         */
        VIDEO(4),
        /**
         * 文件消息
         */
        FILE(5),
        /**
         * 地图位置消息
         */
        MAP(6),
        /**
         * 自定义消息
         */
        CUSTOM(7),
        /**
         * 视频呼叫消息
         */
        VIDEO_CALL(8),
        /**
         * 语音呼叫消息
         */
        VOICE_CALL(9),
        /**
         * 直播消息
         */
        LIVE(10),
        /**
         * 通知消息
         */
        NOTIFY(11),
        /**
         * 未知消息
         */
        UNKNOWN(999);
}

5、消息报告状态类CLReportMessageStatusReq

public class CLReportMessageStatusReq extends BaseReq {

    //发送
    public static final int SEND = 1;
    //接收
    public static final int RECEIVED = 2;
    //读取
    public static final int READ = 3;

    /**
     * 1单聊,2群聊
     */
    private String messageType;
    //会话Id,单聊为好友userId,群聊为GroupId
    private String sessionId;
    //消息Id
    private String messageId;
    /**
     * 报告状态:1已发送,2已接收,3已阅读
     */
    private Integer status;
	//消息对象
    private CLMessage clMessage;
}

1、发送消息

//构造单聊文本消息
CLMessage chatMessage = new CLMessage();
chatMessage.setDirection(CLMessage.ChatMsgDirection.SEND);//发送消息
           .setMessageType(CLMessage.ChatMessageType.CHAT);//聊天类型:单聊、群聊
           .setContentType(CLMessage.ChatMessageBodyType.TEXT);//发送消息类型
           .setContent(content);//消息内容,文件等类型时为本地文件路径
           .setTimestamp(System.currentTimeMillis());//时间戳
           .setSessionId("接收者Id");//会话Id,单聊为好友userId,群聊为GroupId
           .setVoiceDuration(second)//音频时长,会检测时长是否超限60S
           .setExt(ext);//扩展字段,例如发送文件时的文件名、文件大小、音视频时长
//
CLVideoLive.getInstance().sendChatMessage(chatMessage);

取号回调(获取messageId)

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.MESSAGE,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.MESSAGE, this);

	@Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.SEND_MESSAGE_RESP:
				CLSendMessageResp clSendMessageResp = (CLSendMessageResp) message;
                if (clSendMessageResp.getCode() == VideoConstants.SUCCESS) {
                    Toast.makeText(getApplicationContext(), "获取消息Id成功", Toast.LENGTH_SHORT).show();
                	String messageId = clSendMessageResp.getMessageId();
                    //更新发送消息的Id
                    chatMessage.setMessageId(messageId);
                    //发送已发送消息报告
                    reportMessageStatus(chatMessage, CLReportMessageStatusReq.SEND)
                }
            break;
        }
    }

发送消息报告(服务端根据此报告送达消息)

public void reportMessageStatus(CLMessage chatMessage, int status) {
	CLReportMessageStatusReq clReportMessageStatusReq = new CLReportMessageStatusReq();
    clReportMessageStatusReq.setMessageId(chatMessage.getMessageId())
                .setSessionId(mConversionId)//单聊为好友Id,群聊为groupId
                .setClMessage(chatMessage)//此前获取到消息ID的消息对象
                .setMessageType(String.valueOf(getChatMessageType().getCode()))
                .setStatus(status);
    CLVideoLive.getInstance().reportMessageStatus(clReportMessageStatusReq);
}

2、设置监听回调(收消息):

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.MESSAGE,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.MESSAGE, this);

@Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.REPORT_MESSAGE_STATUES_RESP:
                CLReportMessageStatusResp reportMessageResp = (CLReportMessageStatusResp) message;
                if (reportMessageResp.getCode() == VideoConstants.SUCCESS) {
                	Log.d("TAG", "发送消息报告成功")
                }
                break;
            case MessageCode.MESSAGE_SEND_FAIL:
                CLMessage failMessage = (CLMessage) message;
                Log.d("TAG", "发送消息失败code:" + failMessage.getSendCode())
                break;
            case MessageCode.RECEIVE_MESSAGE_RESP:
                CLMessage clMessage = (CLMessage)message;
                Log.d("TAG", "收到消息")
                //发送已接收或已阅读消息报告
                reportMessageStatus(chatMessage, CLReportMessageStatusReq.READ)
				break; 
            case MessageCode.MESSAGE_RECALL_RESP:
                CLMessage recallMessage = (CLMessage) message;
                Log.d("TAG", "撤回消息Id:" + recallMessage.getMessageId())
                break;
            case MessageCode.MESSAGE_REPORT_STATUS_RESP:
                CLMessage reportMessage = (CLMessage) message;
               	Log.d("TAG", "收到消息状态报告,状态:" + reportMessage.getReadReport())
                break;
            case MessageCode.NOTIFY_MESSAGE_RESP:
                CLMessage notifyMessage = (CLMessage) message;
                String eventType = notifyMessage.getExt().get("eventType");
            	String toAppUserId = notifyMessage.getExt().get("toAppUserId");
            	String fromAppUserId = notifyMessage.getExt().get("fromAppUserId");
               	Log.d("TAG", "收到通知消息,消息类型:" + eventType)
                break;
        }
    }

eventType定义:

eventType 定义
100 toAppUserId被fromAppUserId拉进群
101 fromAppUserId把toAppUserId踢出群
102 fromAppUserId禁言toAppUserId
103 fromAppUserId取消禁言toAppUserId
104 fromAppUserId任命toAppUserId为管理员
105 fromAppUserId取消toAppUserId为管理员
106 fromAppUserId修改了群介绍
107 fromAppUserId修改了加群认证方式 (暂无)
108 fromAppUserId把群转让给了toAppUserId(暂无)
109 fromAppUserId退出了群
110 fromAppUserId解散了群
111 fromAppUserId开启群禁言
112 fromAppUserId取消群禁言

3、获取历史消息

CLGetHistoryMessageReq clGetHistoryMessageReq = new CLGetHistoryMessageReq();
clGetHistoryMessageReq.setMessageType(mMessageType)//1单聊,2群聊
                .setFromMsgId(fromMsgId)//拉取消息的起始id,为空则从最新值开始
                .setPageSize(10)//页大小
                .setSessionId(mConversionId);//单聊为好友的appUserId,群聊为群ID
CLVideoLive.getInstance().getHistoryMessage(clGetHistoryMessageReq);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.MESSAGE,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.MESSAGE, this);

@Override
public void onMessage(int msgCode, Object message) {
    switch (msgCode) {
        case MessageCode.GET_HISTORY_MESSAGE_RESP:
            CLGetHistoryMessageResp clGetHistoryMessageResp = (CLGetHistoryMessageResp) message;
            Log.d("TAG", "历史消息列表")
            //未读历史消息追加已读消息报告
            reportMessageStatus(clGetHistoryMessageResp)
            break;
    }
}

private void reportMessageStatus(CLGetHistoryMessageResp clGetHistoryMessageResp) {
	List<CLMessage> messageList = clGetHistoryMessageResp.getClMessageList();
    for (CLMessage clMessage : messageList) {
        //2表示消息已送达状态报告,3表示消息已读状态报告
        if (CLMessage.ChatMessageBodyType.RECALL == clMessage.getContentType())
                || CLMessage.ChatMessageBodyType.NOTIFY == clMessage.getContentType()
                || clMessage.getReadReport() == 2
                || clMessage.getReadReport() == 3 || clMessage.getStatus() == 3) {
            continue;
        }
        reportMessageStatus(clMessage, CLReportMessageStatusReq.READ);
    }
}

4、获取未读消息

CLGetUnReadMessageReq clGetUnReadMessageReq = new CLGetUnReadMessageReq();
clGetUnReadMessageReq.setPageSize(20);//页大小

CLVideoLive.getInstance().getUnReadMessage(clGetUnReadMessageReq);

设置监听回调:

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.MESSAGE,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.MESSAGE, this);

@Override
public void onMessage(int msgCode, Object message) {
    switch (msgCode) {
         case MessageCode.GET_UNREAD_MESSAGE_RESP:
                CLGetUnReadMessageResp clGetUnReadMessageResp = (CLGetUnReadMessageResp) message;
                Log.d("TAG", "历史消息列表")
            	//未读消息追加已读消息报告
                reportMessageStatus(clGetUnReadMessageResp);
                break;
    }
}

private void reportMessageStatus(CLGetUnReadMessageResp clGetUnReadMessageResp) {
	List<CLMessage> messageList = clGetUnReadMessageResp.getClMessageList();
   	//TODO 需和本地消息去重(本地已读消息不需要再发送已读报告)
    for (CLMessage clMessage : messageList) {
        reportMessageStatus(clMessage, CLReportMessageStatusReq.READ);
    }
}

五、群组模块(GROUP)

1、创建群组

CLCreateGroupReq clCreateGroupReq = new CLCreateGroupReq();
clCreateGroupReq.setGroupName("群名称")
        .setGroupIntro("有事没事进来吹吹水");
CLVideoLive.getInstance().createGroup(clCreateGroupReq);

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.GROUP, this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.MESSAGE, this);

@Override
public void onMessage(int msgCode, Object message) {
    switch (msgCode) {
        case MessageCode.CREATE_GROUP_RESP:
            CLCreateGroupResp clCreateGroupResp = (CLCreateGroupResp) message;
            String groupId = clCreateGroupResp.getGroupId();
            String msg = clCreateGroupResp.getMsg();
            Log.d("TAG", "onMessage: msg:" + msg + ",groupId:" + groupId);
            // 创建群分为两步,第一步先创建群,创建成功后,第二部邀请选择的群成员
            if (clCreateGroupResp.getCode() == VideoConstants.SUCCESS) {
                inviteGroupMembers(groupId);
            }
            break;
    }
}

2、邀请好友进群

private void inviteGroupMembers(String groupId) {
    CLGroupInviteUserReq clGroupInviteUserReq = new CLGroupInviteUserReq();
    clGroupInviteUserReq.setGroupId(groupId)
                .setGroupName(getGroupName())
                .setMessage("你好")
                .setMagree(1)//是否需要邀请用户同意进群:1需要、2不需要
                .setToSdkUserIdList(toAppUserIdList);

    CLVideoLive.getInstance().groupInviteUser(clGroupInviteUserReq);
}

3、退出群

CLQuitGroupReq clQuitGroupReq = new CLQuitGroupReq();
clQuitGroupReq.setGroupId("群Id")

CLVideoLive.getInstance().quitGroup(clQuitGroupReq);

4、修改群群名称

CLModifyGroupInfoReq clModifyGroupInfoReq = new CLModifyGroupInfoReq();
clModifyGroupInfoReq.setGroupId(mGroupId)
    .setGroupName("群名称");

CLVideoLive.getInstance().modifyGroupName(clModifyGroupInfoReq);

5、修改群介绍

CLModifyGroupInfoReq clModifyGroupInfoReq = new CLModifyGroupInfoReq();
clModifyGroupInfoReq.setGroupId(mGroupId)
    .setGroupIntro("群介绍");

CLVideoLive.getInstance().modifyGroupIntro(clModifyGroupInfoReq);

6、修改群通知

CLModifyGroupInfoReq clModifyGroupInfoReq = new CLModifyGroupInfoReq();
clModifyGroupInfoReq.setGroupId(mGroupId)
    .setGroupNotice("群通知");

CLVideoLive.getInstance().modifyGroupNotice(clModifyGroupInfoReq);

7、群邀请回应

CLGroupInviteUserAckReq clGroupInviteUserAckReq = new CLGroupInviteUserAckReq();
clGroupInviteUserAckReq.setGroupId(groupId)
        .setGroupName(groupName)
        .setInviteAppUserId(inviteAppUserId)
        .setInviteNickname(inviteNickname)
    	//  0拒绝,1同意
        .setAckType(1);
CLVideoLive.getInstance().groupInviteAckUser(clGroupInviteUserAckReq);

8、查询群成员列表

CLQueryGroupUserReq clQueryGroupUserReq = new CLQueryGroupUserReq();
clQueryGroupUserReq.setGroupId(mGroupId)
                .setPage(0)//页码
                .setPageSize(20);//页大小

CLVideoLive.getInstance().queryGroupUser(clQueryGroupUserReq);

//回调
@Override
public void onMessage(int msgCode, Object message) {
   switch (msgCode) {
       case MessageCode.QUERY_GROUP_USER_RESP:
            CLQueryGroupUserResp clQueryGroupUserResp = (CLQueryGroupUserResp) message;
            List<CLSimpleUserInfo> userInfos = clQueryGroupUserResp.getUserInfos();
            break;
     }
}

9、查询当前用户的群列表

CLQueryGroupListReq clQueryGroupListReq = new CLQueryGroupListReq();
clQueryGroupListReq.setPage(0)
                .setPageSize(20);
CLVideoLive.getInstance().queryGroupList(clQueryGroupListReq);

	//回调
	@Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.QUERY_GROUP_LIST_RESP:
                CLQueryGroupListResp clQueryGroupListResp = (CLQueryGroupListResp) message;
                List<CLGroupInfo> groupList = clQueryGroupListResp.getGroupList();
                Log.d(TAG, "onMessage: groupList:" + groupList.size());
                break;
            default:
                break;
        }
    }

10、获取群文件列表

CLFindGroupFileListReq clFindGroupFileListReq = new CLFindGroupFileListReq();
clFindGroupFileListReq.setGroupId(mGroupId)
      .setPage(0)
      .setPageSize(20);

CLVideoLive.getInstance().findGroupFileList(clFindGroupFileListReq);

11、添加群文件

CLAddGroupFileReq clAddGroupFileReq = new CLAddGroupFileReq();
clAddGroupFileReq.setGroupId(mGroupId)
        .setFileName(getFileNameByPath(filePath))
        .setFilePath(filePath)
        .setFileSize(FileUtils.getBytesLength(filePath));
CLVideoLive.getInstance().addGroupFile(clAddGroupFileReq);

12、删除群文件

CLDeleteGroupFileReq clDeleteGroupFileReq = new CLDeleteGroupFileReq();
clDeleteGroupFileReq.setGroupId(mGroupId)
     .setFileId("");

CLVideoLive.getInstance().deleteGroupFile(clDeleteGroupFileReq);

13、解散群组

CLDisbandGroupReq clDisbandGroupReq = new CLDisbandGroupReq();
clDisbandGroupReq.setGroupId(mGroupId);
CLVideoLive.getInstance().disbandGroup(clDisbandGroupReq);

14、查询群信息

CLQueryGroupInfoReq clQueryGroupInfoReq = new CLQueryGroupInfoReq();
clQueryGroupInfoReq.setGroupId("groupId");
CLVideoLive.getInstance().queryGroupInfo(clQueryGroupInfoReq);

15、设置群聊免打扰

CLSetGroupDisturbReq clSetGroupDisturbReq = new CLSetGroupDisturbReq();
clSetGroupDisturbReq.setGroupId(mGroupId)
                .setDisturb(1);//1开启免打扰、0关闭免打扰

CLVideoLive.getInstance().setGroupDisturbStatus(clSetGroupDisturbReq);

16、收到新群邀请请求

 @Override
    public void onMessage(int msgCode, Object message) {
        switch (msgCode) {
            case MessageCode.GROUP_INVITE_USER_REQ:
                CLNewGroupInviteReceived clNewGroupInviteReq = (CLNewGroupInviteReceived) message;
                Log.d(TAG, "收到新群邀请:" + clNewGroupInviteReq.getGroupName());
                break;
        }
}

17、移除群成员

CLRemoveGroupUserReq clRemoveGroupUserReq = new CLRemoveGroupUserReq()
clRemoveGroupUserReq.setRemoveUserId(modifyCLSimpleUserInfo.getAppUserId())
                     .setGroupId("mGroupId")
CLVideoLive.getInstance().removeGroupUser(clRemoveGroupUserReq)

18、设置群成员角色

//普通成员无权操作
CLSetGroupUserRoleReq clSetGroupUserRoleReq = new CLSetGroupUserRoleReq()
clSetGroupUserRoleReq.setAppUserRole(CLQueryGroupUserReq.OWNER)//"操作用户群角色"
                	.setSetAppUserId("群成名Id")
                	.setSetRole("群成员角色") //设置群主时,群自动转让
                	.setGroupId("mGroupId");
CLVideoLive.getInstance().setGroupUserRole(clSetGroupUserRoleReq);

//CLQueryGroupUserReq类介绍
public class CLQueryGroupUserReq extends BaseReq {
    /**
     * 群主
     */
    public static final int OWNER = 1;
    /**
     * 普通群成员
     */
    public static final int MEMBER = 2;
    /**
     * 群管理员
     */
    public static final int ADMIN = 3;
}

19、群禁言

CLMuteGroupReq clMuteGroupReq = new CLMuteGroupReq();
clMuteGroupReq.setGroupId(mGroupId)
              .setIsMute(1);//1:开启群禁言、0:关闭
CLVideoLive.getInstance().muteGroup(clMuteGroupReq);

20、设置群聊置顶

CLModifyGroupTopReq clModifyGroupTopReq = new CLModifyGroupTopReq();
clModifyGroupTopReq.setGroupId(mGroupId)
                .setIsTop(1);//1:置顶、0:取消置顶
CLVideoLive.getInstance().modifyGroupTop(clModifyGroupTopReq);

21、查找群用户信息

CLFindGroupUserReq clFindGroupUserReq = new CLFindGroupUserReq();
clFindGroupUserReq.setGroupId("群Id")
                .setAppUserId("群用户Id");
CLVideoLive.getInstance().findGroupUser(clFindGroupUserReq);

22、修改群昵称

CLGroupUserNickNameReq clGroupUserNickNameReq = new CLGroupUserNickNameReq();
clGroupUserNickNameReq.setGroupId("mGroupId")
                .setNickName("groupNickName");
CLVideoLive.getInstance().modifyGroupNickName(clGroupUserNickNameReq);

23、群成员禁言/解禁

CLModifyGroupUserMuteReq clModifyGroupUserMuteReq = new CLModifyGroupUserMuteReq();
clModifyGroupUserMuteReq.setMute(1)//1:禁言、0:解禁
                .setGroupId("mGroupId")
                .setMemberAppUserId("memberAppUserIds");
CLVideoLive.getInstance().modifyGroupUserMute(clModifyGroupUserMuteReq);

24、获取群消息已读成员列表

CLAcquireGroupReadMessageInfoReq clGroupReadMessageInfoReq = new CLAcquireGroupReadMessageInfoReq()
    
clGroupReadMessageInfoReq.setGroupId("mGroupId")
                .setMessageId("messageId");
CLVideoLive.getInstance().acquireGroupReadStatus(clGroupReadMessageInfoReq);

25、音视频呼叫操作

1.拒接群呼叫

CLGroupRefuseAvCallReq clGroupRefuseAvCallReq = new CLGroupRefuseAvCallReq();
clGroupRefuseAvCallReq.setGroupId("mGroupId")
                      .setMessageId("messageId")
                      .setTargetAppUserId(targetAppUserId);//此次群呼叫成员列表
CLVideoLive.getInstance().groupRefuseAvCall(clGroupRefuseAvCallReq);

2.收到成员拒接呼叫

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.GROUP,this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.GROUP, this);

@Override
public void onMessage(int msgCode, Object message) {
       switch (msgCode) {
       		case MessageCode.GROUP_REFUSE_AV_CALL_RESP:
               	Log.d("TAG", "拒接成功");
            	break;
           case MessageCode.GROUP_REFUSE_AV_CALL_REQ_RECEIVED:
                CLGroupRefuseAvCallReceived clGroupRefuseAvCallReceived = (CLGroupRefuseAvCallReceived) message;
				Log.d("TAG", "拒接呼叫成员Id:" + clGroupRefuseAvCallReceived.getRefuseAppUserId());
               break;
       }
}

26、申请入群

//请求前设置回调
CLVideoLive.getInstance().addMessageCallback(CommandTypeEnum.GROUP, this);
//页面销毁时注销监听回调
CLVideoLive.getInstance().removeMessageCallback(CommandTypeEnum.GROUP, this);

CLGroupApplyToJoinReq gLGroupApplyToJoinReq = CLGroupApplyToJoinReq()
gLGroupApplyToJoinReq.setGroupId("群Id")
CLVideoLive.getInstance().applyToJoinGroupReq(gLGroupApplyToJoinReq)

@Override
public void onMessage(int msgCode, Object message) {
    switch (msgCode) {
        case MessageCode.GROUP_APPLY_JOIN_RESP:
            CLGroupApplyToJoinResp cLGroupApplyToJoinResp = (CLGroupApplyToJoinResp) message;
            if (cLGroupApplyToJoinResp.getCode() == VideoConstants.SUCCESS) {
                Log.d("TAG", "申请入群成功");
            }
            break;
    }
}

六、系统

1、获取系统未读消息(新好友请求、新群聊邀请)

使用场景:离线再登录请求系统未读消息,用于获取新好友请求、新群聊邀请消息

CLGetUnReadSystemMessageReq clGetUnReadSystemMessageReq = new CLGetUnReadSystemMessageReq();
clGetUnReadSystemMessageReq.setPageSize(20)//页大小,未读消息可能过多,可分页请求
                .setFromMsgId("");//拉取消息的起始id,为空则从最新值开始	

CLVideoLive.getInstance().getUnReadSystemMessage(clGetUnReadSystemMessageReq);

//设置监听回调:见好友、群聊模块
//分别为收到好友请求(MessageCode.FRIEND_REQUEST_RECEIVED)
//收到新群聊消息回调(MessageCode.GROUP_INVITE_USER_REQ)

温馨提示:
1、在调用各个接口方法之前请确保已经设置了监听,否则会接收不到回调数据!!!
2、发送请求基类BaseReq、请求应答基类BaseResp都包含字段commandId,同一个请求应答返回的commandId值相同,可根据该值判断是否是当前请求的回调。

七、历史版本

发布日期 发布版本 更新说明
2021-12-15 V1.0.0 初版发布