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