wuyanan

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

@@ -20,6 +20,10 @@ export interface LiveRoomItemBean { @@ -20,6 +20,10 @@ export interface LiveRoomItemBean {
20 role: string 20 role: string
21 //ZH_TEXT_AND_IMAGE_MSG :图文,ZH_TEXT_MSG:文本,ZH_VIDEO_MSG:视频,ZH_AUDIO_MSG:音频 21 //ZH_TEXT_AND_IMAGE_MSG :图文,ZH_TEXT_MSG:文本,ZH_VIDEO_MSG:视频,ZH_AUDIO_MSG:音频
22 dataType: string 22 dataType: string
  23 + //管理直播间的消息类型 ZH_BARRAGE_SWITCH_MSG:弹幕开关 ZH_TOP_MSG:置顶,ZH_UN_TOP_MSG:取消置顶 ZH_STOP_LIVE: 直播结束,ZH_CHANGE_PAD直播垫片等
  24 + optionType: string
  25 + ///房间类型,标识这个消息属于大家聊还是直播间,ZH_VIDEO:直播间 ZH_CHAT:大家聊
  26 + messageRoom: string
23 //视频封面图 27 //视频封面图
24 transcodeImageUrl: string 28 transcodeImageUrl: string
25 //视频地址 29 //视频地址
@@ -32,5 +36,7 @@ export interface LiveRoomItemBean { @@ -32,5 +36,7 @@ export interface LiveRoomItemBean {
32 audioUrl: string 36 audioUrl: string
33 //详情页面插入数据bean 37 //详情页面插入数据bean
34 fullColumnImgUrlDto: FullColumnImgUrlDTO 38 fullColumnImgUrlDto: FullColumnImgUrlDTO
  39 + //观看人次
  40 + pv: string
35 41
36 } 42 }
@@ -2,10 +2,15 @@ import { ContentDetailDTO } from 'wdBean/Index' @@ -2,10 +2,15 @@ import { ContentDetailDTO } from 'wdBean/Index'
2 import { LiveRoom } from './LiveRoom' 2 import { LiveRoom } from './LiveRoom'
3 import { LiveRoomBaseInfo } from './LiveRoomBaseInfo' 3 import { LiveRoomBaseInfo } from './LiveRoomBaseInfo'
4 import { LiveRoomManager } from './LiveRoomManager' 4 import { LiveRoomManager } from './LiveRoomManager'
  5 +import { LiveRoomItemBean } from 'wdBean/Index';
5 6
6 export class LiveDetailChatRoomController { 7 export class LiveDetailChatRoomController {
7 8
8 detail?: ContentDetailDTO 9 detail?: ContentDetailDTO
  10 + ///用于展示的历史消息,包含聊天室和直播间
  11 + onHistoryMessage?: (liveRoomItemBean: LiveRoomItemBean) => void
  12 + ///用于管理直播间状态的消息,直播垫片,直播结束,上墙/取消上墙,置顶/取消置顶等
  13 + onLiveMessage?: (liveRoomItemBean: LiveRoomItemBean) => void
9 14
10 public configDetail(detail: ContentDetailDTO) { 15 public configDetail(detail: ContentDetailDTO) {
11 this.detail = detail 16 this.detail = detail
@@ -32,6 +37,16 @@ export class LiveDetailChatRoomController { @@ -32,6 +37,16 @@ export class LiveDetailChatRoomController {
32 room.onExited = (room: LiveRoom) => { 37 room.onExited = (room: LiveRoom) => {
33 38
34 } 39 }
  40 + room.onHistoryMessage = (liveRoomItemBean: LiveRoomItemBean) => {
  41 + if (this.onHistoryMessage) {
  42 + this.onHistoryMessage(liveRoomItemBean)
  43 + }
  44 + }
  45 + room.onLiveMessage = (liveRoomItemBean: LiveRoomItemBean) => {
  46 + if (this.onLiveMessage) {
  47 + this.onLiveMessage(liveRoomItemBean)
  48 + }
  49 + }
35 50
36 room.enterRoom() 51 room.enterRoom()
37 } 52 }
@@ -5,9 +5,11 @@ import { ChatroomDestroyType, @@ -5,9 +5,11 @@ import { ChatroomDestroyType,
5 IMEngine, Message, ReceivedInfo, 5 IMEngine, Message, ReceivedInfo,
6 TextMessage} from '@rongcloud/imlib'; 6 TextMessage} from '@rongcloud/imlib';
7 import { Logger } from 'wdKit/Index'; 7 import { Logger } from 'wdKit/Index';
  8 +import { LiveRoomItemBean } from 'wdBean/Index';
  9 +
8 import { LiveRoomBaseInfo } from './LiveRoomBaseInfo' 10 import { LiveRoomBaseInfo } from './LiveRoomBaseInfo'
9 -import { JSON } from '@kit.ArkTS';  
10 11
  12 +import { JSON } from '@kit.ArkTS';
11 const TAG = "LiveRoomManager" 13 const TAG = "LiveRoomManager"
12 14
13 export class LiveRoom extends ChatroomStatusListener { 15 export class LiveRoom extends ChatroomStatusListener {
@@ -18,6 +20,10 @@ export class LiveRoom extends ChatroomStatusListener { @@ -18,6 +20,10 @@ export class LiveRoom extends ChatroomStatusListener {
18 onJoined?: (room: LiveRoom) => void 20 onJoined?: (room: LiveRoom) => void
19 onJoinFailed?: (room: LiveRoom, code: number) => void 21 onJoinFailed?: (room: LiveRoom, code: number) => void
20 onExited?: (room: LiveRoom) => void 22 onExited?: (room: LiveRoom) => void
  23 + ///用于展示的历史消息,包含聊天室和直播间
  24 + onHistoryMessage?: (liveRoomItemBean: LiveRoomItemBean) => void
  25 + ///用于管理直播间状态的消息,直播垫片,直播结束,上墙/取消上墙,置顶/取消置顶等
  26 + onLiveMessage?: (liveRoomItemBean: LiveRoomItemBean) => void
21 27
22 constructor(baseInfo?: LiveRoomBaseInfo) { 28 constructor(baseInfo?: LiveRoomBaseInfo) {
23 super() 29 super()
@@ -93,9 +99,41 @@ export class LiveRoom extends ChatroomStatusListener { @@ -93,9 +99,41 @@ export class LiveRoom extends ChatroomStatusListener {
93 return 99 return
94 } 100 }
95 let textMsg = message.content as TextMessage 101 let textMsg = message.content as TextMessage
96 - textMsg.content 102 + let liveRoomItemBean = JSON.parse(textMsg.content) as LiveRoomItemBean
97 103
  104 + if (liveRoomItemBean == undefined) {
  105 + return
  106 + }
98 107
99 - } 108 + let optionType = liveRoomItemBean.optionType != undefined ? liveRoomItemBean.optionType : liveRoomItemBean.dataType
  109 +
  110 + if (this.isHistoryMessage(optionType)) {
  111 + if (this.onHistoryMessage) {
  112 + this.onHistoryMessage(liveRoomItemBean)
  113 + }
  114 + return
  115 + }
  116 + if (this.onLiveMessage) {
  117 + // liveRoomItemBean.pv = Number(liveRoomItemBean.pv) + 1000000 + ""
  118 + this.onLiveMessage(liveRoomItemBean)
  119 + }
100 120
  121 +
  122 + }
  123 +
  124 + isHistoryMessage(optionType: string): boolean {
  125 + let isHistoryMessage = false
  126 + switch (optionType) {
  127 + case "ZH_TEXT_MSG":
  128 + case "ZH_IMAGE_MSG":
  129 + case "ZH_TEXT_AND_IMAGE_MSG":
  130 + case "ZH_AUDIO_MSG":
  131 + case "ZH_VIDEO_MSG": {
  132 + isHistoryMessage = true
  133 + } break;
  134 + default:
  135 + break;
  136 + }
  137 + return isHistoryMessage
  138 + }
101 } 139 }
@@ -163,7 +163,7 @@ export class LiveRoomManager { @@ -163,7 +163,7 @@ export class LiveRoomManager {
163 // }, 163 // },
164 // } 164 // }
165 IMEngine.getInstance().setChatroomStatusListener(this.connectedRoom); 165 IMEngine.getInstance().setChatroomStatusListener(this.connectedRoom);
166 - IMEngine.getInstance().setMessageReceivedListener(this.connectedRoom.onMessage); 166 + IMEngine.getInstance().setMessageReceivedListener(this.connectedRoom.onMessage.bind(this.connectedRoom));
167 if (this.onConnectedRoom) { 167 if (this.onConnectedRoom) {
168 this.onConnectedRoom(this.connectedRoom) 168 this.onConnectedRoom(this.connectedRoom)
169 } 169 }
@@ -83,7 +83,18 @@ export struct DetailPlayLivePage { @@ -83,7 +83,18 @@ export struct DetailPlayLivePage {
83 if(!await onlyWifiLoadVideo()){ 83 if(!await onlyWifiLoadVideo()){
84 this.showToastTip(this.toastText) 84 this.showToastTip(this.toastText)
85 } 85 }
86 - 86 + this.chatRoomController.onHistoryMessage = (liveRoomItemBean: LiveRoomItemBean) => {
  87 + if (liveRoomItemBean.messageRoom == "ZH_VIDEO") {
  88 + this.lastInputedLiveComment = liveRoomItemBean
  89 + } else if (liveRoomItemBean.messageRoom == "ZH_CHAT") {
  90 + this.lastInputedChatComment = liveRoomItemBean
  91 + }
  92 + }
  93 + this.chatRoomController.onLiveMessage = (liveRoomItemBean: LiveRoomItemBean) => {
  94 + if (liveRoomItemBean.optionType == "ZH_ROOM_NUMBER_MSG") {
  95 + this.liveRoomDataBean.pv = Number(liveRoomItemBean.pv)
  96 + }
  97 + }
87 this.chatRoomController.configDetail(this.contentDetailData) 98 this.chatRoomController.configDetail(this.contentDetailData)
88 } 99 }
89 100