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