import { defineComponent as n, openBlock as c, createElementBlock as i, createElementVNode as d, onMounted as w, onBeforeUnmount as S } from "vue";
const m = { class: "iframe-webscoket" }, f = ["src"], l = n({ name: "zv-scene-ue-shj" }), k = /* @__PURE__ */ n({
  ...l,
  props: {
    basicOption: {},
    sources: {},
    useEvents: {},
    uuid: {},
    isPreview: { type: Boolean }
  },
  emits: [
    "on-message"
  ],
  setup(t, { emit: r }) {
    const s = t, a = r;
    return ((o) => {
      w(() => {
        if (o.webSocketUrl)
          try {
            window.SHJSceneUEIframeWebscoket && (window.SHJSceneUEIframeWebscoket.close(), window.SHJSceneUEIframeWebscoket = null), window.SHJSceneUEIframeWebscoket = new WebSocket(o.webSocketUrl), window.SHJSceneUEIframeWebscoket.onmessage = (e) => {
              try {
                if (JSON.parse(e.data).type && JSON.parse(e.data).type === "ping")
                  return;
                if (!JSON.parse(e.data).data)
                  throw new Error("");
                a("on-message", JSON.parse(e.data).data), window.SHJParseEvent(s.useEvents, "on-message", JSON.parse(e.data).data);
              } catch {
              }
            }, window.SHJSceneUEIframeWebscoket.onopen = () => {
            }, window.SHJSceneUEIframeWebscoket.onerror = () => {
            };
          } catch {
          }
      }), S(() => {
        window.SHJSceneUEIframeWebscoket && window.SHJSceneUEIframeWebscoket.close();
      });
    })(s.basicOption), (o, e) => (c(), i("div", m, [
      d("iframe", {
        src: o.basicOption.iframeUrl,
        sandbox: "allow-scripts allow-same-origin",
        style: { width: "100%", height: "100%", border: "0" }
      }, null, 8, f)
    ]));
  }
});
export {
  k as default
};
