<template>
  <div id="playWnd"></div>
</template>
<script>
let closeVideo=null
import {
  OpenVideo,
  unInitObjPlugin,
  InitObjPlugin, hidePluginWindow, showPluginWindow, resizeFn, isLoadPlugin, setWidthAndHeight, setOffset
} from "./video_isc_plugin.js";
export default {
  props: ["devList", "type", 'isIframe'],
  watch: {
    //监听value的变化，进行相应的操作即可
    devList: function (a, b) {
      console.log('isc_plugin.vue获取到设备列表')
      //a是value的新值，b是旧值
      if (a.length > 0) {
        isLoadPlugin(a, this.layout)
      } else {
        // unInitObjPlugin()
      }

      // a.forEach(element => {
      //     setTimeout(()=>{
      //         OpenVideo(element.serialNumber,1)
      //     },500)

      // });

    },
    isExpand: {
      immediate: true,
      handler: function (newval) {
        console.log('resizeFn')
        resizeFn()
      }
    },

  },
  computed: {
    isExpand() {
      return this.$store.state.isExpand;
    }
  },

  data() {
    return {
      layout: ''
    }
  },
  created() {
    if (COMPANY == 'xingxuan') { setWidthAndHeight(633, 381); }

    this.$EventBus.$on("controlVideoShowOrHide", (data) => {
      console.log('controlVideoShowOrHide', data)
      if (data == 'hide') {
        hidePluginWindow()
      } else {
        showPluginWindow()
      }
    });

  },
  mounted() {
    // if (COMPANY == 'xingxuan') {
    //  closeVideo= setInterval(()=>{
    //     window.onhashchange = function () {
    //      hidePluginWindow();
    //      clearTimeout(closeVideo);
    //   };
    //   },1000)
    // }

    var layout = '2x2'
    if (this.type == 'company') {
      // layout='6x10'
      layout = '4x6'
    }
    if (this.type.indexOf('x') != -1) {
      layout = this.type
    }
    this.layout = layout
    console.log('加载isc_plugin.vue')
    // console.log(this.type)
    // console.log('layout',layout)
    // InitObjPlugin(
    //       this.devList[0].appId,
    //       this.devList[0].appSecret,
    //       this.devList[0].account,
    //       this.devList[0].password,
    //       false,
    //       this.devList,layout
    // );
    if (this.devList.length > 0) {
      isLoadPlugin(this.devList, this.layout)
    }
  },
  beforeDestroy() {
    //反初始化
    unInitObjPlugin();
  },
  methods: {

  }
}
</script>
<style lang="scss" scoped>
#playWnd {
  width: 100%;
  height: 100%;
}
</style>