| 类名 | 类描述 |
|---|---|
| VHSaaSDK.getInstance().userLike | 创建房间的用户点赞 |
| VHSaaSDK.getInstance()getRoomLike | 获取房间的点赞数量 |
| 方法 | 方法描述 |
|---|---|
| imReceiveChatMessage | 消息回调监听 |
| 方法 | 方法描述 |
|---|---|
| VHRoomEventType.CUSTOM_PRAISE | 签到开始消息 |
public userLike(roomId: string, num: string, callback: CallBack)| 参数名称 | 是否必须 | 示例 | 备注 |
|---|---|---|---|
| roomId | 是 | lss_xxxxxx | 房间 id |
| num | 是 | 99 | 点赞次数,最多 500,超过 500 会强制成为 500 |
| callback | 接口请求完成回调 |
VHSaaSDK.getInstance().userLike(this.webinars?.interact?.room_id!, this.clickLikeNumber.toString(), {
onSuccess: (data: string | object) => {
console.log("增加点赞数:", this.clickLikeNumber);
},
onFailure: (errorCode, errorMsg) => {
console.log("增加点赞数失败:", errorMsg)
ToastUtil.showToast(errorMsg);
}
}); public getRoomLike(roomId: string, callback: VHRoomLikeCallback)| 参数名称 | 是否必须 | 示例 | 备注 |
|---|---|---|---|
| roomId | 是 | lss_xxxxxx | 房间 id |
| callback | 接口请求完成回调 | VHRoomLikeCallback |
getLikeCount() {
VHSaaSDK.getInstance().getRoomLike(this.webinars?.interact?.room_id!, {
onSucceed: (data: VHRoomLikeInfo) => {
this.likeCount = Number(data.total) + Number(data.virtual_count) ;
},
onFailure: (errorCode, errorMsg) => {
console.log("聊天获得历史记录失败:", errorMsg)
}
});
}| VHRoomLikeInfo | 类型 | 备注 |
|---|---|---|
| total | string | 当前房间实际点赞数量 |
| virtual_count | string | 虚拟点赞数 |
//读取配置
if (this.functionConfig?.watch_hide_like == 0) {
Image($r('app.media.icon_like'))
.width(30)
.height(30)
.margin({ right: 5 })
.onClick(() => {
this.likeCount++;
this.clickLikeNumber++;
this.timer?.cancel();
this.timer?.start();
// 在按钮中心上方50px位置生成气泡
// 获取按钮实际位置
const buttonWidth = 10
const buttonHeight = 10
const btnCenterX = (this.context.width * 0.9) + buttonWidth / 2
const btnCenterY = (this.context.height * 0.9) + buttonHeight / 2
// 在按钮中心生成气泡,并限制随机偏移范围
const maxOffset = 20
this.addLikeIcon(
btnCenterX + Math.random() * maxOffset - maxOffset / 2,
btnCenterY - 10 + Math.random() * maxOffset - maxOffset / 2
)
})
}监听房间事件CUSTOM_PRAISE
//监听聊天回调点赞消息
imReceiveChatMessage(type: string, message: VHIMMessageModel) {
// 点赞消息
if (type === VHRoomEventType.CUSTOM_PRAISE) {
EmitterMessage.handleCustomMessage(type, message);
}
}
public static handleCustomMessage(type: string, message: VHIMMessageModel) {
let msgData: EmitterMsgData;
msgData = {
type: type,
data: message
} as EmitterMsgData;
EmitterUtil.send(msgData);
}
//更新点赞数据
handleLikeCount(msg?: VHIMMessageModel) {
if (!msg) {
return;
}
// 接收文本消息
let imMsg: VHContent = msg as VHContent;
imMsg.data = msg.data as VHMsgData;
// 接收点赞数
if (imMsg.data!.event_type === VHRoomEventType.CUSTOM_PRAISE && imMsg.data!.num! > 0) {
this.likeCount = imMsg.data.num;
}
}