IM SDK for HarmonyOS 使用指南
IMSDK简介
1.功能目标
开发者在成功接入IMSDK后,无需部署任何服务器即可拥有双人及多人的即时通讯能力。
2.SDK目录讲解
-
库
youme_im.har包含了必须的接口和so库,请导入HarmonyOS工程。
3.关键类及描述
-
YIMClient
IM SDK引擎服务类,单例模式。该类提供SDK操作的相关方法,例如:初始化,登录,登出,消息发送等。 -
YIMObserver
观察者类,监听IM被动收到的消息,例如收到文本语音消息、他人进出房间等。 -
YIMDefine
IM类型定义的命名空间,用法例如:YIMDefine.YIMErrorcode 或者 YIMDefine.YIMChatType.ChatType_PrivateChat -
YIMMessage
消息类的命名空间,用法例如:YIMMessage.Msg -
YIMMessage.Msg
IM消息类,包含消息体和消息基本属性:例如消息ID,消息类型,发送者ID,接收者ID等信息。 -
YIMMessage.BodyBase
IM消息体基类 -
YIMMessage.BodyAudio
IM语音消息类,包含语音消息除基本属性外的其它信息:例如语音时长,语音本地存放地址,语音文件大小等信息。 -
YIMMessage.BodyText
IM文本消息类,包含文本消息除基本属性外的其它信息:文本内容。 -
YIMMessage.BodyCustom
IM自定义消息类,包含自定义消息除基本属性外的其它信息:自定义消息内容。 -
YIMMessage.BodyFile
IM文件消息类,包含文件消息除基本属性外的其它信息:文件名,文件大小,文件类型,文件扩展信息等。 -
YIMMessage.BodyGift
IM礼物消息类,包含礼物消息除基本属性外的其它信息:礼物ID,礼物数量,主播ID,礼物信息。
4.消息类型定义
//消息类型
export enum YIMMessageBodyType
{
MessageBodyType_Unknow = 0,
MessageBodyType_TXT = 1, //文本消息
MessageBodyType_CustomMesssage = 2,
MessageBodyType_Emoji = 3,
MessageBodyType_Image = 4,
MessageBodyType_Voice = 5, //语音消息
MessageBodyType_Video = 6,
MessageBodyType_File = 7,
MessageBodyType_Gift = 8
}5.聊天类型定义
export enum YIMChatType
{
ChatType_Unknow = 0,
ChatType_PrivateChat = 1, //私聊
ChatType_RoomChat = 2, //聊天室
ChatType_Multi = 3,
}IMSDK操作指引
申请使用游密IM引擎SDK
- 首先请与游密商务联系,提供公司名称、游戏的名称、联系人电话、邮箱、 QQ等以申请IM引擎的使用权限。审批通过后会得到有效的AppKey和AppSecret,这些信息属于私密信息,请妥善保管。
导入SDK
两种方法导入HAR包:
1. 手动导入
下载youme_im_3.0.11.har包,放到⼯程libs中。在⼯程中配置引⽤:
"dependencies": {
"@youme/im":"file:./libs/youme_im_3.0.11.har",
}2. ohpm导入
在⼯程中配置:
"dependencies": {
"@youme/im":"3.0.11",
}运⾏命令:
ohpm install @youme/im4.权限配置
在模块的 module.json5 中 requestPermissions添加网络和麦克风权限,配置如下:
"requestPermissions": [
{
"name": "ohos.permission.INTERNET",
},
{
"name": "ohos.permission.MICROPHONE",
"reason": "$string:mic_reason",
"usedScene": {
"abilities": [
"FormAbility"
],
"when": "inuse"
}
}5.使用Native C++接口
har包安装在该模块的oh_modules目录,目录下有提供 Native C++ 的 include头文件 和 so库文件。
若要使用Native C++接口,可以再CMake里配置使用。
C++接口API说明书请参考 IM SDK for C++使用指南
#CMakeLists.txt示例
#包含include目录
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules/@youme/im/include)
#包含so的目录
link_directories("../../../oh_modules/@youme/im/libs/${OHOS_ARCH}")
#把libyim.so添加到链接库里
target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so libyim.so)//papi_init.cpp 引用示例
#include "YIM.h"
#include "YIMPlatformDefine.h
//使用C++回调接口IYIMLoginCallback
class CNAPICallback: public IYIMLoginCallback
{
public:
/*
* 功能:登录回调
* @param errorcode:错误码
* @param userID:用户ID
*/
virtual void OnLogin(YIMErrorcode errorcode, const XCHAR * userID) {
OH_LOG_INFO(LOG_APP, "login with code %d", errorcode);
if(errorcode == YIMErrorcode_Success) {
YIMManager::CreateInstance()->GetChatRoomManager()->JoinChatRoom(ROOM_NAME);
}
}
};
...
//使用YIMManager主接口
XString ver = YIMManager::CreateInstance()->GetSDKVersion();
static auto cb = new CNAPICallback;
YIMManager::CreateInstance()->SetLoginCallback(cb);
YIMManager::CreateInstance()->SetServerZone(ServerZone_China);
auto code = YIMManager::CreateInstance()->Init(APP_KEY, APP_SECRET, "");import接口和定义
import { YIMClient, YIMObserver, YIMDefine, YIMMessage } from '@youme/im'
初始化SDK
-
功能: 初始化IM SDK。
-
原型:
/**
* 初始化IM引擎
* @param appKey 申请的appkey
* @param appSecret 申请得到的secretKey
* @param serverZone IM服务器区域
* @param packageName 所属包
* @param sdkValidDomain 指定sdk验证服务域名
* @param drDomain 指定dr上报服务域名
* @param sdkValidBackupip 指定sdk验证备用服务域名
* @param drBackupip 指定dr上报备用服务域名
*/
init(appKey:string, appSecret:string, serverZone: YIMDefine.YIMServerZone, packageName:string = "", sdkValidDomain:string = "", drDomain:string = "", sdkValidBackupip:string = "", drBackupip:string = ""): YIMDefine.YIMErrorcode-
返回:
错误码,详细描述见错误码定义。 -
备注: 该方法必须在调用其它SDK API之前调用。
监听事件
设置监听
IM引擎底层对于耗时操作都采用异步回调的方式,函数调用会立即返回。因此,用户须实现YIMObserver观察者接口中感兴趣的消息通知,并在初始化完成以后注册到YIMClient。
- 设置监听示例:添加一个观察者
observer: YIMObserver = new YIMObserver();
...
this.observer
.onReceiveMessage((msg: YIMMessage.Msg) => {
//接收文本语音消息
})
.onReceiveMessageNotify((chatType: YIMDefine.YIMChatType, targetID: string) => {
//新消息通知(默认自动接收消息,只有调用SetReceiveMessageSwitch设置为不自动接收消息,才会收到该回调)
})
.onOtherJoinRoom((room, user) => {
//他人进入房间
})
.onOtherLeaveRoom((room, user) => {
//他人离开房间
})
.onUpdateReadStatus((recvID: string, chatType: number, msgSerial: bigint) => {
//消息已读通知
})
.onKickOff(() => {
//被踢出房间
})
.onStartReconnect(() => {
//开始重连
})
.onRecvReconnectResult((result: number) => {
//重连结果
})
YIMClient.getInstance().addObserver(this.observer);- 添加移除观察者
/**
* 注册一个回调观察者
* @param observer YIMObserver类型的观察者对象
*/
addObserver(observer: YIMObserver)
/**
* 卸载一个回调观察者
* @param observer YIMObserver类型的观察者对象
*/
deleteObserver(observer: YIMObserver) 重连回调接口定义
/**
* 开始重连回调类型
* @return
*/
export type funcOnStartReconnect = () => void
/**
* 重连结果通知回调类型
* @param result 错误码
*/
export type funcOnRecvReconnectResult = (result: YIMDefine.YIMErrorcode) => void
/**
* 监听开始重连事件
* @param callback ()=>void
*/
onStartReconnect(callback: funcOnStartReconnect) : YIMObserver
/**
* 监听重连结果返回事件
* @param callback ()=>void
*/
onRecvReconnectResult(callback: funcOnRecvReconnectResult) : YIMObserver 用户进出频道通知接口定义
/**
* 他人加入聊天室回调类型
* @param room 频道/房间ID
* @param user 加入用户id
*/
export type funcOnOtherJoinRoom = (
room: string,
user: string) => void
/**
* 他人离开聊天室回调类型
* @param room 频道/房间ID
* @param user 离开用户id
*/
export type funcOnOtherLeaveRoom = (
room: string,
user: string) => void
/**
* 监听他人加入房间事件
* @param callback (room: string, user: string) => void
*/
onOtherJoinRoom(callback: funcOnOtherJoinRoom) : YIMObserver-
- /**
* 监听他人离开房间事件
* @param callback (room: string, user: string) => void
*/
onOtherLeaveRoom(callback: funcOnOtherLeaveRoom) : YIMObserver
用户被踢通知接口定义
/**
* 被踢出房间回调类型
* @return
*/
export type funcOnKickOff = ()=>void
/**
* 监听被踢出房间事件
* @param callback ()=>void
*/
onKickOff(callback: funcOnKickOff) : YIMObserver消息回调接口定义
/*
* 接收消息回调类型
* @param message 接收消息类YIMMessage.Msg
*/
/**
* Msg接收消息类
* @class Msg
* @property msgId 消息ID
* @property chatType 谈话类型: ChatType_PrivateChat = 1, //私聊 ChatType_RoomChat = 2, //聊天室
* @property msgType 消息类型: MessageBodyType_TXT = 1,//文本 MessageBodyType_Voice = 5, //语音
* @property sender 发送人
* @property receiver 接收者(聊天室:频道ID)
* @property createTime 发送时间
* @property isRead 消息是否已读
* @property distance 距离
* @property body 消息体,具体的消息内容
*/
export type funcOnReceiveMessage = (message: YIMMessage.Msg) => void
onReceiveMessage(callback: funcOnReceiveMessage) : YIMObserver新消息通知接口定义
/**
* 新消息通知(默认自动接收消息,只有调用SetReceiveMessageSwitch设置为不自动接收消息,才会收到该回调)
* @param chatType 聊天类型YIMDefine.YIMChatType
* @param targetID 房间或用户ID
*/
export type funcOnReceiveMessageNotify = (chatType: YIMDefine.YIMChatType, targetID: string) => void消息已读未读功能
- 设置消息已读回调方法:
/*
* 接收端消息已读回调类型,更新发送端消息显示状态
* @param recvId 接收端用户Id
* @param chatType 聊天类型
* @param msgSerial 最新一条已读消息的消息Id
*/
export type funcOnUpdateReadStatus = (
recvID: string,
chatType: YIMDefine.YIMChatType,
msgSerial: bigint) => void
/**
* 监听消息已读通知事件
* @param callback (recvID: string, chatType: YIMDefine.YIMChatType, msgSerial: bigint) => void
*/
onUpdateReadStatus(callback: funcOnUpdateReadStatus) : YIMObserver - 备注: 该回调接口不设置,则消息已读未读功能不生效。
获取 SDK 版本
- 语法:
getSDKVer(): string- 功能:
通过 YIMClient.getInstance().getSDKVer() 获取当前 SDK 的版本字符串。
- 参数说明:
无。
- 返回值:
string:SDK 版本字符串。
- 异步回调:
无。
用户管理
用户登录
-
功能: 指定用户ID登录IM系统,登录为异步过程,通过回调参数返回是否成功,成功后方能进行后续操作。
-
原型:
/**
* 登录IM
* @param user 用户ID,由调用者分配,不可为空字符串,只可由字母或数字或下划线组成,长度限制为255字节
* @param password 用户密码,不可为空字符串,如无特殊要求可以设置为固定字符串
* @param token 登录token,使用服务器token验证模式时使用,如不使用token验证传入:"",由restAPI获取token值
* @param callback 登录回调原型 (errCode: YIMDefine.YIMErrorcode, user: string) => void
* @param callback参数 errCode错误码
* @param callback参数 user 用户ID
*/
login(user: string, password:string, token: string, callback: (errCode: YIMDefine.YIMErrorcode, user: string) => void) : YIMDefine.YIMErrorcode 用户登出
- 功能: 登出游密IM云服务器,这是一个异步操作,操作结果会通过回调参数返回。
- 原型:
/**
* 登出IM
* @param callback 登出回调, 参数 errCode错误码
*/
logout(callback: (errCode: YIMDefine.YIMErrorcode) => void) : YIMDefine.YIMErrorcode被用户踢出通知
同一个用户ID在多台设备上登录时,后登录的会把先登录的踢下线,收到onKickOff()通知。
- 原型
/**
* 监听被踢出房间事件
* @param callback ()=>void
*/
onKickOff(callback: funcOnKickOff) : YIMObserver 频道管理
加入频道
- 功能: 加入聊天频道进行群组聊天,这是一个异步操作,操作结果会通过回调参数返回。
- 原型:
/**
* 加入聊天室
* @param room 频道ID,由调用者定义,如果频道不存在则后台自动创建,仅支持数字、字母、下划线组成的字符串,区分大小写,长度限制为255字节
* @param callback 加入频道回调
* @param callback参数 errCode错误码
* @param callback参数 room 频道ID
*/
joinChatRoom(room: string, callback: (errCode: YIMDefine.YIMErrorcode, room: string) => void) : YIMDefine.YIMErrorcode离开频道
- 功能: 退出聊天频道,这是一个异步操作,操作结果会通过回调参数返回。
- 原型:
/**
* 退出聊天室
* @param room 频道ID
* @param callback 退出频道回调
* @param callback参数 errCode错误码
* @param callback参数 room 频道ID
*/
leaveChatRoom(room: string, callback: (errCode: YIMDefine.YIMErrorcode, room: string) => void) : YIMDefine.YIMErrorcode离开所有频道
- 功能: 离开所有频道,这是一个异步操作,操作结果会通过回调参数返回。
- 原型:
/**
* 离开所有频道
* @param callback 离开所有频道回调
* @param callback参数 errCode错误码
*/
leaveAllChatRooms(callback: (errCode: YIMDefine.YIMErrorcode)=>void) : YIMDefine.YIMErrorcode 用户进出频道通知
接收其他用户加入或离开频道的通知。
此功能默认不开启,需要的请联系游密开启此服务。
/**
* 他人加入聊天室回调类型
* @param room 频道/房间ID
* @param user 加入用户id
*/
export type funcOnOtherJoinRoom = (
room: string,
user: string) => void
/**
* 他人离开聊天室回调类型
* @param room 频道/房间ID
* @param user 离开用户id
*/
export type funcOnOtherLeaveRoom = (
room: string,
user: string) => void
/**
* 监听他人加入房间事件
* @param callback (room: string, user: string) => void
*/
onOtherJoinRoom(callback: funcOnOtherJoinRoom) : YIMObserver
- /**
* 监听他人离开房间事件
* @param callback (room: string, user: string) => void
*/
onOtherLeaveRoom(callback: funcOnOtherLeaveRoom) : YIMObserver
获取房间成员数量
这是一个异步操作,操作结果会通过回调参数返回。
- 原型:
/**
* 功能:获取频道/房间成员数量
* @param room:频道/房间ID(已成功加入此频道才能获取该频道的人数)
* @param callback 获取频道/房间成员数量回调
* @param callback参数 errCode错误码
* @param callback参数 room 频道成/房间ID
* @param callback参数 count 频道/房间成员数量
*/
getRoomMemberCount(room: string, callback: (errCode: YIMDefine.YIMErrorcode, room: string, count: number) => void) : YIMDefine.YIMErrorcode- 备注:
room: 频道ID,string类型。
count: 频道内成员数量,number类型。
消息管理
游密IM可以进行多种消息类型的交互,比如文本,自定义,表情,图片,语音,文件,礼物等。
接收消息
- 功能: 消息接收采用异步回调的方式,在YIMObserver接口中的onReceiveMessage中处理。
/*
* 接收消息回调类型
* @param message 接收消息类YIMMessage.Msg
*/
/**
* Msg接收消息类
* @class Msg
* @property msgId 消息ID
* @property chatType 谈话类型: ChatType_PrivateChat = 1, //私聊 ChatType_RoomChat = 2, //聊天室
* @property msgType 消息类型: MessageBodyType_TXT = 1,//文本 MessageBodyType_Voice = 5, //语音
* @property sender 发送人
* @property receiver 接收者(聊天室:频道ID)
* @property createTime 发送时间
* @property isRead 消息是否已读
* @property distance 距离
* @property body 消息体,具体的消息内容
*/
/**
* 文本消息体
* @class BodyText
* @property content 消息内容
* @property attach 发送文本附加信息(SendTextMessage传入,格式及如何解析由调用方自定)
*/
/**
* 语音消息体
* @class BodyAudio
* @property audioTime 语音时长(单位:秒)
* @property text 语音翻译文字
* @property fileSize 语音大小(单位:字节)
* @property extra
* @property localPath
* @property isPlayed
*/
/**
* 自定义消息体
* @class BodyCustom
* @property custom 消息内容
*/
/**
* 文件消息体
* @class BodyFile
* @property fileName 原文件名
* @property fileExtension 文件扩展名
* @property fileSize 文件大小(单位:字节)
* @property extra 发送文件附加信息(SendFile传入,格式及如何解析由调用方自定)
* @property localPath 文件路径
* @property fileType 文件类型
*/
/**
* 礼物消息体
* @class BodyGift
* @property giftID 礼物ID
* @property giftCount 数量
* @property anchor 主播
* @property extra 附加信息
*/
/**
* 礼物附加信息
* @class YIMExtraGifParam
* @property nickname 昵称
* @property server_area 区服
* @property location 位置
* @property score 积分
* @property level 等级
* @property vip_level VIP等级
* @property extra 附加参数
*/
export type funcOnReceiveMessage = (message: YIMMessage.Msg) => void
onReceiveMessage(callback: funcOnReceiveMessage) : YIMObserver- 示例:
this.observer
.onReceiveMessage(msg: YIMMessage.Msg) => {
if (msg.msgType == YIMDefine.YIMMessageBodyType.MessageBodyType_TXT) {
//文本消息
let body = msg.body as YIMMessage.BodyText;
hilog.info(0x0000, 'YOUMEIM_DEMO_UI', `callback:text messege content:${body.content}`);
} else if (msg.msgType == YIMDefine.YIMMessageBodyType.MessageBodyType_Voice) {
//语音消息
YIMClient.getInstance().downloadFile(msg.msgId, "", (errCode: YIMDefine.YIMErrorcode, message: YIMMessage.Msg, path: string) => {
if (errCode == YIMDefine.YIMErrorcode.YIMErrorcode_Success) {
let body = msg.body as YIMMessage.BodyAudio;
...
}
});
} else {
...
}
})发送文本消息
-
功能: 发送文本消息到指定接收者,这是一个异步操作,操作结果会通过回调参数返回。
-
原型:
/**
* 发送文本消息
* @param receiver 消息接收者ID
* @param chatType 聊天类型: ChatType_PrivateChat = 1, //私聊 ChatType_RoomChat = 2, //聊天室
* @param msg 消息内容
* @param callback函数原型funcOnSendMessage (reqId: bigint, errCode: YIMDefine.YIMErrorcode, sendTime: number, isForbidRoom: boolean,
reasonType: number, forbidEndTime: number, msgId: bigint) => void
* @param callback参数reqId 请求ID(与SendXXMessage发送消息的输出参数requestID一致)
* @param callback参数errCode 错误码
* @param callback参数sendTime 发送时间戳,精确到毫秒
* @param callback参数isForbidRoom 是否被禁言
* @param callback参数reasonType 禁言原因, 0-未知,1-发广告,2-侮辱,3-政治敏感,4-恐怖主义,5-反动,6-色情,7-其它
* @param callback参数forbidEndTime 禁言结束时间
* @param callback参数msgId 消息ID
* @return [YIMDefine.YIMErrorcode 错误码, bigint 请求ID]
*/
sendTextMessage(receiver: string, chatType: number, msg: string, param: string,
callback: funcOnSendMessage) : [YIMDefine.YIMErrorcode, bigint]接收端查看消息后,给发送端发送已读状态信息
-
功能: 接收端用户查看聊天框信息后,给发送端确认消息已读,调用此接口。接收端给发送端发送已读状态信息后,发送端会收到onUpdateReadStatus回调。
-
原型:
/**
* 通知对端消息已读
* @param receiver 对端发送消息的userId
* @param chatType 聊天类型,详见ChatType
* @param messageID 最新消息的msgId
*/
sendMessageReadStatus(receiver: string, chatType: YIMDefine.YIMChatType, messageID: bigint) : YIMDefine.YIMErrorcode- 注意:receiver需要注意下,是发送被标记为已读消息的用户Id,而并非调用此接口的用户Id。messageID表示接收到最新一条消息的messageID,有可能发送端发过来的消息有多条。确认消息已读,接收端只给发送端发送最新一条消息的messageID为已读。
群发文本消息
- 功能: 用于群发文本消息的接口,每次不要超过200个用户。
- 原型:
/**
* 功能:群发文本消息
* @param receivers:接收方ID列表
* @param text:消息内容
* @return 错误码
*/
multiSendTextMessage(receivers: Array<string>, msg: string) : YIMDefine.YIMErrorcode- 返回:
错误码,详细描述见错误码定义。
发送礼物消息
- 功能: 给主播发送礼物消息的接口,支持在游密主播后台查看礼物消息信息和统计信息。客户端还是通过
onReceiveMessage接收消息。giftID为0可以表示普通的主播留言。 - 原型:
/**
* 发送礼物
* @param anchor:游密后台设置的对应的主播游戏id
* @param channel:主播频道ID,通过`JoinChatRoom`进入频道的用户可以接收到消息。
* @param giftID:礼物物品ID,特别的是`0`表示只是留言
* @param giftCount:礼物数量
* @param extraParam:附加参数(格式为json {"nickname":"昵称","server_area":"区服","location":"位置","score":"积分","level":"等级","vip_level":"VIP等级","extra":"附加参数"})
* @param callback函数原型funcOnSendMessage (reqId: bigint, errCode: YIMDefine.YIMErrorcode, sendTime: number, isForbidRoom: boolean,
reasonType: number, forbidEndTime: number, msgId: bigint) => void
* @param callback参数 reqId 请求ID(与SendXXMessage发送消息的输出参数requestID一致)
* @param callback参数 errCode 错误码
* @param callback参数 sendTime 发送时间戳,精确到毫秒
* @param callback参数 isForbidRoom 是否被禁言
* @param callback参数 reasonType 禁言原因, 0-未知,1-发广告,2-侮辱,3-政治敏感,4-恐怖主义,5-反动,6-色情,7-其它
* @param callback参数 forbidEndTime 禁言结束时间
* @param callback参数 msgId 消息ID
* @return [YIMDefine.YIMErrorcode 错误码, bigint 请求ID]
*/
sendGift(anchor: string, channel: string, giftID: number, giftCount: number, extra: YIMMessage.YIMExtraGifParam,
callback: funcOnSendMessage): [YIMDefine.YIMErrorcode, bigint]发送自定义消息
- 功能: 发送用户自定义消息,自定义数据是二进制数据。异步返回结果通过回调参数返回。
- 原型:
/**
* 发送自定义消息
* @param receiver:接收方ID
* @param chatType:聊天类型: ChatType_PrivateChat = 1, //私聊 ChatType_RoomChat = 2, //聊天室
* @param data:消息内容
* @param callback函数原型funcOnSendMessage (reqId: bigint, errCode: YIMDefine.YIMErrorcode, sendTime: number, isForbidRoom: boolean,
reasonType: number, forbidEndTime: number, msgId: bigint) => void
* @param callback参数 reqId 请求ID(与SendXXMessage发送消息的输出参数requestID一致)
* @param callback参数 errCode 错误码
* @param callback参数 sendTime 发送时间戳,精确到毫秒
* @param callback参数 isForbidRoom 是否被禁言
* @param callback参数 reasonType 禁言原因, 0-未知,1-发广告,2-侮辱,3-政治敏感,4-恐怖主义,5-反动,6-色情,7-其它
* @param callback参数 forbidEndTime 禁言结束时间
* @param callback参数 msgId 消息ID
* @return [YIMDefine.YIMErrorcode 错误码, bigint 请求ID]
*/
sendCustomMessage(recerver: string, chatType: YIMDefine.YIMChatType, data: ArrayBuffer,
callback: funcOnSendMessage) : [YIMDefine.YIMErrorcode, bigint]发送文件消息
发送文件
- 功能: 发送文件类型消息,支持上传进度(可选)
- 原型:
/**
* 发送文件
* @param receiver 消息接收者ID
* @param chatType 聊天类型: ChatType_PrivateChat = 1, //私聊 ChatType_RoomChat = 2, //聊天室
* @param fileUri 发送文件的uri地址(以file://开头),注意不是沙箱路径。例如uri = "file://com.example.demo/data/storage/el2/base/files/test.txt"
* @param extra 额外信息
* @param fileType 发送文件的类型:FileType_Other = 0, // 其他;FileType_Image = 2, // 图片
*
*
* @param callback 发送完成回调funcOnSendMessage=(reqId: bigint, errCode: YIMDefine.YIMErrorcode, sendTime: number, isForbidRoom: boolean,
reasonType: number, forbidEndTime: number, msgId: bigint) => void
* @param callback参数 reqId 请求ID(与SendXXMessage发送消息的输出参数requestID一致)
* @param callback参数 errCode 错误码
* @param callback参数 sendTime 发送时间戳,精确到毫秒
* @param callback参数 isForbidRoom 是否被禁言
* @param callback参数 reasonType 禁言原因, 0-未知,1-发广告,2-侮辱,3-政治敏感,4-恐怖主义,5-反动,6-色情,7-其它
* @param callback参数 forbidEndTime 禁言结束时间
* @param callback参数 msgId 消息ID
*
*
* @param progressCallback? (可选)上传进度回调funcOnUploadProgress=(reqId: bigint, percent: number) => void
* @param reqId 请求ID(与SendXXMessage发送消息的输出参数requestID一致)
* @param percent 上传进度 0-100
* @return [YIMDefine.YIMErrorcode 错误码, bigint 请求ID]
*/
sendFile(recerver: string, chatType: YIMDefine.YIMChatType, fileUri: string, extra: string, fileType: YIMDefine.YIMFileType,
callback: funcOnSendMessage, progressCallback?: funcOnUploadProgress) : [YIMDefine.YIMErrorcode, bigint]下载文件
- 功能: 下载文件消息的文件内容,这是一个异步操作,操作结果会通过回调接口返回。
- 原型:
/**
* 下载消息文件
* @param messageID 语音消息ID
* @param path 本地缓存路径,必须保证该路径有可写权限
* @param callback原型 (errCode: YIMDefine.YIMErrorcode, message: YIMMessage.Msg, path: string) => void
* @param callback参数 errCode 错误码
* @param callback参数 message 所属消息类
* @param callback参数 path 下载文件的存储路径
*/
downloadFile(messageID: bigint, path: string, callback: (errCode: YIMDefine.YIMErrorcode, message: YIMMessage.Msg, path: string) => void) : YIMDefine.YIMErrorcode通过url下载文件
- 功能: 通过url下载文件,这是一个异步操作,操作结果会通过回调接口返回。(通过onStopAudioSpeechStatus收到url地址后,通过这个接口下载。)
- 原型:
/**
* 根据Url下载文件
* @param fromUrl 下载地址
* @param savePath 本地缓存路径,必须保证该路径有可写权限
* @param fileType 文件类型
* @param callback 下载文件回调
*/
downloadFileByUrl(fromUrl: string, savePath: string, fileType: YIMDefine.YIMFileType,
callback: (errCode: YIMDefine.YIMErrorcode, fromUrl: string, path: string, audioTime: number) => void) : YIMDefine.YIMErrorcode消息功能设置
设置消息已读
-
功能: 收到消息后,设置消息为已读。
-
原型:
/**
* 设置本地消息已读
* @param messageID 消息ID
* @param readed 是否已读,true-已读,false-未读
* @return
*/
setMessageRead(messageID: bigint, readed: boolean) : YIMDefine.YIMErrorcode- 返回:
错误码,详细描述见错误码定义。
批量设置消息已读
-
功能: 收到消息后,设置消息为已读。
-
原型:
/**
* 设置所有消息为已读
* @param user 发消息的用户ID;用户ID为空字符串时,将登录用户的所有消息设置为已读/未读;用户ID不为空字符串时,将接收的由该用户ID发送的消息设置为已读/未读
* @param readed 是否已读,true-已读,false-未读
* @return
*/
setAllMessageRead(user: string, readed: boolean) : YIMDefine.YIMErrorcode- 返回:
错误码,详细描述见错误码定义。
切换获取消息模式
- 功能: 在自动接收消息和手动接收消息间切换,默认是自动接收消息。不自动接收消息,有新消息达到时,SDK会发出onReceiveMessageNotify回调,调用方需要调用GetMessage获取新消息
- 原型:
/**
* 设置是否自动接收消息(房间消息 )
* @param targets 频道/房间ID列表
* @param autoReceive true:自动接收(默认) false:不自动接收消息,有新消息达到时,SDK会发出onReceiveMessageNotify回调,调用方需要调用GetMessage获取新消息
* @return
*/
SetReceiveMessageSwitch(targets: Array<string>, autoReceive: boolean) : YIMDefine.YIMErrorcode- 返回:
错误码,详细描述见错误码定义。
手动获取消息
- 功能: 在手动接收消息模式,需要调用该接口后才能收到
onReceiveMessage通知。 - 原型:
/**
* 获取新消息(只有setReceiveMessageSwitch设置为不自动接收消息,才需要在收到OnReceiveMessageNotify回调时调用该函数)
* @param targets 房间ID列表
* @return
*/
GetNewMessage(targets: Array<string>) : YIMDefine.YIMErrorcode- 返回:
错误码,详细描述见错误码定义。 - 备注: 这是一个异步操作,操作结果会通过回调接口返回。
新消息通知
-
功能: setReceiveMessageSwitch(false)后,进入手动接收消息模式,有新消息的时候会通知该回调,频道消息会通知消息来自哪个频道ID。
-
原型:
/**
* 新消息通知(默认自动接收消息,只有调用SetReceiveMessageSwitch设置为不自动接收消息,才会收到该回调)
* @param chatType 聊天类型YIMDefine.YIMChatType
* @param targetID 房间或用户ID
*/
onReceiveMessageNotify(callback: funcOnReceiveMessageNotify)
type funcOnReceiveMessageNotify = (chatType: YIMDefine.YIMChatType, targetID: string) => void消息记录管理
设置是否保存频道聊天记录
- 功能: 设置是否在本地保存频道聊天记录,默认不保存。私聊历史记录默认保存。
- 原型:
/**
* 功能:是否保存频道/房间消息到本地历史记录
* @param rooms:频道/房间ID列表
* @param isSave:是否保存(默认不保存)
* @return 错误码
*/
setRoomHistoryMessageSwitch(rooms: Array<string>, isSave: boolean) : YIMDefine.YIMErrorcode - 返回:
错误码,详细描述见错误码定义。
拉取频道最近聊天记录
- 功能: 从服务器拉取频道最近的聊天历史记录。这是一个异步操作,操作结果会通过回调接口返回。
此功能默认不开启,需要的请联系游密开启此服务。
- 原型:
/**
* 从服务器查询房间最近历史消息
* @param roomID 频道/房间id
* @param count 消息数量(最大30条)
* @param direction 历史消息排序方向 0:按时间戳升序 1:按时间戳逆序
* @param callback 查询历史记录回调
*/
queryRoomHistoryMessageFromServer(roomID: string, count: number, direction: number,
callback: (code: YIMDefine.YIMErrorcode, target: string, remain: number, messages: YIMMessage.Msg[]) => void) : YIMDefine.YIMErrorcode- 回调参数:
code:错误码target: 获取频道ID,string类型。
remain: 获取剩余消息记录数量,number类型。messages: 获取消息记录列表。
YIMMessage.Msg类详细定义查看接收消息备注。
按页拉取频道最近聊天记录
- 功能: 从服务器按页拉取频道最近的聊天历史记录。这是一个异步操作,操作结果会通过回调接口返回。
此功能默认不开启,需要的请联系游密开启此服务。
- 原型:
/**
* 从服务器查询房间最近历史消息(按页查询)
* @param roomID 频道/房间id
* @param count 消息数量
* @param direction 历史消息排序方向 0:按时间戳升序 1:按时间戳逆序
* @param lastMessageID 上一分页最后消息ID,第一页可传空
* @param callback 查询历史记录回调
*/
queryRoomHistoryMessageFromServerByPage(roomID: string, count: number, direction: number, lastMessageID: bigint,
callback: (code: YIMDefine.YIMErrorcode, target: string, remain: number, messages: YIMMessage.Msg[]) => void) : YIMDefine.YIMErrorcode- 回调参数:
code:错误码target: 获取频道ID,string类型。
remain: 获取剩余消息记录数量,number类型。messages: 获取消息记录列表。
YIMMessage.Msg类详细定义查看接收消息备注。
本地历史记录管理
查询本地聊天历史记录
- 功能: 获取本地消息历史记录,这是一个异步操作,操作结果会通过回调接口返回。
- 原型:
/**
* 功能:查询本地历史消息记录
* @param target:目标(用户或频道)ID
* @param chatType:表示查询私聊或者频道聊天的历史记录,1是私聊,2是频道聊天
* @param startMessageID:起始消息ID(与requestid不同,默认为0,从最新一条消息ID开始查询)
* @param count:消息数量(一次最大100条)
* @param direction:查询方向 0:向前查找(比startMessageID时间更早) 1:向后查找(比startMessageID时间更晚);`startMessageID=0`时,direction使用默认值0
* @param callback: 查询本地历史记录回调
* @return 错误码
*/
queryHistoryMessage(target: string, chatType: YIMDefine.YIMChatType, startMsgID: bigint, count: number, direction: number,
callback: (code: YIMDefine.YIMErrorcode, target: string, remain: number, messages: YIMMessage.Msg[]) => void) : YIMDefine.YIMErrorcode-
相关函数: 对于房间本地记录,需要先设置自动保存房间消息。
setRoomHistoryMessageSwitch。 -
回调参数:
code:错误码target: 获取频道ID,string类型。
remain: 获取剩余消息记录数量,number类型。messages: 获取消息记录列表。
YIMMessage.Msg类详细定义查看接收消息备注。
根据时间清理本地聊天历史记录
- 功能: 清理本地历史记录
- 原型:
/**
* 功能:删除指定时间之前的历史消息
* @param chatType:聊天类型
* @param time:时间戳(毫秒级,删除指定时间之前的消息),当传入的时间戳为小于等于0时,会删除该聊天类型的所有消息
* @return 错误码
*/
deleteHistoryMessageBeforeTime(chatType: YIMDefine.YIMChatType, time: number) : YIMDefine.YIMErrorcode- 返回:
错误码,详细描述见错误码定义。 - 备注: 建议定期清理本地历史记录。
根据消息ID清理本地聊天历史记录
- 功能: 清理本地历史记录。
- 原型:
/**
* 功能:删除指定messageID对应消息
* @param id:消息ID
* @return 错误码
*/
deleteHistoryMessageByID(id: bigint) : YIMDefine.YIMErrorcode- 返回:
错误码,详细描述见错误码定义。 - 备注: 建议定期清理本地历史记录。
根据用户ID或者频道ID清理指定的本地聊天历史记录
- 功能: 根据用户ID或者频道ID删除对应的本地聊天历史记录,保留消息ID白名单中的消息记录,白名单列表为空时删除与该用户ID或频道ID有关的所有本地聊天历史记录。
- 原型:
/**
* 删除指定用户或频道的本地聊天历史记录,保留指定的消息ID列表记录
*@param targetID: 用户ID或者频道ID
*@param chatType:聊天类型,私聊/频道聊天,1是私聊,2是频道聊天
*@param excludeMesList:保留的消息ID列表
*@return 错误码
*/
deleteSpecifiedHistoryMessage(target: string, chatType: YIMDefine.YIMChatType, excludeMesList: Array<bigint>) : YIMDefine.YIMErrorcode- 返回:
错误码,详细描述见错误码定义。 - 备注: 建议定期清理本地历史记录。
根据用户ID或者频道ID清理本地聊天历史记录
- 功能: 根据用户ID或者频道ID删除以指定的起始消息ID开始的n条本地聊天历史记录,起始消息ID和消息数量使用默认值时则删除所有消息。
- 原型:
/**
* 功能:删除历史消息(删除startMessageID时间之前count条消息)
* @param target:userID或roomID
* @param chatType:聊天类型
* @param startMessageID:起始消息ID(默认0 最近一条消息)
* @param count:消息数量(默认0 删除所有消息)
* @return 错误码
*/
deleteHistoryMessageByTarget(target: string, chatType: YIMDefine.YIMChatType, startMessageID: bigint, count: number) : YIMDefine.YIMErrorcode- 返回:
错误码,详细描述见错误码定义。 - 备注: 建议定期清理本地历史记录。
获取最近私聊联系人列表
- 功能: 该接口是根据本地历史消息记录生成的最近联系人列表,按最后聊天时间倒序排列。该列表会受清理历史记录消息的接口影响。这是一个异步操作,操作结果会通过回调接口返回。
- 原型:
/**
* 获取最近联系人
* @param callback 获取最近联系人回调
* @param callback参数errCode 错误码
* @param callback参数contacts 联系人列表
*/
getHistoryContact(callback: (errCode: YIMDefine.YIMErrorcode, contacts: Array<YIMDefine.ContactMessageInfo>) => void)- 回调参数:
/**
* 最近联系人消息
* @class ContactMessageInfo
* @property id 联系人ID
* @property ctime 消息创建时间
* @property content 消息内容
* @property type 消息类型,0-未知类型,1-文本消息,2-自定义消息,3-表情,4-图片,5-语音,6-视频,7-文件,8-礼物
* @property path 如果是语音或者文件消息,文件存放路径
* @property notreaded 接收端消息未读数量
*/敏感词过滤
考虑到客户端可能需要传递一些自定义消息,关键字过滤方法就直接提供出来,客户端可以选择是否过滤关键字,可以在发送时选择不发送或发送替换后的方字。接收方在收到文本消息时,也可以调用该接口进行过滤,自定义是否显示过滤后的文本。
- 功能: 过滤敏感词。
- 原型:
/**
* 功能:消息关键词过滤
* @param message:消息内容
* @param level:过滤等级,匹配到的敏感词等级会返回,具体数值意义暂未启用,保留字段
* @return [过滤后的字符串(敏感词替换为"***"),过滤等级]
*/
getFilterText (message: string, level: number) : [string, number]- 返回:
返回[string, number]元组:ret[0]是过滤后的字符串(敏感词替换为 "***"),ret[1]是匹配到的敏感词等级。等级数值的业务含义为保留定义。
例:
filerText(message: string) : string {
if(this.FilterEnabled) {
let ret: [string, number] = YIMClient.getInstance().getFilterText(message, 1);
return ret[0];
} else {
return message;
}
}游密支持将消息及用户登录、登出事件抄送至业务服务端。业务侧需提供 HTTP/HTTPS 接收地址,并联系游密配置所属应用及需要接收的事件类型。具体接入方式参见IM 服务端消息抄送接入指南。
语音消息
语音相关接口支持两种使用流程:通过 IM 将语音消息发送给指定用户或频道;录音并上传后获取文件下载链接,由业务侧自行使用。
语音消息收发
调用 StartRecordAudioMessage 开始录音,调用 StopAndSendAudioMessage 结束录音并发送,或调用 cancelAudioMessage 取消本次录音。接收方收到语音消息通知后下载音频,再通过语音播放中的接口播放。
开始录制语音消息
- 功能: 开始录音。
- 原型:
/**
* 开始发送语音消息
* @param receiver 消息接收者ID
* @param chatType 聊天类型: ChatType_PrivateChat = 1, //私聊 ChatType_RoomChat = 2, //聊天室
* @param msg 消息内容
* @param complete 发送语音完成的消息回调
* @param before_send? 可选,录音完成之后开始发送语音之前的通知回调
* @param callback参数 reqId 请求ID(与SendXXMessage发送消息的输出参数requestID一致)
* @param callback参数 errCode 错误码
* @param callback参数 text 语音识别结果
* @param callback参数 audioPath 语音文件路径
* @param callback参数 audioTime 语音时长(单位:秒)
* @param callback参数 sendTime 发送时间戳,精确到毫秒
* @param callback参数 isForbidRoom 是否被禁言
* @param callback参数 reasonType 禁言原因
* @param callback参数 forbidEndTime 禁言结束时间
* @param callback参数 msgId 消息ID
* @return [YIMDefine.YIMErrorcode 错误码, bigint 请求ID]
*/
StartRecordAudioMessage(receiver: string, chatType: number,
complete: (reqId: bigint, errCode: YIMDefine.YIMErrorcode, text: string, audioPath: string, audioTime: number,
sendTime: number, isForbidRoom: boolean, reasonType: number, forbidEndTime: number, msgId: bigint) => void,
before_send?: (reqId: bigint, errCode: YIMDefine.YIMErrorcode, text: string, audioPath: string, audioTime: number) => void)
: [YIMDefine.YIMErrorcode, bigint]- 返回:
启动录音是否成功,请求ID。
结束录音并发送
- 功能: 停止录音并发送出去,这是一个异步操作,操作结果会通过回调参数返回。
- 原型:
/**
* 停止录音并发送
* @param extra 语音消息附带信息
*/
StopAndSendAudioMessage(extra: string) : YIMDefine.YIMErrorcode取消录音
- 功能: 取消录音
- 原型:
/**
* 取消录音
* @return
*/
cancelAudioMessage() : YIMDefine.YIMErrorcode- 返回:
错误码,详细描述见错误码定义。
该接口也适用于录音与上传流程;取消后此次录音不会上传。
设置是否自动下载语音消息
-
功能: 设置是否自动下载语音消息。 setDownloadAudioMessageSwitch()在初始化之后,启动语音之前调用;若设置了自动下载语音消息,不需再调用downloadAudioMessage()接口,收到语音消息时会自动下载,自动下载完成会收到YIMObserver的onDownload()回调。
-
原型:
/**
* 是否自动下载语音消息。当设置为true,语音文件自动下载成功后在OnDownload中通知
* @param download:自动下载语音消息 false:不自动下载语音消息(默认)
* @return
*/
setDownloadAudioMessageSwitch(download: boolean) : YIMDefine.YIMErrorcode- 返回:
错误码,详细描述见错误码定义。
按消息 ID 下载语音
接收消息接口参考收消息通过msgType分拣出语音消息类型:MessageBodyType_Voice。然后调用函数downloadFile下载语音消息,下载完成后调用方播放。
- 备注:
详细定义查看接收消息备注。
录音与上传
调用 startAudioSpeech 开始录音,调用 stopAudioSpeech 停止录音并上传。上传结果通过对应回调返回,包含音频文件的下载链接,业务侧可自行处理该链接。此流程不会自动发送 IM 消息。
开始录音
- 原型:
/**
* 开始语音(不通过游密发送该语音消息,由调用方发送,调用StopAudioSpeech完成上传后会回调结果)
* 暂不支持语音识别
* @param callback 录音结果回调
* @param callback参数errCode 错误码
* @param callback参数audio 录音信息
* @return 错误码
*/
/**
* 录音信息
* @class AudioSpeechInfo
* @property reqID requestID(StartAudioSpeech返回)
* @property text 语音翻译文字,不支持翻译的返回空串
* @property fileSize 语音文件大小(单位:字节)
* @property audioTime 语音时长(单位:秒)
* @property localPath 语音文件本地路径
* @property url 语音文件下载路径
*/
startAudioSpeech(callback: (errCode: YIMDefine.YIMErrorcode, audio: YIMDefine.AudioSpeechInfo) => void) : YIMDefine.YIMErrorcode- 返回:
YIMDefine.YIMErrorcode:错误码,详细描述见错误码定义。
停止录音并上传
- 功能: 该接口停止录音并上传,上传结果返回音频文件的下载链接,不会自动发送 IM 消息,这是一个异步操作,操作结果会通过回调参数返回。
- 原型:
/**
* 停止语音
*/
stopAudioSpeech() : YIMDefine.YIMErrorcode如需取消本次录音,调用取消录音中的 cancelAudioMessage。
根据 URL 下载录音文件
- 功能: 通过startAudioSpeech收到AudioSpeechInfo的url地址后,可以通过url下载文件进行下载。
语音播放
播放语音文件,控制播放音量和状态。
播放语音
- 功能: 可以使用SDK内置的播放接口进行播放。
- 原型:
/**
* 播放语音
* @param path 语音文件路径
*/
startPlayAudio(path: string, callback?: (errCode: YIMDefine.YIMErrorcode, path: string) => void) : YIMDefine.YIMErrorcode - 回调参数:
errCode: YIMDefine.YIMErrorcode //播放语音的错误码
path: string //语音文件路径停止语音播放
- 功能: 停止播放当前语音。
- 原型:
/**
* 停止语音播放
* @return
*/
stopPlayAudio() : YIMDefine.YIMErrorcode- 返回:
错误码,详细描述见错误码定义。
设置语音播放音量
- 功能: 设置语音音量。
- 原型:
/**
* 设置语音播放音量
* @param volume 音量值,取值范围0.0到1.0
*/
setVolume(volume: number)查询播放状态
- 语法:
isPlaying(): boolean- 功能:
查询当前是否正在播放语音。
- 参数说明:
无。
- 返回值:
boolean:true 正在播放,false 未播放。
- 异步回调:
无。
文件与缓存管理
管理录音缓存目录和下载文件的保存目录。下载保存目录也适用于普通文件。
设置录音缓存目录
- 功能: 设置录音时用于保存录音文件的缓存目录,如果没有设置,SDK会在APP默认缓存路径下创建一个文件夹用于保存音频文件。
- 原型:
/**
* 设置语音消息录制的缓存目录
* @param dir 缓存目录
*/
setAudioCacheDir(dir: string)清理录音缓存目录
- 功能: 清空当前设置的录音缓存目录。
- 原型:
/**
* 清理语音缓存目录(注意清空语音缓存目录后历史记录中会无法读取到音频文件,调用清理历史记录接口也会自动删除对应的音频缓存文件)
* @return
*/
clearAudioCachePath()设置下载保存目录
- 功能: 设置语音消息或者文件的保存目录 下载保存目录是cache/downloads的默认下载目录,对下载语音消息和文件均适用;设置下载保存目录在初始化之后,启动语音之前调用,若设置了下载保存目录,调用ddownloadFile()时其中的savePath参数可以为空字符串(若savePath参数为空字符串时,下载语音消息和文件会生成以时间戳为前缀的文件)。
- 原型:
/**
* 设置下载语音消息的缓存目录
* @param dir 缓存目录
*/
setDownloadDir(dir: string)- 返回:
错误码,详细描述见错误码定义。
游戏切入后台与恢复
游戏切入后台通知
- 功能: 建议游戏切入后台时通知该接口,以便于得到更好重连效果。 调用onPause(false),在游戏切入后台后,若IM是登录状态,依旧接收IM消息。 调用onPause(true),游戏切入后台,即使IM是登录状态也不会接收IM消息;在游戏恢复运行时会主动拉取暂停期间未接收的消息,收到onRecvMessage()回调。
- 原型:
/**
* 功能:程序切到后台运行
* @param pauseReceiveMessage:是否暂停接收消息 true-暂停接收 false-不暂停接收
*/
onPause(pauseReceiveMessage: boolean)游戏恢复运行通知
- 功能: 建议游戏恢复运行时通知该接口,以便于得到更好重连效果。
- 原型:
/**
* 功能:程序切恢复前台运行
*/
onResume()反初始化 SDK
- 语法:
unInit(): void- 功能:
不再使用 IM SDK 时释放 SDK 资源。退出账号使用 logout;反初始化后再次使用需重新初始化。
- 参数说明:
无。
- 返回值:
无(void)。
- 异步回调:
无。
服务器部署地区定义
enum YIMServerZone
{
YIMServerZone_China = 0, // 中国
YIMServerZone_Singapore = 1, // 新加坡
YIMServerZone_America = 2, // 美国
YIMServerZone_HongKong = 3, // 香港
YIMServerZone_Korea = 4, // 韩国
YIMServerZone_Australia = 5, // 澳洲
YIMServerZone_Deutschland = 6, // 德国
YIMServerZone_Brazil = 7, // 巴西
YIMServerZone_India = 8, // 印度
YIMServerZone_Japan = 9, // 日本
YIMServerZone_Ireland = 10, // 爱尔兰
YIMServerZone_Thailand = 11, // 泰国
YIMServerZone = 12, // 台湾
YIMServerZone_Unknow = 9999
}错误码定义
enum YIMErrorcode {
YIMErrorcode_Success = 0, //成功
YIMErrorcode_EngineNotInit = 1, //未初始化
YIMErrorcode_NotLogin = 2, //未登录
YIMErrorcode_ParamInvalid = 3, //参数错误
YIMErrorcode_TimeOut = 4, //超时
YIMErrorcode_StatusError = 5, //状态错误
YIMErrorcode_SDKInvalid = 6, //SDK验证识别
YIMErrorcode_AlreadyLogin = 7, //已经登录
YIMErrorcode_ServerError = 8, //服务器错误
YIMErrorcode_NetError = 9, //网络错误
YIMErrorcode_LoginSessionError = 10, //session错误
YIMErrorcode_NotStartUp = 11, //未启动
YIMErrorcode_FileNotExist = 12, //文件不存在
YIMErrorcode_SendFileError = 13, //发送文件失败
YIMErrorcode_UploadFailed = 14, //上传失败
YIMErrorcode_UsernamePasswordError = 15, //用户名密码错误
YIMErrorcode_UserStatusError = 16, //用户状态错误(无效用户)
YIMErrorcode_MessageTooLong = 17, //消息太长
YIMErrorcode_ReceiverTooLong = 18, //接收方ID过长(检查房间名)
YIMErrorcode_InvalidChatType = 19, //无效聊天类型(私聊、聊天室)
YIMErrorcode_InvalidReceiver = 20, //无效用户ID
YIMErrorcode_UnknowError = 21,
YIMErrorcode_InvalidAppkey = 22, //无效APPKEY
YIMErrorcode_ForbiddenSpeak = 23, //被禁言
YIMErrorcode_CreateFileFailed = 24, //创建文件失败
YIMErrorcode_UnsupportFormat = 25, //不支持的文件格式
YIMErrorcode_ReceiverEmpty = 26, //接收方为空
YIMErrorcode_RoomIDTooLong = 27, //房间名太长
YIMErrorcode_ContentInvalid = 28, //聊天内容严重非法
YIMErrorcode_NoLocationAuthrize = 29, //未打开定位权限
YIMErrorcode_UnknowLocation = 30, //未知位置
YIMErrorcode_Unsupport = 31, //不支持该接口
YIMErrorcode_NoAudioDevice = 32, //无音频设备
YIMErrorcode_AudioDriver = 33, //音频驱动问题
YIMErrorcode_DeviceStatusInvalid = 34, //设备状态错误
YIMErrorcode_ResolveFileError = 35, //文件解析错误
YIMErrorcode_ReadWriteFileError = 36, //文件读写错误
YIMErrorcode_NoLangCode = 37, //语言编码错误
YIMErrorcode_TranslateUnable = 38, //翻译接口不可用
YIMErrorcode_SpeechAccentInvalid = 39, //语音识别方言无效
YIMErrorcode_SpeechLanguageInvalid = 40, //语音识别语言无效
YIMErrorcode_HasIllegalText = 41, //消息含非法字符
YIMErrorcode_AdvertisementMessage = 42, //消息涉嫌广告
YIMErrorcode_AlreadyBlock = 43, //用户已经被屏蔽
YIMErrorcode_NotBlock = 44, //用户未被屏蔽
YIMErrorcode_MessageBlocked = 45, //消息被屏蔽
YIMErrorcode_LocationTimeout = 46, //定位超时
YIMErrorcode_NotJoinRoom = 47, //未加入该房间
YIMErrorcode_LoginTokenInvalid = 48, //登录token错误
YIMErrorcode_CreateDirectoryFailed = 49, //创建目录失败
YIMErrorcode_InitFailed = 50, //初始化失败
YIMErrorcode_Disconnect = 51, //与服务器断开
YIMErrorcode_TheSameParam = 52, //设置参数相同
YIMErrorcode_QueryUserInfoFail = 53, //查询用户信息失败
YIMErrorcode_SetUserInfoFail = 54, //设置用户信息失败
YIMErrorcode_UpdateUserOnlineStateFail = 55, //更新用户在线状态失败
YIMErrorcode_NickNameTooLong = 56, //昵称太长(> 64 bytes)
YIMErrorcode_SignatureTooLong = 57, //个性签名太长(> 120 bytes)
YIMErrorcode_NeedFriendVerify = 58, //需要好友验证信息
YIMErrorcode_BeRefuse = 59, //添加好友被拒绝
YIMErrorcode_HasNotRegisterUserInfo = 60, //未注册用户信息
YIMErrorcode_AlreadyFriend = 61, //已经是好友
YIMErrorcode_NotFriend = 62, //非好友
YIMErrorcode_NotBlack = 63, //不在黑名单中
YIMErrorcode_PhotoUrlTooLong = 64, //头像url过长(>500 bytes)
YIMErrorcode_PhotoSizeTooLarge = 65, //头像太大(>100 kb)
YIMErrorcode_ChannelMemberOverflow = 66, // 达到频道人数上限
//服务器的错误码
YIMErrorcode_ALREADYFRIENDS = 1000,
YIMErrorcode_LoginInvalid = 1001,
//语音部分错误码
YIMErrorcode_PTT_Start = 2000,
YIMErrorcode_PTT_Fail = 2001,
YIMErrorcode_PTT_DownloadFail = 2002, //下载语音失败
YIMErrorcode_PTT_GetUploadTokenFail = 2003, //获取token失败
YIMErrorcode_PTT_UploadFail = 2004, //上传失败
YIMErrorcode_PTT_NotSpeech = 2005, //未检测到语音或未开始语音
YIMErrorcode_PTT_DeviceStatusError = 2006, //音频设备状态错误
YIMErrorcode_PTT_IsSpeeching = 2007, //正在录音
YIMErrorcode_PTT_FileNotExist = 2008, //文件不存在
YIMErrorcode_PTT_ReachMaxDuration = 2009, //达到语音最大时长限制
YIMErrorcode_PTT_SpeechTooShort = 2010, //语音时长太短
YIMErrorcode_PTT_StartAudioRecordFailed = 2011, //启动录音失败
YIMErrorcode_PTT_SpeechTimeout = 2012, //音频输入超时
YIMErrorcode_PTT_IsPlaying = 2013, //正在播放
YIMErrorcode_PTT_NotStartPlay = 2014, //未开始播放
YIMErrorcode_PTT_CancelPlay = 2015, //主动取消播放
YIMErrorcode_PTT_NotStartRecord = 2016, //未开始语音
YIMErrorcode_PTT_NotInit = 2017, // 未初始化
YIMErrorcode_PTT_InitFailed = 2018, // 初始化失败
YIMErrorcode_PTT_Authorize = 2019, // 录音权限
YIMErrorcode_PTT_StartRecordFailed = 2020, // 启动录音失败
YIMErrorcode_PTT_StopRecordFailed = 2021, // 停止录音失败
YIMErrorcode_PTT_UnsupprtFormat = 2022, // 不支持的格式
YIMErrorcode_PTT_ResolveFileError = 2023, // 解析文件错误
YIMErrorcode_PTT_ReadWriteFileError = 2024, // 读写文件错误
YIMErrorcode_PTT_ConvertFileFailed = 2025, // 文件转换失败
YIMErrorcode_PTT_NoAudioDevice = 2026, // 无音频设备
YIMErrorcode_PTT_NoDriver = 2027, // 驱动问题
YIMErrorcode_PTT_StartPlayFailed = 2028, // 启动播放失败
YIMErrorcode_PTT_StopPlayFailed = 2029, // 停止播放失败
YIMErrorcode_PTT_RecognizeFailed = 2030, // 识别失败
YIMErrorcode_PTT_ShortConnectionMode = 2031, // 短连接模式不支持发送
YIMErrorcode_Fail = 10000
}