<template>
  <div style="width:100%;height:100%;">
    <iframe
      :src="iframeUrl"
      frameborder="0"
      width="100%"
      height="100%"
      allow="autoplay;geolocation;microphone;camera;midi;encrypted-media;"
    ></iframe>
  </div>
</template>

<script>
// 章节视频
export default {
  name: 'ChapterLive',
  props: {
    // 当前选中的
    chapter: {
      type: Object,
      default() {
        return {}
      }
    },
    // 课程详情接口返回的数据
    data: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  computed: {
    user() {
      return window.G.UserInfo ? window.G.UserInfo.student_info : {}
    },
    nickName() {
      return this.user.personal_name || '匿名'
    },
    iframeUrl() {
      const live = this.chapter.live
      const liveStatus = live.live_status
      live.viewer_name = live.viewer_name || this.nickName
      if (liveStatus === 103 && live.enable_record === 1) {
        // enable_record 0:不启用回放 1:开启回放
        // 查看回放
        return `https://view.csslcloud.net/api/view/callback?recordid=${live.record_id}&roomid=${live.room_id}&userid=${live.user_id}&autoLogin=true&viewername=${live.viewer_name}&viewertoken=${live.viewer_token}`
      } else {
        // 直播
        return `https://view.csslcloud.net/api/view/index?roomid=${live.room_id}&userid=${live.user_id}&autoLogin=true&viewername=${live.viewer_name}&viewertoken=${live.viewer_token}`
      }
    }
  }
}
</script>
