聊天和问答需要获取用户标识与头像,需提前使用第三方创建用户接口创建用户,如传入的第三方用户信息未匹配到用户标识,将自动进行创
建,并默认为游客以及使用微吼的默认头像。目前聊天和问答模块只支持观看端,如需要进行管理操作(禁言、踢出、过滤以及回答等功能),
请前往微吼平台上进行操作。视频模块目前只支持移动端,需在页面上自行添加HTML5的video标签,样式自行定义,播放相关事件使用的是
HTML5中 video标签和 media标签的原生事件。
API | 说明 | 返回内容 |
---|---|---|
getRoominfo() | 获取当前活动状态 | 活动相关的状态信息 |
getUserinfo() | 获取当前用户参会信息 | 用户参会的信息 |
player.setPlayerDefinition(name) | 设置播放清晰度,值来自于canPlayDefinitions事件中的msg的键 | 切换播放清晰度 |
player.setPlayerLine(name) | 设置播放线路,值来自于canPlayLines事件中的msg的键 | 切换播放线路 |
sendChat({text:' '}) | 聊天消息发送,text:消息文本,长度限制为140个字符 | 组装好的聊天数据 |
sendQuestion({text:' '}) | 提问问题发送,text:问题文本,长度限制为140个字符 | 组装好的提问数据 |
vhall_get_live_history_chat_msg() | 获取直播聊天历史记录 | 请求后触发事件vhall_live_history_chat_msg |
getQuestionlist() | 获取问答记录 | 请求后触发事件getQuestionList |
vhall_get_record_history_chat_msg(curr_page) | 回放拉取历史聊天,curr_page:需拉取数据的页数,每页20条 |
API | 说明 |
---|
API | 说明 |
ready | SDK准备就绪后触发事件,全局事件 |
error | SDK调用错误事件消息,全局事件 |
playerReady | 播放器准备就绪后触发事件,全局事件 |
streamOver | 直播活动结束,全局事件 |
publishStart | 活动开始推流,全局事件 |
canPlayLines | 获取视频可播放线路,播放器事件 |
canPlayDefinitions | 获取视频可播放清晰度,播放器事件 |
userOnline | 用户上线事件消息 |
userOffline | 用户下线事件消息 |
chatMsg | 收到直播聊天消息事件 |
sendChat | 发送聊天消息后触发事件 |
disadbleChat | 直播禁言消息 |
permitChat | 直播恢复禁言消息 |
forbidchat | 直播全员禁言消息,1为全员禁言,0为恢复全员禁言 |
kickout | 直播踢出消息 |
kickoutrestore | 直播恢复踢出消息 |
vhall_live_history_chat_msg | 拉取直播历史消息后触发事件 |
vhall_record_history_chat_msg | 拉取回放历史消息后触发事件 |
questionSwitch | 问答开关消息 |
sendQuestion | 问答消息发送事件 |
questionMsg | 收到问答消息,只包含用户能接收的问答消息 |
getQuestionList | 拉取直播问答消息后触发事件 |
错误码 | 说明 |
---|---|
10000 | 消息体格式不对 |
10001 | 消息体为空 |
10002 | 当前用户被禁言 |
10003 | 聊天输入不能超过140个字符 |
10004 | 当前已开启全员禁言 |
10005 | 当前活动不是直播状态 |
10006 | 当前活动未开启问答 |
20000 | 接口请求成功 |
20005 | 没有数据 |
/** * [ready sdk准备就绪] */ VHALL_SDK.on('ready', function() { VHALL_SDK.getUserinfo(); /** * { * avatar:"//cnstatic01.e.vhall.com/static/images/watch/head50.png" //头像 * forbidchat:"" //0:未开启全员禁言,1:已开启全员禁言 * is_gag:0 //0:未禁言,1:禁言 * is_kickout:0 //0:未踢出,1:踢出 * role:"user"//用户角色 * userid:"用户参会id" * username:"昵称" * } */ VHALL_SDK.getRoominfo(); /** * { * type: 1 // 1:活动直播中,2:预约中,3:活动结束 * openQuestion : 1 //1: 开启,0 || '':关闭 * } */ });
/** * [error sdk调用错误事件] * @param {[type]} msg [description] */ VHALL_SDK.on('error', function(msg) { console.log(msg); });
VHALL_SDK.on("playerReady", function(){ /** * 可播线路消息 */ VHALL_SDK.player.on('canPlayLines', function(msg) { var _src = ''; // i 的值为之后调用方法VHALL_SDK.player.setPlayerLine的传参 for (var i in msg) { _src += '<li>' + i + '</li>'; } $("#lines").html(_src).find("li").eq(0).addClass('active'); }); /** * 可播清晰度消息 */ VHALL_SDK.player.on('canPlayDefinitions', function(msg) { var _src = ''; // i 的值为之后调用方法VHALL_SDK.player.setPlayerDefinition的传参 for (var i in msg) { _src += '<li>' + i + '</li>'; } $("#definitions").html(_src).find("li").eq(0).addClass('active'); }); });
VHALL_SDK.on('publishStart', function(msg) { alert('活动开始推流'); });
VHALL_SDK.on('streamOver', function(msg) { alert('活动已结束'); });
/** * [userOnline 用户上线] * @param {[type]} msg [description] */ VHALL_SDK.on('userOnline', function(msg) { console.log(msg); });
/** * [userOffline 用户下线] * @param {[type]} msg [description] */ VHALL_SDK.on('userOffline', function(msg) { console.log(msg); });
/** * [chatMsg 直播收到聊天消息] * @param {[type]} msg [object] */ VHALL_SDK.on('chatMsg', function(msg) { console.log(msg); });
/** * [sendChat 直播消息发送后事件] */ VHALL_SDK.on('sendChat, function(msg) { console.log(msg); });
/** * [sendQuestion 直播问答消息发送事件] */ VHALL_SDK.on('sendQuestion, function(msg) { console.log(msg); });
/** * [disadbleChat 直播禁言消息] * @param {[type]} [禁言用户id] */ VHALL_SDK.on('disadbleChat', function(userid) { console.log(userid); });
/** * [forbidchat 直播全员禁言消息] * @param {[type]} status [1:开启,0:关闭] */ VHALL_SDK.on('forbidchat', function(status) { console.log(status); });
/** * [kickout 直播踢出消息] * @param {[type]} userid [被踢出用户id] */ VHALL_SDK.on('kickout', function(userid) { console.log(userid); });
/** * [kickoutRestore 直播恢复踢出消息] * @param {[type]} userid [恢复踢出用户id] */ VHALL_SDK.on('kickoutRestore', function(userid) { console.log(userid); });
/** * [vhall_live_history_chat_msg 获取直播历史消息成功回调] * @param {[arraylist]} msg [数据数组] */ VHALL_SDK.on('vhall_live_history_chat_msg', function(msg) { console.log(msg); });
/** * [vhall__record_history_chat_msg 获取回放历史消息成功回调] * @param {[arraylist]} msg [数据数组,回放中有curr_page,total,total_page有数据] */ VHALL_SDK.on('vhall_record_history_chat_msg', function(msg) { console.log(msg); });
/** * [questionSwitch 直播问答开关消息] * @param {[type]} msg [msg.status 1:开启,0:关闭] */ VHALL_SDK.on('questionSwitch', function(msg) { console.log(userid); });
/** * [sendQuestion 直播问答消息发送事件] */ VHALL_SDK.on('sendQuestion, function(msg) { console.log(msg); });
/** * [question 直播问答消息] * @param {[type]} msg [消息体] */ VHALL_SDK.on('questionMsg', function(msg) { console.log(userid); });
/** * [getQuestionList 获取直播问答历史消息] * @type {[type]} */ VHALL_SDK.getQuestionList();
demo地址:http://cnstatic01.e.vhall.com/jssdk/dist/2.3.3/
demo提供了基本的样式,开发者可在demo样式的基础上修改成自定义的样式