hyExt.context.on
- 监听直播间消息
- 引入版本 1.1.0
- 适用终端
- 虎牙直播主站
- 虎牙直播APP-iOS:7.9.3
- 虎牙直播APP-安卓:7.9.4
- 虎牙直播助手-iOS:3.14.0
- 虎牙直播助手-安卓:3.14.0
- 虎牙直播PC客户端-主播侧:4.9.0.3
- 虎牙直播PC客户端-观众侧:4.12.2.0
接口签名
declare namespace hyExt {
module context {
/**
* 监听直播间消息
* @param topic 宿主消息名;取值说明:
* activated 小程序激活;
* subscribeSubmit 【观众端】当前观众订阅状态发生变化;
* giftSubmit 【观众端】当前观众送礼;
* barrageSubmit 当前用户发送弹幕;
* unzipProgress 每个任务的解压进度;
* userInteract 用户交互信息;
* downloadProgress 批量下载资源进度;
* openCoinPanelClosed 能量豆弹窗关闭;
* uiVisibilityStateChange 工具栏状态;
* @param callback 收到消息时回调
*/
function on(topic: string, callback: ContextOnCallback): void
}
/**
* 收到消息时回调
* @param content 收到宿主消息
*/
type ContextOnCallback = (content: any) => void
}
其中topic为"subscribeSubmit"时,回调函数的参数结构为:
type SubscribeSubmitNotice = boolean
topic为"giftSubmit"时,回调函数的参数结构为:
type GiftSubmitNotice = {
/** 送礼人的昵称 */
sendNick: string;
/** 送礼人的头像地址 */
senderAvatarUrl: string;
/** 礼物名称 */
itemName: string;
/** 礼物Id */
itemId: number;
/** 礼物数量 */
sendItemCount: number;
/** 送礼连击数 */
sendItemComboHits: number;
}
topic为"barrageSubmit"时,回调函数的参数结构为:
type BarrageSubmitNotice = {
/** 发送弹幕的用户昵称 */
sendNick: string;
/** 发送弹幕的用户头像地址 */
senderAvatarUrl: string;
/** 发送弹幕的用户性别,女为0男为1 */
senderGender: number;
/** 发送弹幕的用户贵族等级 */
nobleLevel: number;
/** 发送弹幕的用户粉丝等级 */
fansLevel: number;
/** 弹幕内容 */
content: string;
}
topic为"downloadProgress"时,回调函数的参数结构为:
type DownloadProgressNotice = {
/**
* 状态码;取值说明:
* 0 下载成功或者文件已经存在;
* 1 正在下载;
* -1 下载失败;
*/
res: 0|1|-1
/** 下载成功失败提示信息 */
msg: string
/** 下载资源的url */
url: string
/** 下载资源的md5 */
md5: string
/** 已下载的字节数(res=1时有效)*/
bytesLoaded: boolean
/** 总字节数(res=1时有效)*/
bytesTotal: number
/** 文件路径,仅res为0的时候才有效 */
path: string
}
topic为"openCoinPanelClosed"时,回调函数的参数结构为:
type OpenCoinPanelClosedNotice = {
/**
* 能量豆弹窗打开类型;取值说明:
* exchange 充值弹窗;
* consume 消费弹窗;
*/
openType: 'exchange' | 'consume';
/**
* 能量豆弹窗关闭类型;取值说明:
* activeClose 主动关闭;
* endProcess 流程结束;
*/
closeType: string;
}
示例代码
hyExt.context.on("activated", (content) => {
console.log("回调触发", content)
})
hyExt.context.on("subscribeSubmit", (isSubscribed) => {
/** 宿主消息回调 */
})
hyExt.context.on("giftSubmit", ({
sendNick,
senderAvatarUrl,
itemName,
itemId,
sendItemCount,
sendItemComboHits
}) => {
/** 宿主消息回调 */
})
hyExt.context.on("barrageSubmit", ({
sendNick,
senderAvatarUrl,
senderGender,
nobleLevel,
fansLevel,
content
}) => {
/** 宿主消息回调 */
})
生命周期
直播间信息
环境信息
弹幕
礼物
文本秩序审核
小程序消息
终端事件监听
KV存储
主播端白板
网络库
文件处理
外部EXE能力
浮窗
小程序付费功能
订阅
直播间分享事件
守护事件
贵族事件
高级用户进场事件
小程序入口控制
本地小程序控制
语音识别事件
手势识别事件
视觉识别事件
人体轮廓点检测事件
肢体骨骼点检测事件
人脸特征点检测事件
播放视频
直播间视频
后台相关