<template>
  <div class="qingliu">
    <div ref="player_area"></div>
  </div>
</template>

<script>
import {
  dataURLToBlob,
  canvasToDataURL,
} from "../../../../../../../../../../../../utils/image-tool";

export default {
  name: "QingLiuPlayer",
  props: {
    url: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      name: "QingLiuPlayer" + Date.now(),
    };
  },
  created() {},
  mounted() {
    this.init();
  },
  beforeDestroy() {
    window.kbt_player_destroy(this.name);
  },
  methods: {
    /**
     * 初始化
     */
    init() {
      window.kbt_sdk_load().then(() => {
        let parentObj = this.$refs.player_area;
        window.kbt_player_create(this.name, this.url, 970, 545, parentObj);
      });
    },
    screenShot() {
      var canvas = document.querySelector("#sdk_canvas_" + this.name);
      const image = canvasToDataURL(canvas);
      let blob = dataURLToBlob(image);
      return blob;
    },
    fullScreen() {
      // var canvas = document.querySelector("#sdk_canvas_" + this.name);
      var canvas = this.$refs.player_area.querySelector("canvas");
      canvas && canvas.requestFullscreen();
    },
  },
};
</script>

<style scoped lang='scss'>
.qingliu::v-deep {
  width: 100%;
  height: 100%;
  > div {
    width: 100%;
    height: 100%;
  }
  .player_area {
    width: 100%;
    height: 100%;
  }
  .cf {
    position: fixed;
    top: 0;
    left: 0;
    padding: 10px;
    color: #fff;
    background: rgba($color: #000000, $alpha: 0.6);
  }
  canvas {
    width: 100%;
    height: 100%;
  }
}
</style>