import { getSDK, CbEvents } from '@openim/wasm-client-sdk';

let sdkInstance = null;
let cbEvents = null;
export function getOpenIM() {
  if (!sdkInstance) {
    sdkInstance = getSDK({ debug: true })
  }
  return sdkInstance
}
export const getCbEvents = () => {
  if (!cbEvents) {
    cbEvents = CbEvents;
  }
  return cbEvents;
};

// 设置全局监听（只需一次）
/*export const setupListeners = (store) => {
  if (isListenersSetup) return;

  const im = getOpenIM();

  im.on(CbEvents.OnConnectSuccess, () => {
    store.commit('im/setReadyState', true);
  });

  im.on(CbEvents.OnConnectFailed, (error) => {
    store.commit('im/setError', error.message);
    console.error('[OpenIM] 连接失败:', error);
  });

  // 其他必要的事件监听...
  isListenersSetup = true;
};*/
