init-client.js 1.52 KB
import Vue from 'vue';
import cookie from 'yoho-cookie';
import xianyu from '../common/xianyu';

const setWindowSize = (store) => {
  const { clientWidth, clientHeight } = document.body;

  store.commit('SET_WINDOW_SIZE', { clientWidth, clientHeight });
};

const initClient = (store) => {
  setWindowSize(store);
  window.onresize = () => {
    setWindowSize(store);
  };

  let supportsPassive = false;

  try {
    const opts = Object.defineProperty({}, 'passive', {
      get() {
        supportsPassive = true;
        return true;
      }
    });

    window.addEventListener('test', null, opts);
  } catch (e) { } //eslint-disable-line
  store.commit('SET_SUPPORT_PASSIVE', { supportsPassive });

  let img = new Image();

  img.onload = () => {
    if (img.width > 0 && img.height > 0) {
      store.commit('SET_SUPPORT_WEBP', { supportWebp: true });
    }
  };
  img.src = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';
};

function getUdid() {
  return cookie.get('udid') || '';
}

window.appBaseLogs = {
  status: [
    {
      ca: '',
      lo: '',
      cy: 'CN',
      av: '',
      udid: getUdid(),
      ln: '',
      ab: '',
      sid: '',
      net: '',
      la: ''
    }
  ],
  device: {
    res: '',
    ifa: '',
    mac: '',
    osv: '',
    ifv: '',
    ps: '',
    os: xianyu.isiOS ? 'iOS' : 'android',
    ak: 'yoho-xianyu_' + (xianyu.isiOS ? 'iOS' : 'android'),
    sv: '',
    ch: '',
    dm: '',
    tdid: '',
    afp: '',
    udid: getUdid()
  },
  events: [{}]
};

export {
  initClient
};