NIM Cocos2d-x SDK  2.2.0
Public Types | Static Public Member Functions | List of all members
nim::Talk Class Reference

聊天功能;主要包括发送消息、接收消息等功能 More...

#include <nim_cpp_talk.h>

Public Types

typedef std::function< void(const SendMessageArc &)> SendMsgAckCallback
 
typedef std::function< void(const IMMessage &)> ReceiveMsgCallback
 
typedef std::function< void(const std::list< IMMessage > &)> ReceiveMsgsCallback
 
typedef std::function< void(int64_t, int64_t)> FileUpPrgCallback
 
typedef std::function< bool(const IMMessage &)> TeamNotificationFilter
 
typedef std::function< void(const NIMResCode, const std::list< RecallMsgNotify > &)> RecallMsgsCallback
 
typedef std::function< void(const BroadcastMessage &)> ReceiveBroadcastMsgCallback
 
typedef std::function< void(const std::list< BroadcastMessage > &)> ReceiveBroadcastMsgsCallback
 

Static Public Member Functions

static void RegSendMsgCb (const SendMsgAckCallback &cb, const std::string &json_extension="")
 
static void SendMsg (const std::string &json_msg, const std::string &json_extension="", FileUpPrgCallback *pcb=nullptr)
 
static bool StopSendMsg (const std::string &client_msg_id, const NIMMessageType &type, const std::string &json_extension="")
 
static void RegReceiveCb (const ReceiveMsgCallback &cb, const std::string &json_extension="")
 
static void RegReceiveMessagesCb (const ReceiveMsgsCallback &cb, const std::string &json_extension="")
 
static std::string CreateTextMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const std::string &content, const MessageSetting &msg_setting, int64_t timetag=0)
 
static std::string CreateImageMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const IMImage &image, const std::string &file_path, const MessageSetting &msg_setting, int64_t timetag=0)
 
static std::string CreateFileMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const IMFile &file, const std::string &file_path, const MessageSetting &msg_setting, int64_t timetag=0)
 
static std::string CreateAudioMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const IMAudio &audio, const std::string &file_path, const MessageSetting &msg_setting, int64_t timetag=0)
 
static std::string CreateVideoMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const IMVideo &video, const std::string &file_path, const MessageSetting &msg_setting, int64_t timetag=0)
 
static std::string CreateLocationMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const IMLocation &location, const MessageSetting &msg_setting, int64_t timetag=0)
 
static std::string CreateTipMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const std::string &tip_content, const MessageSetting &msg_setting, int64_t timetag=0)
 
static std::string CreateBotRobotMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const std::string &content, const IMBotRobot &bot_msg, const MessageSetting &msg_setting, int64_t timetag=0)
 
static std::string CreateRetweetMessage (const std::string &src_msg_json, const std::string &client_msg_id, const NIMSessionType retweet_to_session_type, const std::string &retweet_to_session_id, const MessageSetting &msg_setting, int64_t timetag=0)
 
static bool ParseIMMessage (const std::string &json_msg, IMMessage &msg)
 
static bool ParseImageMessageAttach (const IMMessage &msg, IMImage &image)
 
static bool ParseFileMessageAttach (const IMMessage &msg, IMFile &file)
 
static bool ParseAudioMessageAttach (const IMMessage &msg, IMAudio &audio)
 
static bool ParseVideoMessageAttach (const IMMessage &msg, IMVideo &video)
 
static bool ParseLocationMessageAttach (const IMMessage &msg, IMLocation &location)
 
static bool ParseBotRobotMessageAttach (const IMMessage &msg, IMBotRobot &robot_msg)
 
static void UnregTalkCb ()
 
static void RegTeamNotificationFilter (const TeamNotificationFilter &filter, const std::string &json_extension="")
 
static void RegRecallMsgsCallback (const RecallMsgsCallback &cb, const std::string &json_extension="")
 
static void RecallMsg (const IMMessage &msg, const std::string &notify, const RecallMsgsCallback &cb, const std::string &json_extension="")
 
static std::string GetAttachmentPathFromMsg (const IMMessage &msg)
 
static void RegReceiveBroadcastMsgCb (const ReceiveBroadcastMsgCallback &cb, const std::string &json_extension="")
 
static void RegReceiveBroadcastMsgsCb (const ReceiveBroadcastMsgsCallback &cb, const std::string &json_extension="")
 

Detailed Description

聊天功能;主要包括发送消息、接收消息等功能

Member Typedef Documentation

◆ FileUpPrgCallback

typedef std::function<void(int64_t, int64_t)> nim::Talk::FileUpPrgCallback

发送多媒体消息文件上传过程回调模板

◆ RecallMsgsCallback

typedef std::function<void(const NIMResCode, const std::list<RecallMsgNotify>&)> nim::Talk::RecallMsgsCallback

消息撤回通知回调模板

◆ ReceiveBroadcastMsgCallback

typedef std::function<void(const BroadcastMessage&)> nim::Talk::ReceiveBroadcastMsgCallback

接收广播消息通知回调模板

◆ ReceiveBroadcastMsgsCallback

typedef std::function<void(const std::list<BroadcastMessage>&)> nim::Talk::ReceiveBroadcastMsgsCallback

批量接收广播消息通知回调模板

◆ ReceiveMsgCallback

typedef std::function<void(const IMMessage&)> nim::Talk::ReceiveMsgCallback

接收消息通知回调模板

◆ ReceiveMsgsCallback

typedef std::function<void(const std::list<IMMessage>&)> nim::Talk::ReceiveMsgsCallback

批量接收消息通知回调模板

◆ SendMsgAckCallback

typedef std::function<void(const SendMessageArc&)> nim::Talk::SendMsgAckCallback

发送消息回执通知回调模板

◆ TeamNotificationFilter

typedef std::function<bool(const IMMessage&)> nim::Talk::TeamNotificationFilter

群通知过滤器

Member Function Documentation

◆ CreateAudioMessage()

static std::string nim::Talk::CreateAudioMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const IMAudio &  audio,
const std::string &  file_path,
const MessageSetting &  msg_setting,
int64_t  timetag = 0 
)
static

生成语音消息内容,生成的字符串在调用SendMsg时直接传入

Parameters
[in]receiver_id聊天对象的 ID,如果是单聊,为用户帐号,如果是群聊,为群组 ID
[in]session_typeNIMSessionType,聊天类型,单聊或群组
[in]client_msg_id客户端消息id,建议uuid
[in]audioIMAudio,语音文件信息
[in]file_path文件本地绝对路径
[in]msg_setting消息属性设置
[in]timetag消息时间
Returns
std::string 语音消息Json字符串

◆ CreateBotRobotMessage()

static std::string nim::Talk::CreateBotRobotMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const std::string &  content,
const IMBotRobot &  bot_msg,
const MessageSetting &  msg_setting,
int64_t  timetag = 0 
)
static

生成Tip消息内容,生成的字符串在调用SendMsg时直接传入

Parameters
[in]receiver_id聊天对象的 ID,如果是单聊,为用户帐号,如果是群聊,为群组 ID
[in]session_typeNIMSessionType,聊天类型,单聊或群组
[in]client_msg_id客户端消息id,建议uuid
[in]content内容
[in]bot_msg机器人消息信息
[in]msg_setting消息属性设置
[in]timetag消息时间
Returns
std::string 位置消息Json字符串

◆ CreateFileMessage()

static std::string nim::Talk::CreateFileMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const IMFile &  file,
const std::string &  file_path,
const MessageSetting &  msg_setting,
int64_t  timetag = 0 
)
static

生成文件消息内容,生成的字符串在调用SendMsg时直接传入

Parameters
[in]receiver_id聊天对象的 ID,如果是单聊,为用户帐号,如果是群聊,为群组 ID
[in]session_typeNIMSessionType,聊天类型,单聊或群组
[in]client_msg_id客户端消息id,建议uuid
[in]fileIMFile,文件信息
[in]file_path文件本地绝对路径
[in]msg_setting消息属性设置
[in]timetag消息时间
Returns
std::string 文件消息Json字符串

◆ CreateImageMessage()

static std::string nim::Talk::CreateImageMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const IMImage &  image,
const std::string &  file_path,
const MessageSetting &  msg_setting,
int64_t  timetag = 0 
)
static

生成图片消息内容,生成的字符串在调用SendMsg时直接传入

Parameters
[in]receiver_id聊天对象的 ID,如果是单聊,为用户帐号,如果是群聊,为群组 ID
[in]session_typeNIMSessionType,聊天类型,单聊或群组
[in]client_msg_id客户端消息id,建议uuid
[in]imageIMImage,图片文件信息
[in]file_path文件本地绝对路径
[in]msg_setting消息属性设置
[in]timetag消息时间
Returns
std::string 图片消息Json字符串

◆ CreateLocationMessage()

static std::string nim::Talk::CreateLocationMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const IMLocation &  location,
const MessageSetting &  msg_setting,
int64_t  timetag = 0 
)
static

生成位置消息内容,生成的字符串在调用SendMsg时直接传入

Parameters
[in]receiver_id聊天对象的 ID,如果是单聊,为用户帐号,如果是群聊,为群组 ID
[in]session_typeNIMSessionType,聊天类型,单聊或群组
[in]client_msg_id客户端消息id,建议uuid
[in]locationIMLocation,位置信息
[in]msg_setting消息属性设置
[in]timetag消息时间
Returns
std::string 位置消息Json字符串

◆ CreateRetweetMessage()

static std::string nim::Talk::CreateRetweetMessage ( const std::string &  src_msg_json,
const std::string &  client_msg_id,
const NIMSessionType  retweet_to_session_type,
const std::string &  retweet_to_session_id,
const MessageSetting &  msg_setting,
int64_t  timetag = 0 
)
static

由其他消息生成转发消息

Parameters
[in]src_msg_json原消息json
[in]client_msg_id新的客户端消息id,建议uuid
[in]retweet_to_session_type转发目标会话类型 NIMSessionType
[in]retweet_to_session_id转发目标ID
[in]msg_setting消息属性设置
[in]timetag消息时间
Returns
std::string 位置消息Json字符串

◆ CreateTextMessage()

static std::string nim::Talk::CreateTextMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const std::string &  content,
const MessageSetting &  msg_setting,
int64_t  timetag = 0 
)
static

生成文字消息内容,生成的字符串在调用SendMsg时直接传入

Parameters
[in]receiver_id聊天对象的 ID,如果是单聊,为用户帐号,如果是群聊,为群组 ID
[in]session_typeNIMSessionType,聊天类型,单聊或群组
[in]client_msg_id客户端消息id,建议uuid
[in]content文本内容
[in]msg_setting消息属性设置
[in]timetag消息时间
Returns
std::string 文字消息Json字符串

◆ CreateTipMessage()

static std::string nim::Talk::CreateTipMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const std::string &  tip_content,
const MessageSetting &  msg_setting,
int64_t  timetag = 0 
)
static

生成Tip消息内容,生成的字符串在调用SendMsg时直接传入

Parameters
[in]receiver_id聊天对象的 ID,如果是单聊,为用户帐号,如果是群聊,为群组 ID
[in]session_typeNIMSessionType,聊天类型,单聊或群组
[in]client_msg_id客户端消息id,建议uuid
[in]tip_contentTip文本内容
[in]msg_setting消息属性设置
[in]timetag消息时间
Returns
std::string 位置消息Json字符串

◆ CreateVideoMessage()

static std::string nim::Talk::CreateVideoMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const IMVideo &  video,
const std::string &  file_path,
const MessageSetting &  msg_setting,
int64_t  timetag = 0 
)
static

生成视频消息内容,生成的字符串在调用SendMsg时直接传入

Parameters
[in]receiver_id聊天对象的 ID,如果是单聊,为用户帐号,如果是群聊,为群组 ID
[in]session_typeNIMSessionType,聊天类型,单聊或群组
[in]client_msg_id客户端消息id,建议uuid
[in]videoIMVideo,视频文件信息
[in]file_path文件本地绝对路径
[in]msg_setting消息属性设置
[in]timetag消息时间
Returns
std::string 视频消息Json字符串

◆ GetAttachmentPathFromMsg()

static std::string nim::Talk::GetAttachmentPathFromMsg ( const IMMessage &  msg)
static

从消息体中获取附件(图片、语音、视频等)的本地路径

Parameters
[in]msg消息
Returns
char * 消息如果有附件,不管是否已下载,返回附件的本地路径;消息如果没有附件,返回空字符串。

◆ ParseAudioMessageAttach()

static bool nim::Talk::ParseAudioMessageAttach ( const IMMessage &  msg,
IMAudio &  audio 
)
static

通过得到的消息获得语音信息

Parameters
[in]msg消息
[out]audio语音信息
Returns
bool 解析是否成功

◆ ParseBotRobotMessageAttach()

static bool nim::Talk::ParseBotRobotMessageAttach ( const IMMessage &  msg,
IMBotRobot &  robot_msg 
)
static

◆ ParseFileMessageAttach()

static bool nim::Talk::ParseFileMessageAttach ( const IMMessage &  msg,
IMFile &  file 
)
static

通过得到的消息获得文件信息

Parameters
[in]msg消息
[out]file文件信息
Returns
bool 解析是否成功

◆ ParseImageMessageAttach()

static bool nim::Talk::ParseImageMessageAttach ( const IMMessage &  msg,
IMImage &  image 
)
static

通过得到的消息获得图片信息

Parameters
[in]msg消息
[out]image图片信息
Returns
bool 解析是否成功

◆ ParseIMMessage()

static bool nim::Talk::ParseIMMessage ( const std::string &  json_msg,
IMMessage &  msg 
)
static

解析消息Json字符串

Parameters
[in]json_msg消息内容Json字符串
[out]msg消息内容
Returns
bool 解析是否成功

◆ ParseLocationMessageAttach()

static bool nim::Talk::ParseLocationMessageAttach ( const IMMessage &  msg,
IMLocation &  location 
)
static

通过得到的消息获得位置信息

Parameters
[in]msg消息
[out]location位置信息
Returns
bool 解析是否成功

◆ ParseVideoMessageAttach()

static bool nim::Talk::ParseVideoMessageAttach ( const IMMessage &  msg,
IMVideo &  video 
)
static

通过得到的消息获得视频信息

Parameters
[in]msg消息
[out]video视频信息
Returns
bool 解析是否成功

◆ RecallMsg()

static void nim::Talk::RecallMsg ( const IMMessage &  msg,
const std::string &  notify,
const RecallMsgsCallback cb,
const std::string &  json_extension = "" 
)
static

撤回消息

Parameters
[in]msg消息
[in]notify自定义通知消息
[in]json_extensionjson扩展参数(备用,目前不需要)
[in]cb回调
Returns
void 无返回值
Note
错误码 200:成功 414:参数错误 508:撤回时间超过配制有效期,默认是2分钟 10414:本地错误码,参数错误 10508:本地错误码,超过配置有效期或者所需参数不存在

◆ RegRecallMsgsCallback()

static void nim::Talk::RegRecallMsgsCallback ( const RecallMsgsCallback cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册消息回调通知接口

Parameters
[in]json_extensionjson扩展参数(备用,目前不需要)
[in]cb回调
Returns
void 无返回值
Note
错误码 200:成功

◆ RegReceiveBroadcastMsgCb()

static void nim::Talk::RegReceiveBroadcastMsgCb ( const ReceiveBroadcastMsgCallback cb,
const std::string &  json_extension = "" 
)
static

◆ RegReceiveBroadcastMsgsCb()

static void nim::Talk::RegReceiveBroadcastMsgsCb ( const ReceiveBroadcastMsgsCallback cb,
const std::string &  json_extension = "" 
)
static

◆ RegReceiveCb()

static void nim::Talk::RegReceiveCb ( const ReceiveMsgCallback cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册接收消息回调 (建议全局注册,统一接受回调后分发消息到具体的会话)

Parameters
[in]json_extensionjson扩展参数(备用,目前不需要)
[in]cb接收消息的回调函数
Returns
void 无返回值
Note
错误码 200:成功 10414:本地错误码,参数错误 10417:本地错误码,对象已经存在/重复操作

(全局回调)注册接收广播消息回调 (全局注册)

Parameters
[in]json_extensionjson扩展参数(备用,目前不需要)
[in]cb接收消息的回调函数
Returns
void 无返回值
Note
错误码 200:成功 10414:本地错误码,参数错误 10417:本地错误码,对象已经存在/重复操作

◆ RegReceiveMessagesCb()

static void nim::Talk::RegReceiveMessagesCb ( const ReceiveMsgsCallback cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册批量接收消息回调 (建议全局注册,统一接受回调后分发消息到具体的会话)

Parameters
[in]json_extensionjson扩展参数(备用,目前不需要)
[in]cb接收消息的回调函数
Returns
void 无返回值
Note
错误码 200:成功

(全局回调)注册批量接收广播消息回调 (全局注册)

Parameters
[in]json_extensionjson扩展参数(备用,目前不需要)
[in]cb接收消息的回调函数
Returns
void 无返回值
Note
错误码 200:成功

◆ RegSendMsgCb()

static void nim::Talk::RegSendMsgCb ( const SendMsgAckCallback cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册发送消息回调函数 (必须全局注册,统一接受回调后分发消息到具体的会话。注意:客户端发包之后,服务器不一定会返回!!!)

Parameters
[in]json_extensionjson扩展参数(备用,目前不需要)
[in]cb发送消息的回调函数
Returns
void 无返回值
Note
错误码 200:成功 408:请求过程超时 414:参数错误 802:没有权限(群错误码) 811:强推列表中帐号数量超限(群错误码) 812:群禁言(群错误码) 10200:发送文件消息,NOS上传暂停 10404:本地资源不存在 10414:本地错误码,参数错误 10502:发送消息,上传NOS失败

◆ RegTeamNotificationFilter()

static void nim::Talk::RegTeamNotificationFilter ( const TeamNotificationFilter cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册群通知过滤接口 (堵塞线程,谨慎使用,避免耗时行为)

Parameters
[in]json_extensionjson扩展参数(备用,目前不需要)
[in]filter过滤接口
Returns
void 无返回值

◆ SendMsg()

static void nim::Talk::SendMsg ( const std::string &  json_msg,
const std::string &  json_extension = "",
FileUpPrgCallback pcb = nullptr 
)
static

发送消息

Parameters
[in]json_msg消息体Json字符串,可以通过CreateXXXMessage方法自动创建
[in]json_extensionjson扩展参数(备用,目前不需要)
[in]pcb上传进度的回调函数, 如果发送的消息里包含了文件资源,则通过此回调函数通知上传进度
Returns
void 无返回值

◆ StopSendMsg()

static bool nim::Talk::StopSendMsg ( const std::string &  client_msg_id,
const NIMMessageType &  type,
const std::string &  json_extension = "" 
)
static

停止正在发送中的消息(目前只支持发送文件消息时的终止)

Parameters
[in]client_msg_id停止发送的消息客户端id
[in]type停止发送的消息类型
[in]json_extensionjson扩展参数(备用,目前不需要)
Returns
void 无返回值

◆ UnregTalkCb()

void nim::Talk::UnregTalkCb ( )
static

反注册Talk提供的所有回调

Returns
void 无返回值

The documentation for this class was generated from the following file: