聊天功能
当用户进入房间,聊天服务自动连接。
发送聊天
发送聊天消息,主播端老师和进入房间的学生都可以接收到消息
public void send(String msg) {
VHClass.getInstance().sendChat(msg, new VHClass.RequestCallback() {
@Override
public void onSuccess() {
Toast.makeText(context, "发送成功", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(int errorCode, String errorMsg) {
Toast.makeText(context, "发送失败 " + errorMsg, Toast.LENGTH_SHORT).show();
}
});
}
接收聊天
在进入房间时设置房间回调(ClassCallback),其中有一个方法 onChatReceived()
聊天参数 | 描述 |
---|---|
account_id | 发送人ID |
user_name | 用户昵称 |
avatar | 头像 |
time | 发送时间 |
role | 角色信息 1:老师 2:学员 3:助教 4:嘉宾 5:监课 |
ChatData | 发送的消息内容 |
@Override
public void onChatReceived(ChatServer.ChatInfo chatInfo) {
switch (chatInfo.event) {
case IConnectService.eventMsgKey:
if (chatFragment != null)
chatFragment.updateData(chatInfo);
break;
}
}
获取最近的N条聊天信息
获取最近的历史聊天记录
VHClass.getInstance().getChat(num, new ChatServer.ChatRecordCallback() {
@Override
public void onDataLoaded(List<ChatServer.ChatInfo> newList) {
if (newList.size() > 0) {
chatAdapter.updateDataSourceList(newList, false);
}
}
@Override
public void onError(int errorCode, String messaage) {
}
});
分页获取聊天信息
VHClass.getInstance().getChatByPage(curPage,pageSize, ChatServer.ChatRecordCallback callback);