wuyanan

ref |> 对接直播聊天室IM消息,收到消息展示到界面上

... ... @@ -20,6 +20,10 @@ export interface LiveRoomItemBean {
role: string
//ZH_TEXT_AND_IMAGE_MSG :图文,ZH_TEXT_MSG:文本,ZH_VIDEO_MSG:视频,ZH_AUDIO_MSG:音频
dataType: string
//管理直播间的消息类型 ZH_BARRAGE_SWITCH_MSG:弹幕开关 ZH_TOP_MSG:置顶,ZH_UN_TOP_MSG:取消置顶 ZH_STOP_LIVE: 直播结束,ZH_CHANGE_PAD直播垫片等
optionType: string
///房间类型,标识这个消息属于大家聊还是直播间,ZH_VIDEO:直播间 ZH_CHAT:大家聊
messageRoom: string
//视频封面图
transcodeImageUrl: string
//视频地址
... ... @@ -32,5 +36,7 @@ export interface LiveRoomItemBean {
audioUrl: string
//详情页面插入数据bean
fullColumnImgUrlDto: FullColumnImgUrlDTO
//观看人次
pv: string
}
\ No newline at end of file
... ...
... ... @@ -2,10 +2,15 @@ import { ContentDetailDTO } from 'wdBean/Index'
import { LiveRoom } from './LiveRoom'
import { LiveRoomBaseInfo } from './LiveRoomBaseInfo'
import { LiveRoomManager } from './LiveRoomManager'
import { LiveRoomItemBean } from 'wdBean/Index';
export class LiveDetailChatRoomController {
detail?: ContentDetailDTO
///用于展示的历史消息,包含聊天室和直播间
onHistoryMessage?: (liveRoomItemBean: LiveRoomItemBean) => void
///用于管理直播间状态的消息,直播垫片,直播结束,上墙/取消上墙,置顶/取消置顶等
onLiveMessage?: (liveRoomItemBean: LiveRoomItemBean) => void
public configDetail(detail: ContentDetailDTO) {
this.detail = detail
... ... @@ -32,6 +37,16 @@ export class LiveDetailChatRoomController {
room.onExited = (room: LiveRoom) => {
}
room.onHistoryMessage = (liveRoomItemBean: LiveRoomItemBean) => {
if (this.onHistoryMessage) {
this.onHistoryMessage(liveRoomItemBean)
}
}
room.onLiveMessage = (liveRoomItemBean: LiveRoomItemBean) => {
if (this.onLiveMessage) {
this.onLiveMessage(liveRoomItemBean)
}
}
room.enterRoom()
}
... ...
... ... @@ -5,9 +5,11 @@ import { ChatroomDestroyType,
IMEngine, Message, ReceivedInfo,
TextMessage} from '@rongcloud/imlib';
import { Logger } from 'wdKit/Index';
import { LiveRoomItemBean } from 'wdBean/Index';
import { LiveRoomBaseInfo } from './LiveRoomBaseInfo'
import { JSON } from '@kit.ArkTS';
import { JSON } from '@kit.ArkTS';
const TAG = "LiveRoomManager"
export class LiveRoom extends ChatroomStatusListener {
... ... @@ -18,6 +20,10 @@ export class LiveRoom extends ChatroomStatusListener {
onJoined?: (room: LiveRoom) => void
onJoinFailed?: (room: LiveRoom, code: number) => void
onExited?: (room: LiveRoom) => void
///用于展示的历史消息,包含聊天室和直播间
onHistoryMessage?: (liveRoomItemBean: LiveRoomItemBean) => void
///用于管理直播间状态的消息,直播垫片,直播结束,上墙/取消上墙,置顶/取消置顶等
onLiveMessage?: (liveRoomItemBean: LiveRoomItemBean) => void
constructor(baseInfo?: LiveRoomBaseInfo) {
super()
... ... @@ -93,9 +99,41 @@ export class LiveRoom extends ChatroomStatusListener {
return
}
let textMsg = message.content as TextMessage
textMsg.content
let liveRoomItemBean = JSON.parse(textMsg.content) as LiveRoomItemBean
if (liveRoomItemBean == undefined) {
return
}
}
let optionType = liveRoomItemBean.optionType != undefined ? liveRoomItemBean.optionType : liveRoomItemBean.dataType
if (this.isHistoryMessage(optionType)) {
if (this.onHistoryMessage) {
this.onHistoryMessage(liveRoomItemBean)
}
return
}
if (this.onLiveMessage) {
// liveRoomItemBean.pv = Number(liveRoomItemBean.pv) + 1000000 + ""
this.onLiveMessage(liveRoomItemBean)
}
}
isHistoryMessage(optionType: string): boolean {
let isHistoryMessage = false
switch (optionType) {
case "ZH_TEXT_MSG":
case "ZH_IMAGE_MSG":
case "ZH_TEXT_AND_IMAGE_MSG":
case "ZH_AUDIO_MSG":
case "ZH_VIDEO_MSG": {
isHistoryMessage = true
} break;
default:
break;
}
return isHistoryMessage
}
}
\ No newline at end of file
... ...
... ... @@ -163,7 +163,7 @@ export class LiveRoomManager {
// },
// }
IMEngine.getInstance().setChatroomStatusListener(this.connectedRoom);
IMEngine.getInstance().setMessageReceivedListener(this.connectedRoom.onMessage);
IMEngine.getInstance().setMessageReceivedListener(this.connectedRoom.onMessage.bind(this.connectedRoom));
if (this.onConnectedRoom) {
this.onConnectedRoom(this.connectedRoom)
}
... ...
... ... @@ -83,7 +83,18 @@ export struct DetailPlayLivePage {
if(!await onlyWifiLoadVideo()){
this.showToastTip(this.toastText)
}
this.chatRoomController.onHistoryMessage = (liveRoomItemBean: LiveRoomItemBean) => {
if (liveRoomItemBean.messageRoom == "ZH_VIDEO") {
this.lastInputedLiveComment = liveRoomItemBean
} else if (liveRoomItemBean.messageRoom == "ZH_CHAT") {
this.lastInputedChatComment = liveRoomItemBean
}
}
this.chatRoomController.onLiveMessage = (liveRoomItemBean: LiveRoomItemBean) => {
if (liveRoomItemBean.optionType == "ZH_ROOM_NUMBER_MSG") {
this.liveRoomDataBean.pv = Number(liveRoomItemBean.pv)
}
}
this.chatRoomController.configDetail(this.contentDetailData)
}
... ...