// 注意,该示例的事件响应在login对象中

let count = 0;
async function sendDataToFlutter() {
  count += 1;

  const clickCountElement = document.getElementById("count");
  clickCountElement.textContent = count;

  let event = {type:0x0007, data:count};
  let data = await window.postMessage(event);
  console.log(data);

  let promise = window.postMessage(event);
  promise.then((v) => {
    console.log(v);
  });
}

// 异步接收数据通知
window.recvMessage = (data) => {
  console.log(data);
}

// 通知dart调用js函数callback
window.onload = () => {
  let eventobj = {type:0x000f, func: 'callback', param:{value:"test"}};
  window.postMessage(eventobj);

  let eventstr = {type:0x000f, func: 'callback', param:"test 123"};
  window.postMessage(eventstr);

  let eventnum = {type:0x000f, func: 'callback', param:666};
  window.postMessage(eventnum);
}

function callback(data) {
  console.log(data);
}

// 窗口大小
var show = {
  type: 0x000B,
  width: 800,
  height: 600,
};
window.postMessage(show);

// 窗口居中
var cent = {
  type: 0x000C,
};
window.postMessage(cent);
