chat 模块进行调用访问。版本说明: vhall_get_live_history_chat_msg(直播历史)与vhall_get_record_history_chat_msg(回放历史)两个接口规则对齐,以 SDK 3.7.3 为分界。3.7.3 之前:传入数字页码分页; 3.7.3 及之后:推荐使用对象锚点分页,优化历史消息重复拉取问题。
| API 名称 | 功能描述 | 参数 | 返回值 | 备注 |
|---|---|---|---|---|
| sendChat | 发送聊天消息 | msg: String | Promise | 聊天内容,最多支持140字符 |
| sendCustomEvent | 发送自定义消息 | msg: Object | Promise | 自定义消息对象,格式 {type: '自定义消息 类型', data:{ name: '自定义消息数据'}} |
| vhall_get_live_history_chat_msg | 获取直播聊天历史记录 | opt: Number / Object | Promise | 3.7.3前传数字页码;3.7.3+推荐锚点对象分页,单页最多返回50条。 ⚠️ 页码模式踩坑:数据不足50条时传入页码1会返回空数组,首页应传0 |
| vhall_get_record_history_chat_msg | 获取回放聊天历史记录 | page: Number / Object | Promise | 3.7.3前传数字页码;3.7.3+推荐锚点对象分页,单页最多返回50条。 |
vhallSDKInstance.chat.sendCustomEvent(msg)// opt:页码,首页传0
vhallSDKInstance.vhall_get_live_history_chat_msg(0)
.then((history) => {
// 处理返回的历史消息集合
})
.catch((error) => {
// 错误处理
});msgId:从指定消息ID开始查询,首页留空;anchorPath:查询方向,down查询当前消息之前的消息,up查询当前消息之后的消息
vhallSDKInstance.vhall_get_live_history_chat_msg({
msgId: "",
anchorPath: "down",
})
.then((history) => {
// 处理返回的历史消息集合
})
.catch((error) => {
// 错误处理
});// page:页码
vhallSDKInstance.chat.vhall_get_record_history_chat_msg(0)
.then((history) => {
// 处理返回的历史消息集合
})
.catch((error) => {
// 错误处理
});参数结构含义和直播历史接口完全一致
vhallSDKInstance.chat.vhall_get_record_history_chat_msg({
msgId: "",
anchorPath: "down",
})
.then((history) => {
// 处理返回的历史消息集合
})
.catch((error) => {
// 错误处理
});var vhallSDKInstance = new VhallSDK({
... // 微吼SDK 初始化参数
})
// 发送聊天消息
vhallSDKInstance.chat.sendChat(msg)
// 发送自定义聊天消息
vhallSDKInstance.chat.sendCustomEvent(msg)