var videoController = {};
var videoController2;
var initVideo;

var optVideo;

var infoTables = [
  { point_idx: 'point1', coordinate: [114.210825, 38.255429], title: "单兵", data: { id: '0021', rw: '20',network:'5G' } },
  { point_idx: 'point2', coordinate: [114.202696, 38.250256], title: "单兵", data: { id: '0022', rw: '20',network:'4G' } },
];

var wzTables=[
  { wz_idx: 'wz1', coordinate: [114.219825, 38.255429], title: "物资", data: { type: '口罩', count: '20',date:'2022-02-01' } },
  { wz_idx: 'wz2', coordinate: [114.202696, 38.258256], title: "物资", data: { type: '防护服', count: '20',date:'2021-08-01' } },
];

var videos = [
  { video_idx: 'video1', coordinate: [114.218825, 38.254429], title: '金地城如家酒店' },
  { video_idx: 'video2', coordinate: [114.202696, 38.256256], title: '福美佳速8酒店' },
  { video_idx: 'video3', coordinate: [114.088219, 38.252942], title: '柏坡正元化肥' },
  { video_idx: 'video4', coordinate: [114.086916, 38.252128], title: '柏坡正元化肥' },
  { video_idx: 'video5', coordinate: [114.083278, 38.25186], title: '柏坡正元化肥' },
  { video_idx: 'video6', coordinate: [114.086153, 38.250428], title: '柏坡正元化肥' },
  { video_idx: 'video8', coordinate: [114.088119, 38.251842], title: '柏坡正元化肥' },
  { video_idx: 'video9', coordinate: [114.085816, 38.252228], title: '柏坡正元化肥' },
  { video_idx: 'video10', coordinate: [114.082378, 38.25286], title: '柏坡正元化肥' },
  { video_idx: 'video11', coordinate: [114.086253, 38.251328], title: '柏坡正元化肥' },
];

var video_ids = {
  video1: '5003',
  video2: '5002',
  video3: '5004',
  video4: '5005',
  video5: '5006',
  video6: '5007',
  video7: '5008',
  video8: '5009',
  video9: '5010',
  video10: '5011'
};

(function ($, $w) {
  //视频对象

  $(document).ready(function () {
    initView();

    // initVideo();
  });

  function videoListenEvent(ele) {
    var videoId;

    if (ele == 'video1' || ele == 'video2') {
      setTimeout(function () {
        videoController[ele].playByOrder(video_ids[ele], video_ids[ele], {
          name: video_ids[ele]
        });
        optVideo = videoController[ele];
      }, 3000);
    } else if (ele == 'video3' || ele == 'video4' || ele == 'video5' || ele == 'video6' || ele == 'video7' || ele == 'video8' || ele == 'video9' || ele == 'video10') {
      // //播放后的返回事件通知
      // videoController[ele].addListener('afterclose', function (e) { });

      // //分屏的返回事件通知
      // videoController[ele].addListener('screenchange', function (e) {
      //   $('.menu-screen>li').removeClass('on-sel');
      //   $('.menu-screen>li[mode=' + e.windowNums + ']').addClass('on-sel');
      // });
      setTimeout(function () {
        videoController[ele].playByOrder(video_ids[ele], video_ids[ele], {
          name: video_ids[ele]
        });
      }, 3000);
    }
  }

  initVideo = function (ele) {
    var url = videoPlatUrl + '/scooper-video/conf/data';
    var param = {};
    //从接口获取视频的参数信息
    $.getJSON(url, param, function (data) {
      //创建视频对象
      var conf = data;
      //参数
      var videoOpts = {
        //初始化时的界面显示的分屏树
        windows: 1,
        //共有哪几种分屏
        windowsArr: [1],
        //总的窗口数
        windowsNum: 1,
        conf: {
          user: conf['video.username'],
          passwd: conf['video.password'],
          //videoServer ip
          // ip: conf['video.ip'],
          ip: '27.128.189.131',
          //videoServer port
          port: conf['video.port'],
          //janus地址
          // janusUrl: conf['video.janus.url']
          janusUrl: 'ws://27.128.189.131:8188'
        },
        //码流类型，默认0
        streamType: conf['video.stream'],
        //是否截屏
        capImage: conf['video.cap.image'] === 'true',
        //截屏默认保存的地址
        videoCapImagePath: conf['video.cap.image.path']
      };
      //轮巡的时间，单位秒
      conf['video.poll.time'] &&
        (videoOpts.pollInterval = conf['video.poll.time']);
      var cla = '.' + ele;
      console.log($(cla));

      setTimeout(() => {
        videoController[ele] = new scooper.video($(cla), videoOpts);
        videoListenEvent(ele);
      }, 2000);
    });
  };
  function initView() {
    //分屏切换
    $('.menu-screen>li').click(function () {
      $('.menu-screen>li').removeClass('on-sel');
      var num = $(this)
        .addClass('on-sel')
        .attr('mode');

      videoController.setWindowsNum(num);
    });

    //播放
    $('.btn-play').click(function () {
      var video = $('.input-devid').val();
      if (!video) {
        promptView.showAlarm('请输入视频ID');
        return;
      }

      if (videoController.isPlaying(video) != -1) {
        promptView.showAlarm('该视频正在播放！');
        return;
      }

      videoController.playByOrder(video, video, { name: video });
    });

    //停止
    $('.btn-stop').click(function () {
      var videoObj = videoController.getInChoiceVideo();

      if (!videoObj) {
        promptView.showAlarm('请选择正在播放的视频窗口！');
        return;
      }

      var index = videoController.isPlaying(videoObj.id);
      videoController.close(index);
    });

    //一键关闭
    $('.btn-stop-all').click(function () {
      videoController.closeAll();
    });

    //参数配置
    // $(".p-config").click(function () {
    //     $(".dialog-config").show();
    // });
    //
    // $('.left-switch').click(function () {
    //     $('.part-left').toggleClass('hide')
    //     $('.part-right').toggleClass('hide')
    //     $(this).toggleClass('open')
    // })
  }
})(jQuery, window);
