/* 移动端预览的时候 监听按键事件 传给学生端控制操作按钮 */
import { onMounted, onUnmounted } from "vue"

export const changeToggeMes = () => {
  function handleMessage(event: any) {
    const { api, playState } = event.data || {}
    if (api === "headerTogge") {
      window.parent.postMessage(
        {
          api: "headerTogge",
          playState: playState
        },
        "*"
      )
    } else if (api === "changeTogge") {
      window.parent.postMessage(
        {
          api: "changeTogge"
        },
        "*"
      )
    }
  }
  onMounted(() => {
    window.addEventListener("message", handleMessage)
  })
  onUnmounted(() => {
    window.removeEventListener("message", handleMessage)
  })
}
