DetailPlayLiveCommon.ets 6.5 KB
import { Action, ContentDetailDTO, GetPullAddressBean } from 'wdBean/Index';
import { LiveViewModel } from '../viewModel/LiveViewModel';
import router from '@ohos.router';

import { DetailPlayLivePage } from './DetailPlayLivePage';
import { DetailPlayVLivePage } from './DetailPlayVLivePage';
import { DateTimeUtils, Logger, ToastUtils, WindowModel } from 'wdKit/Index';
import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel';
import { PictureLoading } from '../widgets/vertical/PictureLoading';
import { TrackConstants, TrackingPageBrowse } from 'wdTracking/Index';
import { LiveDetailPageLogic } from '../viewModel/LiveDetailPageLogic';

const TAG = 'DetailPlayLiveCommon'

/**
 * 直播详情页
 * @Description: 沉浸式和非沉浸式直播页面
 * @Author:
 * @Email:
 * @CreateDate:
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Entry
@Component
export struct DetailPlayLiveCommon {
  private liveViewModel: LiveViewModel = new LiveViewModel()
  pageShowTime: number = 0;

  @Provide topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0
  @Provide bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0
  @Provide relId: string = ''
  @Provide contentId: string = ''
  @Provide relType: string = ''

  // 直播状态
  @Provide liveState: string = ''
  // 直播样式 0-正常模式,1-隐藏直播 2-隐藏大家聊
  @Provide liveStyle: number = -1
  // 直播地址
  @Provide playUrl: string = ''

  // 全屏展示
  @Provide pageShow: number = -1
  // 关闭全屏
  @Provide pageHide: number = -1
  // 返回功能
  @Provide pageBackPress: number = -1

  @Provide  liveDetailPageLogic :LiveDetailPageLogic = new LiveDetailPageLogic
  // 直播详情内容
  @Provide contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
  //发布评论 Model
  @Provide publishCommentModel: publishCommentModel = new publishCommentModel()

  // 埋点
  @Provide pageId: string = TrackConstants.PageName.Live_Detail
  @Provide pageName: string = TrackConstants.PageName.Live_Detail

   // 是否隐藏Loading view
  @State isHideLoading: boolean = false

  async aboutToAppear(): Promise<void> {
    const par: Action = router.getParams() as Action;
    const params = par?.params;
    this.relId = params?.extra?.relId || '';
    this.relType = params?.extra?.relType || '';
    this.contentId = params?.contentID || '';
    this.getContentDetail()

  }

  build() {
    Column() {
      // 直播预约或横屏直播统一进横屏直播
      if (this.liveDetailPageLogic.isLangScapeScreenVideo()) {
        // 非沉浸式直播
        DetailPlayLivePage({ contentId: this.contentId, relId: this.relId, relType: this.relType })
      } else if (this.liveDetailPageLogic.isVerticalScreenVideo()) {
        // 沉浸式直播
        DetailPlayVLivePage()
      } else {
        PictureLoading().visibility(this.isHideLoading ? Visibility.None : Visibility.Visible)
      }
    }
    .height('100%')
    .width('100%')
    .backgroundColor(Color.Black)
  //  .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  }

  /**
   * 查询视频详情用于评论展示
   */
  getContentDetail() {
    this.liveViewModel.getContentDetail(this.contentId, this.relId, this.relType)
      .then(async (data: Array<ContentDetailDTO>) => {
        console.log(TAG, '查询视频详情用于评论展示 getContentDetail:', JSON.stringify(data))
        if (data) {
          let detailData = data[0]
          //人民号类型单独获取直播地址
          if (detailData.rmhPlatform === 1 && detailData.liveInfo?.liveState === 'running') { //
            let vliveId = detailData.liveInfo.vlive[0].vliveId as string
            let pullStreamAddressData = await this.liveViewModel.getLiveRoomPullAddress(vliveId) as GetPullAddressBean
            if (pullStreamAddressData) {
              //  console.log(TAG, ' GetPullAddressBean:', JSON.stringify(pullStreamAddressData))
              let m3u8uUrl = pullStreamAddressData.transCode[0].m3u8Url
              detailData.liveInfo.vlive[0].liveUrl = m3u8uUrl
              this.playUrl = m3u8uUrl
            }
          }

          this.liveState = detailData.liveInfo?.liveState

          this.contentDetailData = data[0]

          this.liveDetailPageLogic.contentDetailData = this.contentDetailData

          this.liveDetailPageLogic.liveLandscape = detailData?.liveInfo?.liveLandScape

          this.liveDetailPageLogic.liveState = detailData.liveInfo?.liveState

          this.liveDetailPageLogic.resolvingRoomImgSource()

          this.liveDetailPageLogic.resolvingRoomVliveData(0)

          this.publishCommentModel.targetId = String(detailData?.newsId || '')
          this.publishCommentModel.targetRelId = String(detailData?.reLInfo?.relId || '')
          this.publishCommentModel.targetTitle = detailData?.newsTitle
          this.publishCommentModel.targetRelType = String(detailData?.reLInfo?.relType || '')
          this.publishCommentModel.targetRelObjectId = String(detailData?.reLInfo?.relObjectId || '')
          this.publishCommentModel.keyArticle = String(detailData?.keyArticle || '')
          this.publishCommentModel.targetType = String(detailData?.newsType || '')
          this.publishCommentModel.visitorComment = String(detailData?.visitorComment || '')
          this.publishCommentModel.commentContent = ''
          this.liveStyle = detailData.liveInfo?.liveStyle

          if (detailData.liveInfo.liveState == 'end') {
            this.playUrl = detailData.liveInfo.vlive[0].replayUri
          }

        } else {
          this.isHideLoading = true
          ToastUtils.shortToast('内容不存在')
          router.back()
        }
      }, () => {
        this.isHideLoading = true
        ToastUtils.shortToast('内容不存在')
        router.back()

      })
  }

  onPageShow() {
    this.pageShow = Math.random()
    Logger.info(TAG, 'onPageShow')
    this.pageShowTime = DateTimeUtils.getTimeStamp()
    WindowModel.shared.setWindowSystemBarProperties({ statusBarContentColor: '#ffffff'})
  }

  onPageHide() {
    WindowModel.shared.setWindowSystemBarProperties({ statusBarContentColor: '#000000'})
    this.pageHide = Math.random()
    Logger.info(TAG, 'onPageHide')
    //页面浏览
    TrackingPageBrowse.trackCommonPageExposureEnd(TrackConstants.PageName.Live_Detail,
      TrackConstants.PageName.Live_Detail
      , Math.floor((DateTimeUtils.getTimeStamp() - this.pageShowTime) / 1000))

  }

  onBackPress(): boolean | void {

    this.pageBackPress = Math.random()
    Logger.info(TAG, 'onBackPress')
    return true
  }
}