<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
      if (
        live.live_status === 2 &&
        live.enable_record === 1 &&
        live.record_url
      ) {
        // enable_record 0:不启用回放 1:开启回放
        // 查看回放
        return live.record_url
      } else {
        // 直播
        live.viewer_name = live.viewer_name || this.nickName
        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>
