import { SHJDatasourceV2 as w } from "../index.mjs";
import { createWebSocketClient as x } from "../utils/websocket.mjs";
import { DataSourceUtils as n } from "../utils/utils.mjs";
const R = async (t, a, e) => {
  try {
    const {
      url: o,
      protocols: i,
      reconnect: s,
      reconnectInterval: d,
      maxReconnectAttempts: m,
      message: D,
      isMessage: p,
      headers: f,
      isHeaders: h,
      binaryType: y,
      timeout: S
    } = t.source.websocket;
    if (!o || o.trim() === "") {
      e(n.noneData(t.id));
      return;
    }
    await x(
      {
        uuid: t.id,
        url: o,
        protocols: i,
        reconnect: s,
        reconnectInterval: d,
        maxReconnectAttempts: m,
        message: D,
        isMessage: p,
        headers: f,
        isHeaders: h,
        binaryType: y,
        timeout: S
      },
      {
        onOpen: () => {
          e(n.noneData(t.id));
        },
        onError: (r) => {
          e(n.noneData(t.id));
        },
        onClose: () => {
          e(n.noneData(t.id));
        },
        onReconnect: () => {
          e(n.noneData(t.id));
        },
        onMessage: (r) => {
          w.processData(
            t.source,
            r,
            t.id,
            a
          ).then((g) => {
            e(g);
          }).catch(() => {
            e(n.noneData(t.id));
          });
        }
      }
    );
  } catch {
    e(n.noneData(t.id));
  }
};
export {
  R as parseWebSocketData
};
