LiveDetailChatRoomController.ets 1.6 KB
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

    let roomInfo = new LiveRoomBaseInfo()
    roomInfo.roomID = detail.liveInfo.mlive.roomId
    roomInfo.mliveID = detail.liveInfo.mlive.mliveId
    roomInfo.liveID = detail.newsId + ""

    this.listenConnect()

    LiveRoomManager.sharedManager().connectLiveRoomWith(roomInfo)
  }

  listenConnect() {
    LiveRoomManager.sharedManager().onConnectedRoom = (room: LiveRoom) => {

      room.onJoined = (room: LiveRoom) => {

      }
      room.onJoinFailed = (room: LiveRoom, code: number) => {

      }
      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()
    }
  }
}