export const airport = {
  camera_index: '165-0-7',
  video_index: 'normal-0',
};
export const uav = {
  camera_index: '99-0-0',
  video_index: 'normal-0',
};
export const liveInfo = {
  rtmp: 'rtmp://box.wisestcity.com:1935/live/',
  url: 'http://box.wisestcity.com:8081/live/',
};
const hexList: string[] = [];
for (let i = 0; i <= 15; i++) {
  hexList[i] = i.toString(16);
}
export function buildGUID(): string {
  let guid = '';
  for (let i = 1; i <= 36; i++) {
    if (i === 9 || i === 14 || i === 19 || i === 24) {
      guid += '-';
    } else if (i === 15) {
      guid += 4;
    } else if (i === 20) {
      guid += hexList[(Math.random() * 4) | 8];
    } else {
      guid += hexList[(Math.random() * 16) | 0];
    }
  }
  return guid;
}

// 图片地址 转为 blob 、base64格式 imgUrl类型为字符串string
export function base64ByURL(imgUrl) {
  // 两大重点 Promise  XMLHttpRequest
  return new Promise((resolve) => {
    var xhr = new XMLHttpRequest();
    xhr.open('get', imgUrl, true);
    xhr.responseType = 'blob';
    xhr.onload = function () {
      if (this.status == 200) {
        let blob = this.response;
        let oFileReader = new FileReader();
        oFileReader.onloadend = function (e) {
          resolve({ blob, base64: e.target.result });
        };
        oFileReader.readAsDataURL(blob);
      }
    };
    xhr.send();
  });
}
