// The reason for this strange abstraction is because we can't rely on
// nested worker support (Safari doesn't support it). We need to proxy
// creating a child worker through the main thread, and this requires
// a bit of glue code. We don't want to duplicate this code in each
// backend that needs it, so this module abstracts it out. It has to
// have a strange shape because we don't want to eagerly bundle the
// backend code, so users of this code need to pass an `() =>
// import('./worker.js')` expression to get the worker module to run.

function isWorker() {
  return (
    typeof WorkerGlobalScope !== 'undefined' &&
    self instanceof WorkerGlobalScope
  );
}

function makeStartWorkerFromMain(getModule) {
  return (argBuffer, resultBuffer, parentWorker) => {
    if (isWorker()) {
      throw new Error(
        '`startWorkerFromMain` should only be called from the main thread'
      );
    }

    if (typeof Worker === 'undefined') {
      // We're on the main thread? Weird: it doesn't have workers
      throw new Error(
        'Web workers not available. sqlite3 requires web workers to work.'
      );
    }

    getModule().then(({ default: BackendWorker }) => {
      let worker = new BackendWorker();

      worker.postMessage({ type: 'init', buffers: [argBuffer, resultBuffer] });

      worker.addEventListener('message', msg => {
        // Forward any messages to the worker that's supposed
        // to be the parent
        parentWorker.postMessage(msg.data);
      });
    });
  };
}

function makeInitBackend(spawnEventName, getModule) {
  const startWorkerFromMain = makeStartWorkerFromMain(getModule);

  return worker => {
    worker.addEventListener('message', e => {
      switch (e.data.type) {
        case spawnEventName:
          startWorkerFromMain(e.data.argBuffer, e.data.resultBuffer, worker);
          break;
      }
    });
  };
}

// Use the generic main thread module to create our indexeddb worker
// proxy
const initBackend = makeInitBackend('__absurd:spawn-idb-worker', () =>
  Promise.resolve().then(function () { return indexeddbMainThreadWorkerB24e7a21; })
);

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};
const RPCCodes = {
  CONNECT_TIMEOUT: {
    code: -32300,
    message: "Connect timeout"
  },
  APPLICATION_ERROR: {
    code: -32500,
    message: "Application error"
  },
  METHOD_NOT_FOUND: {
    code: -32601,
    message: `Method not found`
  }
};
class RPCMessageEvent {
  constructor(options) {
    __publicField(this, "_currentEndpoint");
    __publicField(this, "_targetEndpoint");
    __publicField(this, "_events");
    __publicField(this, "_originOnmessage");
    __publicField(this, "_receiveMessage");
    __publicField(this, "onerror", null);
    __publicField(this, "config");
    __publicField(this, "sendAdapter");
    __publicField(this, "receiveAdapter");
    this._events = {};
    this._currentEndpoint = options.currentEndpoint;
    this._targetEndpoint = options.targetEndpoint;
    this._originOnmessage = null;
    this.config = options.config;
    this.receiveAdapter = options.receiveAdapter;
    this.sendAdapter = options.sendAdapter;
    const receiveMessage = (event) => {
      const receiveData = this.receiveAdapter ? this.receiveAdapter(event) : event.data;
      if (receiveData && typeof receiveData.event === "string") {
        const eventHandlers = this._events[receiveData.event] || [];
        if (eventHandlers.length) {
          eventHandlers.forEach((handler) => {
            handler(...receiveData.args || []);
          });
          return;
        }
        if (this.onerror) {
          this.onerror(__spreadProps(__spreadValues({}, RPCCodes.METHOD_NOT_FOUND), {
            data: receiveData
          }));
        }
      }
    };
    if (this._currentEndpoint.addEventListener) {
      if ("start" in this._currentEndpoint && this._currentEndpoint.start) {
        this._currentEndpoint.start();
      }
      this._currentEndpoint.addEventListener("message", receiveMessage, false);
      this._receiveMessage = receiveMessage;
      return;
    }
    this._originOnmessage = this._currentEndpoint.onmessage;
    this._currentEndpoint.onmessage = (event) => {
      if (this._originOnmessage) {
        this._originOnmessage(event);
      }
      receiveMessage(event);
    };
    this._receiveMessage = this._currentEndpoint.onmessage;
  }
  emit(event, ...args) {
    const data = {
      event,
      args
    };
    const result = this.sendAdapter ? this.sendAdapter(data, this._targetEndpoint) : { data };
    const sendData = result.data || data;
    const postMessageConfig = this.config ? typeof this.config === "function" ? this.config(sendData, this._targetEndpoint) || {} : this.config || {} : {};
    if (Array.isArray(result.transfer) && result.transfer.length) {
      postMessageConfig.transfer = result.transfer;
    }
    this._targetEndpoint.postMessage(sendData, postMessageConfig);
  }
  on(event, fn) {
    if (!this._events[event]) {
      this._events[event] = [];
    }
    this._events[event].push(fn);
  }
  off(event, fn) {
    if (!this._events[event])
      return;
    if (!fn) {
      this._events[event] = [];
      return;
    }
    const handlers = this._events[event] || [];
    this._events[event] = handlers.filter((handler) => handler !== fn);
  }
  destroy() {
    if (this._currentEndpoint.removeEventListener) {
      this._currentEndpoint.removeEventListener("message", this._receiveMessage, false);
      return;
    }
    try {
      this._currentEndpoint.onmessage = this._originOnmessage;
    } catch (error) {
      console.warn(error);
    }
  }
}
const _RPC = class {
  constructor(options) {
    __publicField(this, "_event");
    __publicField(this, "_methods", {});
    __publicField(this, "_timeout", 0);
    __publicField(this, "_$connect", null);
    this._event = options.event;
    this._timeout = options.timeout || 0;
    if (options.methods) {
      Object.entries(options.methods).forEach(([method, handler]) => {
        this.registerMethod(method, handler);
      });
    }
    this._event.onerror = (error) => {
      const { code, message, data } = error;
      if (data.event && Array.isArray(data.args) && data.args.length) {
        const synEventData = data.args[0];
        const ackEventName = this._getAckEventName(synEventData.method);
        const ackEventData = {
          jsonrpc: "2.0",
          id: synEventData == null ? void 0 : synEventData.id,
          error: {
            code,
            message,
            data: synEventData
          }
        };
        this._event.emit(ackEventName, ackEventData);
      } else {
        console.error(error);
      }
    };
    this.connect();
  }
  static uuid() {
    return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
      const r = Math.random() * 16 | 0;
      const v = c == "x" ? r : r & 3 | 8;
      return v.toString(16);
    });
  }
  _getSynEventName(method) {
    return `${_RPC.EVENT.SYN_SIGN}${method}`;
  }
  _getAckEventName(method) {
    return `${_RPC.EVENT.ACK_SIGN}${method}`;
  }
  connect(timeout) {
    if (this._$connect) {
      return this._$connect;
    }
    this._$connect = new Promise((resolve, reject) => {
      const connectTimeout = timeout || this._timeout;
      let connectTimer;
      if (connectTimeout) {
        connectTimer = setTimeout(() => {
          const error = __spreadProps(__spreadValues({}, RPCCodes.TIMEOUT), {
            data: { timeout: connectTimeout }
          });
          reject(error);
        }, connectTimeout);
      }
      const connectEventName = _RPC.EVENT.CONNECT;
      const connectAckEventName = this._getAckEventName(connectEventName);
      const connectSynEventName = this._getSynEventName(connectEventName);
      const resolveConnectEvent = () => {
        clearTimeout(connectTimer);
        resolve();
      };
      this._event.on(connectAckEventName, resolveConnectEvent);
      const connectSynEventHandler = () => {
        this._event.emit(connectAckEventName);
        resolveConnectEvent();
      };
      this._event.on(connectSynEventName, connectSynEventHandler);
      this._event.emit(connectSynEventName);
    });
    return this._$connect;
  }
  registerMethod(method, handler) {
    if (this._methods[method]) {
      throw new Error(`${method} already registered`);
    }
    this._methods[method] = handler;
    const synEventName = this._getSynEventName(method);
    const synEventHandler = (synEventData) => {
      const ackEventName = this._getAckEventName(method);
      if (!synEventData.id) {
        handler(...synEventData.params);
        return;
      }
      Promise.resolve(handler(...synEventData.params)).then((result) => {
        const ackEventData = {
          jsonrpc: "2.0",
          result,
          id: synEventData.id
        };
        this._event.emit(ackEventName, ackEventData);
      }).catch((error) => {
        const ackEventData = {
          jsonrpc: "2.0",
          id: synEventData.id,
          error: {
            code: (error == null ? void 0 : error.code) || RPCCodes.APPLICATION_ERROR.code,
            message: (error == null ? void 0 : error.message) || RPCCodes.APPLICATION_ERROR.message,
            data: null
          }
        };
        this._event.emit(ackEventName, ackEventData);
      });
    };
    this._event.on(synEventName, synEventHandler);
  }
  removeMethod(method) {
    if (!this._methods[method]) {
      delete this._methods[method];
    }
    const synEventName = this._getSynEventName(method);
    this._event.off(synEventName);
  }
  invoke(method, ...args) {
    return new Promise((resolve, reject) => {
      const lastArg = args[args.length - 1];
      const hasInvokeOptions = lastArg && typeof lastArg === "object" && (Reflect.has(lastArg, "isNotify") || Reflect.has(lastArg, "timeout"));
      const options = hasInvokeOptions ? lastArg : { isNotify: false, timeout: 0 };
      const params = hasInvokeOptions ? args.slice(0, -1) : args;
      const synEventName = this._getSynEventName(method);
      const synEventId = _RPC.uuid();
      const synEventData = {
        jsonrpc: "2.0",
        method,
        params,
        id: synEventId
      };
      this._event.emit(synEventName, synEventData);
      if (!options.isNotify) {
        const ackEventName = this._getAckEventName(method);
        const timeout = options.timeout || this._timeout;
        let timer;
        if (timeout) {
          timer = setTimeout(() => {
            const error = __spreadProps(__spreadValues({}, RPCCodes.CONNECT_TIMEOUT), {
              data: { timeout }
            });
            reject(error);
          }, timeout);
        }
        const ackEventHandler = (ackEventData) => {
          if (ackEventData.id === synEventId) {
            clearTimeout(timer);
            this._event.off(ackEventName, ackEventHandler);
            if (!ackEventData.error) {
              resolve(ackEventData.result);
            } else {
              reject(ackEventData.error);
            }
          }
        };
        this._event.on(ackEventName, ackEventHandler);
      } else {
        resolve(void 0);
      }
    });
  }
  destroy() {
    Object.entries(this._methods).forEach(([method]) => {
      const synEventName = this._getSynEventName(method);
      this._event.off(synEventName);
    });
    const connectAckEventName = this._getAckEventName(_RPC.EVENT.CONNECT);
    const connectSynEventName = this._getSynEventName(_RPC.EVENT.CONNECT);
    this._event.off(connectSynEventName);
    this._event.off(connectAckEventName);
    if (this._event.destroy) {
      this._event.destroy();
    }
  }
};
let RPC = _RPC;
__publicField(RPC, "CODES", RPCCodes);
__publicField(RPC, "EVENT", {
  SYN_SIGN: "syn:",
  ACK_SIGN: "ack:",
  CONNECT: "__rpc_connect_event",
  SYNC_METHODS: "__rpc_sync_methods_event"
});

const DatabaseErrorCode = {
    ErrorInit: 10001,
    ErrorNoRecord: 10002,
    ErrorDBTimeout: 10003,
};
var CbEvents;
(function (CbEvents) {
    CbEvents["Login"] = "Login";
    CbEvents["OnConnectFailed"] = "OnConnectFailed";
    CbEvents["OnConnectSuccess"] = "OnConnectSuccess";
    CbEvents["OnConnecting"] = "OnConnecting";
    CbEvents["OnKickedOffline"] = "OnKickedOffline";
    CbEvents["OnSelfInfoUpdated"] = "OnSelfInfoUpdated";
    CbEvents["OnUserTokenExpired"] = "OnUserTokenExpired";
    CbEvents["OnUserTokenInvalid"] = "OnUserTokenInvalid";
    CbEvents["OnProgress"] = "OnProgress";
    CbEvents["OnRecvNewMessage"] = "OnRecvNewMessage";
    CbEvents["OnRecvNewMessages"] = "OnRecvNewMessages";
    CbEvents["OnRecvOfflineNewMessage"] = "onRecvOfflineNewMessage";
    CbEvents["OnRecvOfflineNewMessages"] = "onRecvOfflineNewMessages";
    CbEvents["OnRecvMessageRevoked"] = "OnRecvMessageRevoked";
    CbEvents["OnNewRecvMessageRevoked"] = "OnNewRecvMessageRevoked";
    CbEvents["OnRecvC2CReadReceipt"] = "OnRecvC2CReadReceipt";
    CbEvents["OnRecvGroupReadReceipt"] = "OnRecvGroupReadReceipt";
    CbEvents["OnConversationChanged"] = "OnConversationChanged";
    CbEvents["OnNewConversation"] = "OnNewConversation";
    CbEvents["OnSyncServerFailed"] = "OnSyncServerFailed";
    CbEvents["OnSyncServerFinish"] = "OnSyncServerFinish";
    CbEvents["OnSyncServerProgress"] = "OnSyncServerProgress";
    CbEvents["OnSyncServerStart"] = "OnSyncServerStart";
    CbEvents["OnTotalUnreadMessageCountChanged"] = "OnTotalUnreadMessageCountChanged";
    CbEvents["OnBlackAdded"] = "OnBlackAdded";
    CbEvents["OnBlackDeleted"] = "OnBlackDeleted";
    CbEvents["OnFriendApplicationAccepted"] = "OnFriendApplicationAccepted";
    CbEvents["OnFriendApplicationAdded"] = "OnFriendApplicationAdded";
    CbEvents["OnFriendApplicationDeleted"] = "OnFriendApplicationDeleted";
    CbEvents["OnFriendApplicationRejected"] = "OnFriendApplicationRejected";
    CbEvents["OnFriendInfoChanged"] = "OnFriendInfoChanged";
    CbEvents["OnFriendAdded"] = "OnFriendAdded";
    CbEvents["OnFriendDeleted"] = "OnFriendDeleted";
    CbEvents["OnJoinedGroupAdded"] = "OnJoinedGroupAdded";
    CbEvents["OnJoinedGroupDeleted"] = "OnJoinedGroupDeleted";
    CbEvents["OnGroupDismissed"] = "OnGroupDismissed";
    CbEvents["OnGroupMemberAdded"] = "OnGroupMemberAdded";
    CbEvents["OnGroupMemberDeleted"] = "OnGroupMemberDeleted";
    CbEvents["OnGroupApplicationAdded"] = "OnGroupApplicationAdded";
    CbEvents["OnGroupApplicationDeleted"] = "OnGroupApplicationDeleted";
    CbEvents["OnGroupInfoChanged"] = "OnGroupInfoChanged";
    CbEvents["OnGroupMemberInfoChanged"] = "OnGroupMemberInfoChanged";
    CbEvents["OnGroupApplicationAccepted"] = "OnGroupApplicationAccepted";
    CbEvents["OnGroupApplicationRejected"] = "OnGroupApplicationRejected";
    CbEvents["UploadComplete"] = "UploadComplete";
    CbEvents["OnRecvCustomBusinessMessage"] = "OnRecvCustomBusinessMessage";
    CbEvents["OnUserStatusChanged"] = "OnUserStatusChanged";
    CbEvents["OnUploadLogsProgress"] = "OnUploadLogsProgress";
    // rtc
    CbEvents["OnReceiveNewInvitation"] = "OnReceiveNewInvitation";
    CbEvents["OnInviteeAccepted"] = "OnInviteeAccepted";
    CbEvents["OnInviteeRejected"] = "OnInviteeRejected";
    CbEvents["OnInvitationCancelled"] = "OnInvitationCancelled";
    CbEvents["OnHangUp"] = "OnHangUp";
    CbEvents["OnInvitationTimeout"] = "OnInvitationTimeout";
    CbEvents["OnInviteeAcceptedByOtherDevice"] = "OnInviteeAcceptedByOtherDevice";
    CbEvents["OnInviteeRejectedByOtherDevice"] = "OnInviteeRejectedByOtherDevice";
    // meeting
    CbEvents["OnStreamChange"] = "OnStreamChange";
    CbEvents["OnRoomParticipantConnected"] = "OnRoomParticipantConnected";
    CbEvents["OnRoomParticipantDisconnected"] = "OnRoomParticipantDisconnected";
    CbEvents["OnReceiveCustomSignal"] = "OnReceiveCustomSignal";
    // unuse
    CbEvents["UnUsedEvent"] = "UnUsedEvent";
})(CbEvents || (CbEvents = {}));

let rpc;
let worker;
let debug = false;
function supportsModuleWorkers() {
    if (typeof Worker !== 'undefined' && 'type' in Worker.prototype) {
        return true;
    }
    try {
        const blob = new Blob([''], { type: 'text/javascript' });
        const url = URL.createObjectURL(blob);
        new Worker(url, { type: 'module' });
        URL.revokeObjectURL(url);
        return true;
    }
    catch (e) {
        return false;
    }
}
function initWorker() {
    if (typeof window === 'undefined') {
        return;
    }
    // use for webpack 4
    // const IMWorker = require('worker-loader!./worker.js');
    // worker = new IMWorker.default();
    // use for webpack5+ or vite
    const isViteEnvironment = import.meta.url.includes('.vite/deps');
    const isNuxtEnvironment = import.meta.url.includes('_nuxt/node_modules');
    const isSupportModuleWorker = supportsModuleWorkers();
    let workerUrl = isSupportModuleWorker
        ? new URL('worker.js', import.meta.url)
        : new URL('worker-legacy.js', import.meta.url);
    if (isViteEnvironment) {
        workerUrl = workerUrl.href.replace('.vite/deps', 'open-im-sdk-wasm/lib');
    }
    if (isNuxtEnvironment) {
        workerUrl = workerUrl.href.replace('.cache/vite/client/deps', 'open-im-sdk-wasm/lib');
    }
    worker = new Worker(workerUrl, {
        type: isSupportModuleWorker ? 'module' : 'classic',
    });
    // This is only required because Safari doesn't support nested
    // workers. This installs a handler that will proxy creating web
    // workers through the main thread
    initBackend(worker);
    rpc = new RPC({
        event: new RPCMessageEvent({
            currentEndpoint: worker,
            targetEndpoint: worker,
        }),
    });
}
function resetWorker() {
    if (rpc) {
        rpc.destroy();
        rpc = undefined;
    }
    if (worker) {
        worker.terminate();
        worker = undefined;
    }
}
initWorker();
function catchErrorHandle(error) {
    // defined in rpc-shooter
    if (error.code === -32300) {
        resetWorker();
        return JSON.stringify({
            data: '',
            errCode: DatabaseErrorCode.ErrorDBTimeout,
            errMsg: 'database maybe damaged',
        });
    }
    throw error;
}
function _logWrap(...args) {
    if (debug) {
        console.info(...args);
    }
}
function registeMethodOnWindow(name, realName, needStringify = true) {
    _logWrap(`=> (database api) registe ${realName !== null && realName !== void 0 ? realName : name}`);
    return async (...args) => {
        if (!rpc || !worker) {
            initWorker();
        }
        if (!rpc) {
            return;
        }
        try {
            _logWrap(`=> (invoked by go wasm) run ${realName !== null && realName !== void 0 ? realName : name} method with args ${JSON.stringify(args)}`);
            const response = await rpc.invoke(name, ...args, { timeout: 5000000 });
            _logWrap(`=> (invoked by go wasm) run ${realName !== null && realName !== void 0 ? realName : name} method with response `, JSON.stringify(response));
            if (!needStringify) {
                return response;
            }
            return JSON.stringify(response);
        }
        catch (error) {
            // defined in rpc-shooter
            catchErrorHandle(error);
        }
    };
}
// register method on window for go wasm invoke
function initDatabaseAPI(isLogStandardOutput = true) {
    if (!rpc) {
        return;
    }
    debug = isLogStandardOutput;
    // upload
    window.wasmOpen = registeMethodOnWindow('wasmOpen');
    window.wasmClose = registeMethodOnWindow('wasmClose');
    window.wasmRead = registeMethodOnWindow('wasmRead', 'wasmRead', false);
    window.getUpload = registeMethodOnWindow('getUpload');
    window.insertUpload = registeMethodOnWindow('insertUpload');
    window.updateUpload = registeMethodOnWindow('updateUpload');
    window.deleteUpload = registeMethodOnWindow('deleteUpload');
    window.fileMapSet = registeMethodOnWindow('fileMapSet');
    window.fileMapClear = registeMethodOnWindow('fileMapClear');
    window.setSqlWasmPath = registeMethodOnWindow('setSqlWasmPath');
    window.initDB = registeMethodOnWindow('initDB');
    window.close = registeMethodOnWindow('close');
    // message
    window.getMessage = registeMethodOnWindow('getMessage');
    window.getMultipleMessage = registeMethodOnWindow('getMultipleMessage');
    window.getSendingMessageList = registeMethodOnWindow('getSendingMessageList');
    window.getNormalMsgSeq = registeMethodOnWindow('getNormalMsgSeq');
    window.updateMessageTimeAndStatus = registeMethodOnWindow('updateMessageTimeAndStatus');
    window.updateMessage = registeMethodOnWindow('updateMessage');
    window.updateMessageBySeq = registeMethodOnWindow('updateMessageBySeq');
    window.updateColumnsMessage = registeMethodOnWindow('updateColumnsMessage');
    window.insertMessage = registeMethodOnWindow('insertMessage');
    window.batchInsertMessageList = registeMethodOnWindow('batchInsertMessageList');
    window.getMessageList = registeMethodOnWindow('getMessageList');
    window.getMessageListNoTime = registeMethodOnWindow('getMessageListNoTime');
    window.messageIfExists = registeMethodOnWindow('messageIfExists');
    window.messageIfExistsBySeq = registeMethodOnWindow('messageIfExistsBySeq');
    window.getAbnormalMsgSeq = registeMethodOnWindow('getAbnormalMsgSeq');
    window.getAbnormalMsgSeqList = registeMethodOnWindow('getAbnormalMsgSeqList');
    window.batchInsertExceptionMsg = registeMethodOnWindow('batchInsertExceptionMsg');
    window.searchMessageByKeyword = registeMethodOnWindow('searchMessageByKeyword');
    window.searchMessageByContentType = registeMethodOnWindow('searchMessageByContentType');
    window.searchMessageByContentTypeAndKeyword = registeMethodOnWindow('searchMessageByContentTypeAndKeyword');
    window.updateMsgSenderNickname = registeMethodOnWindow('updateMsgSenderNickname');
    window.updateMsgSenderFaceURL = registeMethodOnWindow('updateMsgSenderFaceURL');
    window.updateMsgSenderFaceURLAndSenderNickname = registeMethodOnWindow('updateMsgSenderFaceURLAndSenderNickname');
    window.getMsgSeqByClientMsgID = registeMethodOnWindow('getMsgSeqByClientMsgID');
    window.getMsgSeqListByGroupID = registeMethodOnWindow('getMsgSeqListByGroupID');
    window.getMsgSeqListByPeerUserID = registeMethodOnWindow('getMsgSeqListByPeerUserID');
    window.getMsgSeqListBySelfUserID = registeMethodOnWindow('getMsgSeqListBySelfUserID');
    window.deleteAllMessage = registeMethodOnWindow('deleteAllMessage');
    window.getAllUnDeleteMessageSeqList = registeMethodOnWindow('getAllUnDeleteMessageSeqList');
    window.updateSingleMessageHasRead = registeMethodOnWindow('updateSingleMessageHasRead');
    window.updateGroupMessageHasRead = registeMethodOnWindow('updateGroupMessageHasRead');
    window.updateMessageStatusBySourceID = registeMethodOnWindow('updateMessageStatusBySourceID');
    window.getAlreadyExistSeqList = registeMethodOnWindow('getAlreadyExistSeqList');
    window.getMessageBySeq = registeMethodOnWindow('getMessageBySeq');
    window.getMessagesByClientMsgIDs = registeMethodOnWindow('getMessagesByClientMsgIDs');
    window.getMessagesBySeqs = registeMethodOnWindow('getMessagesBySeqs');
    window.getConversationNormalMsgSeq = registeMethodOnWindow('getConversationNormalMsgSeq');
    window.checkConversationNormalMsgSeq = registeMethodOnWindow('getConversationNormalMsgSeq');
    window.getConversationPeerNormalMsgSeq = registeMethodOnWindow('getConversationPeerNormalMsgSeq');
    window.deleteConversationAllMessages = registeMethodOnWindow('deleteConversationAllMessages');
    window.markDeleteConversationAllMessages = registeMethodOnWindow('markDeleteConversationAllMessages');
    window.getUnreadMessage = registeMethodOnWindow('getUnreadMessage');
    window.markConversationMessageAsReadBySeqs = registeMethodOnWindow('markConversationMessageAsReadBySeqs');
    window.markConversationMessageAsReadDB = registeMethodOnWindow('markConversationMessageAsRead');
    window.deleteConversationMsgs = registeMethodOnWindow('deleteConversationMsgs');
    window.markConversationAllMessageAsRead = registeMethodOnWindow('markConversationAllMessageAsRead');
    window.searchAllMessageByContentType = registeMethodOnWindow('searchAllMessageByContentType');
    window.insertSendingMessage = registeMethodOnWindow('insertSendingMessage');
    window.deleteSendingMessage = registeMethodOnWindow('deleteSendingMessage');
    window.getAllSendingMessages = registeMethodOnWindow('getAllSendingMessages');
    // conversation
    window.getAllConversationListDB = registeMethodOnWindow('getAllConversationList');
    window.getAllConversationListToSync = registeMethodOnWindow('getAllConversationListToSync');
    window.getHiddenConversationList = registeMethodOnWindow('getHiddenConversationList');
    window.getConversation = registeMethodOnWindow('getConversation');
    window.getMultipleConversationDB = registeMethodOnWindow('getMultipleConversation');
    window.updateColumnsConversation = registeMethodOnWindow('updateColumnsConversation');
    window.updateConversation = registeMethodOnWindow('updateColumnsConversation', 'updateConversation');
    window.updateConversationForSync = registeMethodOnWindow('updateColumnsConversation', 'updateConversationForSync');
    window.decrConversationUnreadCount = registeMethodOnWindow('decrConversationUnreadCount');
    window.batchInsertConversationList = registeMethodOnWindow('batchInsertConversationList');
    window.insertConversation = registeMethodOnWindow('insertConversation');
    window.getTotalUnreadMsgCountDB = registeMethodOnWindow('getTotalUnreadMsgCount');
    window.getConversationByUserID = registeMethodOnWindow('getConversationByUserID');
    window.getConversationListSplitDB = registeMethodOnWindow('getConversationListSplit');
    window.deleteConversation = registeMethodOnWindow('deleteConversation');
    window.deleteAllConversation = registeMethodOnWindow('deleteAllConversation');
    window.batchUpdateConversationList = registeMethodOnWindow('batchUpdateConversationList');
    window.conversationIfExists = registeMethodOnWindow('conversationIfExists');
    window.resetConversation = registeMethodOnWindow('resetConversation');
    window.resetAllConversation = registeMethodOnWindow('resetAllConversation');
    window.clearConversation = registeMethodOnWindow('clearConversation');
    window.clearAllConversation = registeMethodOnWindow('clearAllConversation');
    window.setConversationDraftDB = registeMethodOnWindow('setConversationDraft');
    window.removeConversationDraft = registeMethodOnWindow('removeConversationDraft');
    window.unPinConversation = registeMethodOnWindow('unPinConversation');
    // window.updateAllConversation = registeMethodOnWindow('updateAllConversation');
    window.incrConversationUnreadCount = registeMethodOnWindow('incrConversationUnreadCount');
    window.setMultipleConversationRecvMsgOpt = registeMethodOnWindow('setMultipleConversationRecvMsgOpt');
    window.getAllSingleConversationIDList = registeMethodOnWindow('getAllSingleConversationIDList');
    window.getAllConversationIDList = registeMethodOnWindow('getAllConversationIDList');
    window.getAllConversations = registeMethodOnWindow('getAllConversations');
    window.searchConversations = registeMethodOnWindow('searchConversations');
    // users
    window.getLoginUser = registeMethodOnWindow('getLoginUser');
    window.insertLoginUser = registeMethodOnWindow('insertLoginUser');
    window.updateLoginUser = registeMethodOnWindow('updateLoginUser');
    window.getStrangerInfo = registeMethodOnWindow('getStrangerInfo');
    window.setStrangerInfo = registeMethodOnWindow('setStrangerInfo');
    // app sdk versions
    window.getAppSDKVersion = registeMethodOnWindow('getAppSDKVersion');
    window.setAppSDKVersion = registeMethodOnWindow('setAppSDKVersion');
    // versions sync
    window.getVersionSync = registeMethodOnWindow('getVersionSync');
    window.setVersionSync = registeMethodOnWindow('setVersionSync');
    window.deleteVersionSync = registeMethodOnWindow('deleteVersionSync');
    // super groups
    window.getJoinedSuperGroupList = registeMethodOnWindow('getJoinedSuperGroupList');
    window.getJoinedSuperGroupIDList = registeMethodOnWindow('getJoinedSuperGroupIDList');
    window.getSuperGroupInfoByGroupID = registeMethodOnWindow('getSuperGroupInfoByGroupID');
    window.deleteSuperGroup = registeMethodOnWindow('deleteSuperGroup');
    window.insertSuperGroup = registeMethodOnWindow('insertSuperGroup');
    window.updateSuperGroup = registeMethodOnWindow('updateSuperGroup');
    // unread messages
    window.deleteConversationUnreadMessageList = registeMethodOnWindow('deleteConversationUnreadMessageList');
    window.batchInsertConversationUnreadMessageList = registeMethodOnWindow('batchInsertConversationUnreadMessageList');
    // super group messages
    window.superGroupGetMessage = registeMethodOnWindow('superGroupGetMessage');
    window.superGroupGetMultipleMessage = registeMethodOnWindow('superGroupGetMultipleMessage');
    window.superGroupGetNormalMinSeq = registeMethodOnWindow('superGroupGetNormalMinSeq');
    window.getSuperGroupNormalMsgSeq = registeMethodOnWindow('getSuperGroupNormalMsgSeq');
    window.superGroupUpdateMessageTimeAndStatus = registeMethodOnWindow('superGroupUpdateMessageTimeAndStatus');
    window.superGroupUpdateMessage = registeMethodOnWindow('superGroupUpdateMessage');
    window.superGroupInsertMessage = registeMethodOnWindow('superGroupInsertMessage');
    window.superGroupBatchInsertMessageList = registeMethodOnWindow('superGroupBatchInsertMessageList');
    window.superGroupGetMessageListNoTime = registeMethodOnWindow('superGroupGetMessageListNoTime');
    window.superGroupGetMessageList = registeMethodOnWindow('superGroupGetMessageList');
    window.superGroupUpdateColumnsMessage = registeMethodOnWindow('superGroupUpdateColumnsMessage');
    window.superGroupDeleteAllMessage = registeMethodOnWindow('superGroupDeleteAllMessage');
    window.superGroupSearchMessageByKeyword = registeMethodOnWindow('superGroupSearchMessageByKeyword');
    window.superGroupSearchMessageByContentType = registeMethodOnWindow('superGroupSearchMessageByContentType');
    window.superGroupSearchMessageByContentTypeAndKeyword = registeMethodOnWindow('superGroupSearchMessageByContentTypeAndKeyword');
    window.superGroupUpdateMessageStatusBySourceID = registeMethodOnWindow('superGroupUpdateMessageStatusBySourceID');
    window.superGroupGetSendingMessageList = registeMethodOnWindow('superGroupGetSendingMessageList');
    window.superGroupUpdateGroupMessageHasRead = registeMethodOnWindow('superGroupUpdateGroupMessageHasRead');
    window.superGroupGetMsgSeqByClientMsgID = registeMethodOnWindow('superGroupGetMsgSeqByClientMsgID');
    window.superGroupUpdateMsgSenderFaceURLAndSenderNickname =
        registeMethodOnWindow('superGroupUpdateMsgSenderFaceURLAndSenderNickname');
    window.superGroupSearchAllMessageByContentType = registeMethodOnWindow('superGroupSearchAllMessageByContentType');
    // debug
    window.exec = registeMethodOnWindow('exec');
    window.getRowsModified = registeMethodOnWindow('getRowsModified');
    window.exportDB = async () => {
        if (!rpc || !worker) {
            initWorker();
        }
        if (!rpc) {
            return;
        }
        try {
            _logWrap('=> (invoked by go wasm) run exportDB method ');
            const result = await rpc.invoke('exportDB', undefined, { timeout: 5000 });
            _logWrap('=> (invoked by go wasm) run exportDB method with response ', JSON.stringify(result));
            return result;
        }
        catch (error) {
            catchErrorHandle(error);
        }
    };
    // black
    window.getBlackListDB = registeMethodOnWindow('getBlackList');
    window.getBlackListUserID = registeMethodOnWindow('getBlackListUserID');
    window.getBlackInfoByBlockUserID = registeMethodOnWindow('getBlackInfoByBlockUserID');
    window.getBlackInfoList = registeMethodOnWindow('getBlackInfoList');
    window.insertBlack = registeMethodOnWindow('insertBlack');
    window.deleteBlack = registeMethodOnWindow('deleteBlack');
    window.updateBlack = registeMethodOnWindow('updateBlack');
    // friendRequest
    window.insertFriendRequest = registeMethodOnWindow('insertFriendRequest');
    window.deleteFriendRequestBothUserID = registeMethodOnWindow('deleteFriendRequestBothUserID');
    window.updateFriendRequest = registeMethodOnWindow('updateFriendRequest');
    window.getRecvFriendApplication = registeMethodOnWindow('getRecvFriendApplication');
    window.getSendFriendApplication = registeMethodOnWindow('getSendFriendApplication');
    window.getFriendApplicationByBothID = registeMethodOnWindow('getFriendApplicationByBothID');
    window.getBothFriendReq = registeMethodOnWindow('getBothFriendReq');
    // friend
    window.insertFriend = registeMethodOnWindow('insertFriend');
    window.deleteFriendDB = registeMethodOnWindow('deleteFriend');
    window.updateFriend = registeMethodOnWindow('updateFriend');
    window.getAllFriendList = registeMethodOnWindow('getAllFriendList');
    window.searchFriendList = registeMethodOnWindow('searchFriendList');
    window.getFriendInfoByFriendUserID = registeMethodOnWindow('getFriendInfoByFriendUserID');
    window.getFriendInfoList = registeMethodOnWindow('getFriendInfoList');
    window.getPageFriendList = registeMethodOnWindow('getPageFriendList');
    window.updateColumnsFriend = registeMethodOnWindow('updateColumnsFriend');
    window.getFriendListCount = registeMethodOnWindow('getFriendListCount');
    window.batchInsertFriend = registeMethodOnWindow('batchInsertFriend');
    window.deleteAllFriend = registeMethodOnWindow('deleteAllFriend');
    // groups
    window.insertGroup = registeMethodOnWindow('insertGroup');
    window.deleteGroup = registeMethodOnWindow('deleteGroup');
    window.updateGroup = registeMethodOnWindow('updateGroup');
    window.getJoinedGroupListDB = registeMethodOnWindow('getJoinedGroupList');
    window.getGroupInfoByGroupID = registeMethodOnWindow('getGroupInfoByGroupID');
    window.getAllGroupInfoByGroupIDOrGroupName = registeMethodOnWindow('getAllGroupInfoByGroupIDOrGroupName');
    window.subtractMemberCount = registeMethodOnWindow('subtractMemberCount');
    window.addMemberCount = registeMethodOnWindow('addMemberCount');
    window.getJoinedWorkingGroupIDList = registeMethodOnWindow('getJoinedWorkingGroupIDList');
    window.getJoinedWorkingGroupList = registeMethodOnWindow('getJoinedWorkingGroupList');
    window.getGroupMemberAllGroupIDs = registeMethodOnWindow('getGroupMemberAllGroupIDs');
    window.getUserJoinedGroupIDs = registeMethodOnWindow('getUserJoinedGroupIDs');
    window.getGroups = registeMethodOnWindow('getGroups');
    window.getGroupMemberListByUserIDs = registeMethodOnWindow('getGroupMemberListByUserIDs');
    window.batchInsertGroup = registeMethodOnWindow('batchInsertGroup');
    window.deleteAllGroup = registeMethodOnWindow('deleteAllGroup');
    // groupRequest
    window.insertGroupRequest = registeMethodOnWindow('insertGroupRequest');
    window.deleteGroupRequest = registeMethodOnWindow('deleteGroupRequest');
    window.updateGroupRequest = registeMethodOnWindow('updateGroupRequest');
    window.getSendGroupApplication = registeMethodOnWindow('getSendGroupApplication');
    window.insertAdminGroupRequest = registeMethodOnWindow('insertAdminGroupRequest');
    window.deleteAdminGroupRequest = registeMethodOnWindow('deleteAdminGroupRequest');
    window.updateAdminGroupRequest = registeMethodOnWindow('updateAdminGroupRequest');
    window.getAdminGroupApplication = registeMethodOnWindow('getAdminGroupApplication');
    // groupMember
    window.getGroupMemberInfoByGroupIDUserID = registeMethodOnWindow('getGroupMemberInfoByGroupIDUserID');
    window.getAllGroupMemberList = registeMethodOnWindow('getAllGroupMemberList');
    window.getAllGroupMemberUserIDList = registeMethodOnWindow('getAllGroupMemberUserIDList');
    window.getGroupMemberCount = registeMethodOnWindow('getGroupMemberCount');
    window.getGroupSomeMemberInfo = registeMethodOnWindow('getGroupSomeMemberInfo');
    window.getGroupAdminID = registeMethodOnWindow('getGroupAdminID');
    window.getGroupMemberListByGroupID = registeMethodOnWindow('getGroupMemberListByGroupID');
    window.getGroupMemberListSplit = registeMethodOnWindow('getGroupMemberListSplit');
    window.getGroupMemberOwnerAndAdminDB = registeMethodOnWindow('getGroupMemberOwnerAndAdmin');
    window.getGroupMemberOwner = registeMethodOnWindow('getGroupMemberOwner');
    window.getGroupMemberListSplitByJoinTimeFilter = registeMethodOnWindow('getGroupMemberListSplitByJoinTimeFilter');
    window.getGroupOwnerAndAdminByGroupID = registeMethodOnWindow('getGroupOwnerAndAdminByGroupID');
    window.getGroupMemberUIDListByGroupID = registeMethodOnWindow('getGroupMemberUIDListByGroupID');
    window.insertGroupMember = registeMethodOnWindow('insertGroupMember');
    window.batchInsertGroupMember = registeMethodOnWindow('batchInsertGroupMember');
    window.deleteGroupMember = registeMethodOnWindow('deleteGroupMember');
    window.deleteGroupAllMembers = registeMethodOnWindow('deleteGroupAllMembers');
    window.updateGroupMember = registeMethodOnWindow('updateGroupMember');
    window.updateGroupMemberField = registeMethodOnWindow('updateGroupMemberField');
    window.searchGroupMembersDB = registeMethodOnWindow('searchGroupMembers', 'searchGroupMembersDB');
    // temp cache chat logs
    window.batchInsertTempCacheMessageList = registeMethodOnWindow('batchInsertTempCacheMessageList');
    window.InsertTempCacheMessage = registeMethodOnWindow('InsertTempCacheMessage');
    // notification
    window.getNotificationAllSeqs = registeMethodOnWindow('getNotificationAllSeqs');
    window.setNotificationSeq = registeMethodOnWindow('setNotificationSeq');
    window.batchInsertNotificationSeq = registeMethodOnWindow('batchInsertNotificationSeq');
    window.getExistedTables = registeMethodOnWindow('getExistedTables');
}
const workerPromise = rpc === null || rpc === void 0 ? void 0 : rpc.connect(5000);

class Emitter {
    constructor() {
        this.events = {};
    }
    emit(event, data) {
        if (this.events[event]) {
            this.events[event].forEach(fn => {
                return fn(data);
            });
        }
        return this;
    }
    on(event, fn) {
        if (this.events[event]) {
            this.events[event].push(fn);
        }
        else {
            this.events[event] = [fn];
        }
        return this;
    }
    off(event, fn) {
        if (event && typeof fn === 'function' && this.events[event]) {
            const listeners = this.events[event];
            if (!listeners || listeners.length === 0) {
                return;
            }
            const index = listeners.findIndex(_fn => {
                return _fn === fn;
            });
            if (index !== -1) {
                listeners.splice(index, 1);
            }
        }
        return this;
    }
}

// Unique ID creation requires a high quality random # generator. In the browser we therefore
// require the crypto API and do not support built-in fallback to lower quality random number
// generators (like Math.random()).
let getRandomValues;
const rnds8 = new Uint8Array(16);
function rng() {
  // lazy load so that environments that need to polyfill have a chance to do so
  if (!getRandomValues) {
    // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
    getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);

    if (!getRandomValues) {
      throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
    }
  }

  return getRandomValues(rnds8);
}

/**
 * Convert array of 16 byte values to UUID string format of the form:
 * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
 */

const byteToHex = [];

for (let i = 0; i < 256; ++i) {
  byteToHex.push((i + 0x100).toString(16).slice(1));
}

function unsafeStringify(arr, offset = 0) {
  // Note: Be careful editing this code!  It's been tuned for performance
  // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
  return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
}

const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
var native = {
  randomUUID
};

function v4(options, buf, offset) {
  if (native.randomUUID && !buf && !options) {
    return native.randomUUID();
  }

  options = options || {};
  const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`

  rnds[6] = rnds[6] & 0x0f | 0x40;
  rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided

  if (buf) {
    offset = offset || 0;

    for (let i = 0; i < 16; ++i) {
      buf[offset + i] = rnds[i];
    }

    return buf;
  }

  return unsafeStringify(rnds);
}

async function wait(duration) {
    return new Promise(resolve => {
        const timer = setTimeout(() => {
            clearTimeout(timer);
            resolve(null);
        }, duration);
    });
}

function logBoxStyleValue(backgroundColor, color) {
    return `font-size:14px; background:${backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : '#ffffff'}; color:${color !== null && color !== void 0 ? color : '#000000'}; border-radius:4px; padding-inline:4px;`;
}

let initialized = false;
let go;
let goExitPromise;
const CACHE_KEY = 'openim-wasm-cache';
async function initializeWasm(url) {
    if (initialized) {
        return null;
    }
    if (typeof window === 'undefined') {
        return Promise.resolve(null);
    }
    go = new Go();
    let wasm;
    try {
        if ('instantiateStreaming' in WebAssembly) {
            wasm = await WebAssembly.instantiateStreaming(fetchWithCache(url), go.importObject);
        }
        else {
            const bytes = await fetchWithCache(url).then(resp => resp.arrayBuffer());
            wasm = await WebAssembly.instantiate(bytes, go.importObject);
        }
        go.run(wasm.instance);
    }
    catch (error) {
        console.error('Failed to initialize WASM:', error);
        return null;
    }
    await wait(100);
    initialized = true;
    return go;
}
function getGO() {
    return go;
}
function getGoExitPromise() {
    return goExitPromise;
}
async function fetchWithCache(url) {
    if (!('caches' in window)) {
        return fetch(url);
    }
    const cache = await caches.open(CACHE_KEY);
    const cachedResponse = await cache.match(url);
    const isResourceUpdated = async () => {
        const serverResponse = await fetch(url, { method: 'HEAD' });
        const etag = serverResponse.headers.get('ETag');
        const lastModified = serverResponse.headers.get('Last-Modified');
        return (serverResponse.ok &&
            (etag !== (cachedResponse === null || cachedResponse === void 0 ? void 0 : cachedResponse.headers.get('ETag')) ||
                lastModified !== (cachedResponse === null || cachedResponse === void 0 ? void 0 : cachedResponse.headers.get('Last-Modified'))));
    };
    if (cachedResponse && !(await isResourceUpdated())) {
        return cachedResponse;
    }
    return fetchAndUpdateCache(url, cache);
}
async function fetchAndUpdateCache(url, cache) {
    const response = await fetch(url, { cache: 'no-cache' });
    await cache.put(url, response.clone());
    return response;
}

class SDK extends Emitter {
    constructor(url = '/openIM.wasm', debug = true) {
        super();
        this.goExisted = false;
        this.tryParse = true;
        this.isLogStandardOutput = true;
        this.login = async (params, operationID = v4()) => {
            var _a, _b;
            this._logWrap(`SDK => (invoked by js) run login with args ${JSON.stringify({
                params,
                operationID,
            })}`);
            await workerPromise;
            await this.wasmInitializedPromise;
            window.commonEventFunc(event => {
                try {
                    this._logWrap(`%cSDK =>%c received event %c${event}%c `, logBoxStyleValue('#282828', '#ffffff'), '', 'color: #4f2398;', '');
                    const parsed = JSON.parse(event);
                    if (this.tryParse) {
                        try {
                            parsed.data = JSON.parse(parsed.data);
                        }
                        catch (error) {
                            // parse error
                        }
                    }
                    this.emit(parsed.event, parsed);
                }
                catch (error) {
                    console.error(error);
                }
            });
            const config = {
                platformID: params.platformID,
                apiAddr: params.apiAddr,
                wsAddr: params.wsAddr,
                dataDir: './',
                logLevel: params.logLevel || 5,
                isLogStandardOutput: (_a = params.isLogStandardOutput) !== null && _a !== void 0 ? _a : this.isLogStandardOutput,
                logFilePath: './',
                isExternalExtensions: params.isExternalExtensions || false,
            };
            this.tryParse = (_b = params.tryParse) !== null && _b !== void 0 ? _b : true;
            window.initSDK(operationID, JSON.stringify(config));
            return await window.login(operationID, params.userID, params.token);
        };
        this.logout = (operationID = v4()) => {
            window.fileMapClear();
            return this._invoker('logout', window.logout, [operationID]);
        };
        this.getAllConversationList = (operationID = v4()) => {
            return this._invoker('getAllConversationList', window.getAllConversationList, [operationID]);
        };
        this.getOneConversation = (params, operationID = v4()) => {
            return this._invoker('getOneConversation', window.getOneConversation, [operationID, params.sessionType, params.sourceID]);
        };
        this.getAdvancedHistoryMessageList = (params, operationID = v4()) => {
            return this._invoker('getAdvancedHistoryMessageList', window.getAdvancedHistoryMessageList, [operationID, JSON.stringify(params)]);
        };
        this.getAdvancedHistoryMessageListReverse = (params, operationID = v4()) => {
            return this._invoker('getAdvancedHistoryMessageListReverse', window.getAdvancedHistoryMessageListReverse, [operationID, JSON.stringify(params)]);
        };
        this.getSpecifiedGroupsInfo = (params, operationID = v4()) => {
            return this._invoker('getSpecifiedGroupsInfo', window.getSpecifiedGroupsInfo, [operationID, JSON.stringify(params)]);
        };
        this.deleteConversationAndDeleteAllMsg = (conversationID, operationID = v4()) => {
            return this._invoker('deleteConversationAndDeleteAllMsg', window.deleteConversationAndDeleteAllMsg, [operationID, conversationID]);
        };
        this.markConversationMessageAsRead = (data, operationID = v4()) => {
            return this._invoker('markConversationMessageAsRead', window.markConversationMessageAsRead, [operationID, data]);
        };
        this.sendGroupMessageReadReceipt = (params, operationID = v4()) => {
            return this._invoker('sendGroupMessageReadReceipt', window.sendGroupMessageReadReceipt, [
                operationID,
                params.conversationID,
                JSON.stringify(params.clientMsgIDList),
            ]);
        };
        this.getGroupMessageReaderList = (params, operationID = v4()) => {
            return this._invoker('getGroupMessageReaderList', window.getGroupMessageReaderList, [
                operationID,
                params.conversationID,
                params.clientMsgID,
                params.filter,
                params.offset,
                params.count,
            ]);
        };
        this.getGroupMemberList = (params, operationID = v4()) => {
            return this._invoker('getGroupMemberList', window.getGroupMemberList, [operationID, params.groupID, params.filter, params.offset, params.count]);
        };
        this.createTextMessage = (text, operationID = v4()) => {
            return this._invoker('createTextMessage', window.createTextMessage, [operationID, text], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createImageMessageByURL = (params, operationID = v4()) => {
            return this._invoker('createImageMessageByURL', window.createImageMessageByURL, [
                operationID,
                params.sourcePath,
                JSON.stringify(params.sourcePicture),
                JSON.stringify(params.bigPicture),
                JSON.stringify(params.snapshotPicture),
            ], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createImageMessageByFile = (params, operationID = v4()) => {
            params.sourcePicture.uuid = `${params.sourcePicture.uuid}/${params.file.name}`;
            window.fileMapSet(params.sourcePicture.uuid, params.file);
            return this._invoker('createImageMessageByFile', window.createImageMessageByURL, [
                operationID,
                params.sourcePath,
                JSON.stringify(params.sourcePicture),
                JSON.stringify(params.bigPicture),
                JSON.stringify(params.snapshotPicture),
            ], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createCustomMessage = (params, operationID = v4()) => {
            return this._invoker('createCustomMessage', window.createCustomMessage, [operationID, params.data, params.extension, params.description], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createQuoteMessage = (params, operationID = v4()) => {
            return this._invoker('createQuoteMessage', window.createQuoteMessage, [operationID, params.text, params.message], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createAdvancedQuoteMessage = (params, operationID = v4()) => {
            return this._invoker('createAdvancedQuoteMessage', window.createAdvancedQuoteMessage, [
                operationID,
                params.text,
                JSON.stringify(params.message),
                JSON.stringify(params.messageEntityList),
            ], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createAdvancedTextMessage = (params, operationID = v4()) => {
            return this._invoker('createAdvancedTextMessage', window.createAdvancedTextMessage, [operationID, params.text, JSON.stringify(params.messageEntityList)], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.sendMessage = (params, operationID = v4()) => {
            var _a, _b;
            const offlinePushInfo = (_a = params.offlinePushInfo) !== null && _a !== void 0 ? _a : {
                title: '你有一条新消息',
                desc: '',
                ex: '',
                iOSPushSound: '+1',
                iOSBadgeCount: true,
            };
            return this._invoker('sendMessage', window.sendMessage, [
                operationID,
                JSON.stringify(params.message),
                params.recvID,
                params.groupID,
                JSON.stringify(offlinePushInfo),
                (_b = params.isOnlineOnly) !== null && _b !== void 0 ? _b : false,
            ]);
        };
        this.sendMessageNotOss = (params, operationID = v4()) => {
            var _a, _b;
            const offlinePushInfo = (_a = params.offlinePushInfo) !== null && _a !== void 0 ? _a : {
                title: '你有一条新消息',
                desc: '',
                ex: '',
                iOSPushSound: '+1',
                iOSBadgeCount: true,
            };
            return this._invoker('sendMessageNotOss', window.sendMessageNotOss, [
                operationID,
                JSON.stringify(params.message),
                params.recvID,
                params.groupID,
                JSON.stringify(offlinePushInfo),
                (_b = params.isOnlineOnly) !== null && _b !== void 0 ? _b : false,
            ]);
        };
        this.setMessageLocalEx = (params, operationID = v4()) => {
            return this._invoker('setMessageLocalEx', window.setMessageLocalEx, [
                operationID,
                params.conversationID,
                params.clientMsgID,
                params.localEx,
            ]);
        };
        this.getHistoryMessageListReverse = (params, operationID = v4()) => {
            return this._invoker('getHistoryMessageListReverse', window.getHistoryMessageListReverse, [operationID, JSON.stringify(params)]);
        };
        this.revokeMessage = (data, operationID = v4()) => {
            return this._invoker('revokeMessage', window.revokeMessage, [
                operationID,
                data.conversationID,
                data.clientMsgID,
            ]);
        };
        this.setConversationPrivateChat = (params, operationID = v4()) => {
            return this._invoker('setConversationPrivateChat', window.setConversationPrivateChat, [operationID, params.conversationID, params.isPrivate]);
        };
        this.setConversationBurnDuration = (params, operationID = v4()) => {
            return this._invoker('setConversationBurnDuration', window.setConversationBurnDuration, [operationID, params.conversationID, params.burnDuration]);
        };
        this.getLoginStatus = (operationID = v4()) => {
            return this._invoker('getLoginStatus', window.getLoginStatus, [operationID], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.setAppBackgroundStatus = (data, operationID = v4()) => {
            return this._invoker('setAppBackgroundStatus', window.setAppBackgroundStatus, [operationID, data]);
        };
        this.networkStatusChanged = (operationID = v4()) => {
            return this._invoker('networkStatusChanged ', window.networkStatusChanged, [operationID]);
        };
        this.getLoginUserID = (operationID = v4()) => {
            return this._invoker('getLoginUserID', window.getLoginUserID, [
                operationID,
            ]);
        };
        this.getSelfUserInfo = (operationID = v4()) => {
            return this._invoker('getSelfUserInfo', window.getSelfUserInfo, [operationID]);
        };
        this.getUsersInfo = (data, operationID = v4()) => {
            return this._invoker('getUsersInfo', window.getUsersInfo, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.getUsersInfoWithCache = (data, operationID = v4()) => {
            return this._invoker('getUsersInfoWithCache', window.getUsersInfoWithCache, [operationID, JSON.stringify(data.userIDList), data.groupID]);
        };
        this.setSelfInfo = (data, operationID = v4()) => {
            return this._invoker('setSelfInfo', window.setSelfInfo, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.createTextAtMessage = (data, operationID = v4()) => {
            var _a;
            return this._invoker('createTextAtMessage', window.createTextAtMessage, [
                operationID,
                data.text,
                JSON.stringify(data.atUserIDList),
                JSON.stringify(data.atUsersInfo),
                (_a = JSON.stringify(data.message)) !== null && _a !== void 0 ? _a : '',
            ], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createSoundMessageByURL = (data, operationID = v4()) => {
            return this._invoker('createSoundMessageByURL', window.createSoundMessageByURL, [operationID, JSON.stringify(data)], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createSoundMessageByFile = (data, operationID = v4()) => {
            data.uuid = `${data.uuid}/${data.file.name}`;
            window.fileMapSet(data.uuid, data.file);
            return this._invoker('createSoundMessageByFile', window.createSoundMessageByURL, [operationID, JSON.stringify(data)], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createVideoMessageByURL = (data, operationID = v4()) => {
            return this._invoker('createVideoMessageByURL', window.createVideoMessageByURL, [operationID, JSON.stringify(data)], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createVideoMessageByFile = (data, operationID = v4()) => {
            data.videoUUID = `${data.videoUUID}/${data.videoFile.name}`;
            data.snapshotUUID = `${data.snapshotUUID}/${data.snapshotFile.name}`;
            window.fileMapSet(data.videoUUID, data.videoFile);
            window.fileMapSet(data.snapshotUUID, data.snapshotFile);
            return this._invoker('createVideoMessageByFile', window.createVideoMessageByURL, [operationID, JSON.stringify(data)], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createFileMessageByURL = (data, operationID = v4()) => {
            return this._invoker('createFileMessageByURL', window.createFileMessageByURL, [operationID, JSON.stringify(data)], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createFileMessageByFile = (data, operationID = v4()) => {
            data.uuid = `${data.uuid}/${data.file.name}`;
            window.fileMapSet(data.uuid, data.file);
            return this._invoker('createFileMessageByFile', window.createFileMessageByURL, [operationID, JSON.stringify(data)], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createMergerMessage = (data, operationID = v4()) => {
            return this._invoker('createMergerMessage ', window.createMergerMessage, [
                operationID,
                JSON.stringify(data.messageList),
                data.title,
                JSON.stringify(data.summaryList),
            ], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createForwardMessage = (data, operationID = v4()) => {
            return this._invoker('createForwardMessage ', window.createForwardMessage, [operationID, JSON.stringify(data)], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createFaceMessage = (data, operationID = v4()) => {
            return this._invoker('createFaceMessage ', window.createFaceMessage, [operationID, data.index, data.data], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createLocationMessage = (data, operationID = v4()) => {
            return this._invoker('createLocationMessage ', window.createLocationMessage, [operationID, data.description, data.longitude, data.latitude], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.createCardMessage = (data, operationID = v4()) => {
            return this._invoker('createCardMessage ', window.createCardMessage, [operationID, JSON.stringify(data)], data => {
                // compitable with old version sdk
                return data[0];
            });
        };
        this.deleteMessageFromLocalStorage = (data, operationID = v4()) => {
            return this._invoker('deleteMessageFromLocalStorage ', window.deleteMessageFromLocalStorage, [operationID, data.conversationID, data.clientMsgID]);
        };
        this.deleteMessage = (data, operationID = v4()) => {
            return this._invoker('deleteMessage ', window.deleteMessage, [
                operationID,
                data.conversationID,
                data.clientMsgID,
            ]);
        };
        this.deleteAllConversationFromLocal = (operationID = v4()) => {
            return this._invoker('deleteAllConversationFromLocal ', window.deleteAllConversationFromLocal, [operationID]);
        };
        this.deleteAllMsgFromLocal = (operationID = v4()) => {
            return this._invoker('deleteAllMsgFromLocal ', window.deleteAllMsgFromLocal, [operationID]);
        };
        this.deleteAllMsgFromLocalAndSvr = (operationID = v4()) => {
            return this._invoker('deleteAllMsgFromLocalAndSvr ', window.deleteAllMsgFromLocalAndSvr, [operationID]);
        };
        this.insertSingleMessageToLocalStorage = (data, operationID = v4()) => {
            return this._invoker('insertSingleMessageToLocalStorage ', window.insertSingleMessageToLocalStorage, [operationID, JSON.stringify(data.message), data.recvID, data.sendID]);
        };
        this.insertGroupMessageToLocalStorage = (data, operationID = v4()) => {
            return this._invoker('insertGroupMessageToLocalStorage ', window.insertGroupMessageToLocalStorage, [operationID, JSON.stringify(data.message), data.groupID, data.sendID]);
        };
        this.typingStatusUpdate = (data, operationID = v4()) => {
            return this._invoker('typingStatusUpdate ', window.typingStatusUpdate, [
                operationID,
                data.recvID,
                data.msgTip,
            ]);
        };
        this.clearConversationAndDeleteAllMsg = (data, operationID = v4()) => {
            return this._invoker('clearConversationAndDeleteAllMsg ', window.clearConversationAndDeleteAllMsg, [operationID, data]);
        };
        this.hideConversation = (data, operationID = v4()) => {
            return this._invoker('hideConversation ', window.hideConversation, [
                operationID,
                data,
            ]);
        };
        this.getConversationListSplit = (data, operationID = v4()) => {
            return this._invoker('getConversationListSplit ', window.getConversationListSplit, [operationID, data.offset, data.count]);
        };
        // searchConversation = (data: SplitConversationParams, operationID = uuidv4()) => {
        //   return this._invoker<ConversationItem[]>(
        //     'searchConversation ',
        //     window.searchConversation,
        //     [operationID, data.offset, data.count]
        //   );
        // };
        this.setConversationEx = (data, operationID = v4()) => {
            return this._invoker('setConversationEx ', window.setConversationEx, [operationID, data.conversationID, data.ex]);
        };
        this.getConversationIDBySessionType = (data, operationID = v4()) => {
            return this._invoker('getConversationIDBySessionType ', window.getConversationIDBySessionType, [operationID, data.sourceID, data.sessionType]);
        };
        this.getMultipleConversation = (data, operationID = v4()) => {
            return this._invoker('getMultipleConversation ', window.getMultipleConversation, [operationID, JSON.stringify(data)]);
        };
        this.deleteConversation = (data, operationID = v4()) => {
            return this._invoker('deleteConversation ', window.deleteConversation, [
                operationID,
                data,
            ]);
        };
        this.setConversationDraft = (data, operationID = v4()) => {
            return this._invoker('setConversationDraft ', window.setConversationDraft, [operationID, data.conversationID, data.draftText]);
        };
        this.pinConversation = (data, operationID = v4()) => {
            return this._invoker('pinConversation ', window.pinConversation, [
                operationID,
                data.conversationID,
                data.isPinned,
            ]);
        };
        this.getTotalUnreadMsgCount = (operationID = v4()) => {
            return this._invoker('getTotalUnreadMsgCount ', window.getTotalUnreadMsgCount, [operationID]);
        };
        this.getConversationRecvMessageOpt = (data, operationID = v4()) => {
            return this._invoker('getConversationRecvMessageOpt ', window.getConversationRecvMessageOpt, [operationID, JSON.stringify(data)]);
        };
        this.setConversationRecvMessageOpt = (data, operationID = v4()) => {
            return this._invoker('setConversationRecvMessageOpt ', window.setConversationRecvMessageOpt, [operationID, data.conversationID, data.opt]);
        };
        this.searchLocalMessages = (data, operationID = v4()) => {
            return this._invoker('searchLocalMessages ', window.searchLocalMessages, [operationID, JSON.stringify(data)]);
        };
        this.addFriend = (data, operationID = v4()) => {
            return this._invoker('addFriend ', window.addFriend, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.searchFriends = (data, operationID = v4()) => {
            return this._invoker('searchFriends ', window.searchFriends, [operationID, JSON.stringify(data)]);
        };
        this.getSpecifiedFriendsInfo = (data, operationID = v4()) => {
            return this._invoker('getSpecifiedFriendsInfo ', window.getSpecifiedFriendsInfo, [operationID, JSON.stringify(data)]);
        };
        this.getFriendApplicationListAsRecipient = (operationID = v4()) => {
            return this._invoker('getFriendApplicationListAsRecipient ', window.getFriendApplicationListAsRecipient, [operationID]);
        };
        this.getFriendApplicationListAsApplicant = (operationID = v4()) => {
            return this._invoker('getFriendApplicationListAsApplicant ', window.getFriendApplicationListAsApplicant, [operationID]);
        };
        this.getFriendList = (operationID = v4()) => {
            return this._invoker('getFriendList ', window.getFriendList, [operationID]);
        };
        this.getFriendListPage = (data, operationID = v4()) => {
            return this._invoker('getFriendListPage ', window.getFriendListPage, [operationID, data.offset, data.count]);
        };
        this.setFriendRemark = (data, operationID = v4()) => {
            return this._invoker('setFriendRemark ', window.setFriendRemark, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.pinFriends = (data, operationID = v4()) => {
            return this._invoker('pinFriends ', window.pinFriends, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.setFriendsEx = (data, operationID = v4()) => {
            return this._invoker('setFriendsEx ', window.setFriendsEx, [
                operationID,
                JSON.stringify(data.toUserIDs),
                data.ex,
            ]);
        };
        this.checkFriend = (data, operationID = v4()) => {
            return this._invoker('checkFriend', window.checkFriend, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.acceptFriendApplication = (data, operationID = v4()) => {
            return this._invoker('acceptFriendApplication', window.acceptFriendApplication, [operationID, JSON.stringify(data)]);
        };
        this.refuseFriendApplication = (data, operationID = v4()) => {
            return this._invoker('refuseFriendApplication ', window.refuseFriendApplication, [operationID, JSON.stringify(data)]);
        };
        this.deleteFriend = (data, operationID = v4()) => {
            return this._invoker('deleteFriend ', window.deleteFriend, [
                operationID,
                data,
            ]);
        };
        this.addBlack = (data, operationID = v4()) => {
            var _a;
            return this._invoker('addBlack ', window.addBlack, [
                operationID,
                data.toUserID,
                (_a = data.ex) !== null && _a !== void 0 ? _a : '',
            ]);
        };
        this.removeBlack = (data, operationID = v4()) => {
            return this._invoker('removeBlack ', window.removeBlack, [
                operationID,
                data,
            ]);
        };
        this.getBlackList = (operationID = v4()) => {
            return this._invoker('getBlackList ', window.getBlackList, [operationID]);
        };
        this.inviteUserToGroup = (data, operationID = v4()) => {
            return this._invoker('inviteUserToGroup ', window.inviteUserToGroup, [
                operationID,
                data.groupID,
                data.reason,
                JSON.stringify(data.userIDList),
            ]);
        };
        this.kickGroupMember = (data, operationID = v4()) => {
            return this._invoker('kickGroupMember ', window.kickGroupMember, [
                operationID,
                data.groupID,
                data.reason,
                JSON.stringify(data.userIDList),
            ]);
        };
        this.isJoinGroup = (data, operationID = v4()) => {
            return this._invoker('isJoinGroup ', window.isJoinGroup, [
                operationID,
                data,
            ]);
        };
        this.getSpecifiedGroupMembersInfo = (data, operationID = v4()) => {
            return this._invoker('getSpecifiedGroupMembersInfo ', window.getSpecifiedGroupMembersInfo, [operationID, data.groupID, JSON.stringify(data.userIDList)]);
        };
        this.getUsersInGroup = (data, operationID = v4()) => {
            return this._invoker('getUsersInGroup ', window.getUsersInGroup, [
                operationID,
                data.groupID,
                JSON.stringify(data.userIDList),
            ]);
        };
        this.getGroupMemberListByJoinTimeFilter = (data, operationID = v4()) => {
            return this._invoker('getGroupMemberListByJoinTimeFilter ', window.getGroupMemberListByJoinTimeFilter, [
                operationID,
                data.groupID,
                data.offset,
                data.count,
                data.joinTimeBegin,
                data.joinTimeEnd,
                JSON.stringify(data.filterUserIDList),
            ]);
        };
        this.searchGroupMembers = (data, operationID = v4()) => {
            return this._invoker('searchGroupMembers ', window.searchGroupMembers, [operationID, JSON.stringify(data)]);
        };
        this.setGroupApplyMemberFriend = (data, operationID = v4()) => {
            return this._invoker('setGroupApplyMemberFriend ', window.setGroupApplyMemberFriend, [operationID, data.groupID, data.rule]);
        };
        this.setGroupLookMemberInfo = (data, operationID = v4()) => {
            return this._invoker('setGroupLookMemberInfo ', window.setGroupLookMemberInfo, [operationID, data.groupID, data.rule]);
        };
        this.getJoinedGroupList = (operationID = v4()) => {
            return this._invoker('getJoinedGroupList ', window.getJoinedGroupList, [operationID]);
        };
        this.getJoinedGroupListPage = (data, operationID = v4()) => {
            return this._invoker('getJoinedGroupListPage ', window.getJoinedGroupListPage, [operationID, data.offset, data.count]);
        };
        this.createGroup = (data, operationID = v4()) => {
            return this._invoker('createGroup ', window.createGroup, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.setGroupInfo = (data, operationID = v4()) => {
            return this._invoker('setGroupInfo ', window.setGroupInfo, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.setGroupMemberNickname = (data, operationID = v4()) => {
            return this._invoker('setGroupMemberNickname ', window.setGroupMemberNickname, [operationID, data.groupID, data.userID, data.groupMemberNickname]);
        };
        this.setGroupMemberInfo = (data, operationID = v4()) => {
            return this._invoker('setGroupMemberInfo ', window.setGroupMemberInfo, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.joinGroup = (data, operationID = v4()) => {
            var _a;
            return this._invoker('joinGroup ', window.joinGroup, [
                operationID,
                data.groupID,
                data.reqMsg,
                data.joinSource,
                (_a = data.ex) !== null && _a !== void 0 ? _a : '',
            ]);
        };
        this.searchGroups = (data, operationID = v4()) => {
            return this._invoker('searchGroups ', window.searchGroups, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.quitGroup = (data, operationID = v4()) => {
            return this._invoker('quitGroup ', window.quitGroup, [
                operationID,
                data,
            ]);
        };
        this.dismissGroup = (data, operationID = v4()) => {
            return this._invoker('dismissGroup ', window.dismissGroup, [
                operationID,
                data,
            ]);
        };
        this.changeGroupMute = (data, operationID = v4()) => {
            return this._invoker('changeGroupMute ', window.changeGroupMute, [
                operationID,
                data.groupID,
                data.isMute,
            ]);
        };
        this.changeGroupMemberMute = (data, operationID = v4()) => {
            return this._invoker('changeGroupMemberMute ', window.changeGroupMemberMute, [operationID, data.groupID, data.userID, data.mutedSeconds]);
        };
        this.transferGroupOwner = (data, operationID = v4()) => {
            return this._invoker('transferGroupOwner ', window.transferGroupOwner, [
                operationID,
                data.groupID,
                data.newOwnerUserID,
            ]);
        };
        this.getGroupApplicationListAsApplicant = (operationID = v4()) => {
            return this._invoker('getGroupApplicationListAsApplicant ', window.getGroupApplicationListAsApplicant, [operationID]);
        };
        this.getGroupApplicationListAsRecipient = (operationID = v4()) => {
            return this._invoker('getGroupApplicationListAsRecipient ', window.getGroupApplicationListAsRecipient, [operationID]);
        };
        this.acceptGroupApplication = (data, operationID = v4()) => {
            return this._invoker('acceptGroupApplication ', window.acceptGroupApplication, [operationID, data.groupID, data.fromUserID, data.handleMsg]);
        };
        this.refuseGroupApplication = (data, operationID = v4()) => {
            return this._invoker('refuseGroupApplication ', window.refuseGroupApplication, [operationID, data.groupID, data.fromUserID, data.handleMsg]);
        };
        this.resetConversationGroupAtType = (data, operationID = v4()) => {
            return this._invoker('resetConversationGroupAtType ', window.resetConversationGroupAtType, [operationID, data]);
        };
        this.setGroupMemberRoleLevel = (data, operationID = v4()) => {
            return this._invoker('setGroupMemberRoleLevel ', window.setGroupMemberRoleLevel, [operationID, data.groupID, data.userID, data.roleLevel]);
        };
        this.setGroupVerification = (data, operationID = v4()) => {
            return this._invoker('setGroupVerification ', window.setGroupVerification, [operationID, data.groupID, data.verification]);
        };
        this.getGroupMemberOwnerAndAdmin = (data, operationID = v4()) => {
            return this._invoker('getGroupMemberOwnerAndAdmin ', window.getGroupMemberOwnerAndAdmin, [operationID, data]);
        };
        this.setGlobalRecvMessageOpt = (opt, operationID = v4()) => {
            return this._invoker('setGlobalRecvMessageOpt ', window.setGlobalRecvMessageOpt, [operationID, opt]);
        };
        this.findMessageList = (data, operationID = v4()) => {
            return this._invoker('findMessageList ', window.findMessageList, [operationID, JSON.stringify(data)]);
        };
        this.uploadFile = (data, operationID = v4()) => {
            var _a;
            data.uuid = `${data.uuid}/${(_a = data.file) === null || _a === void 0 ? void 0 : _a.name}`;
            window.fileMapSet(data.uuid, data.file);
            return this._invoker('uploadFile ', window.uploadFile, [
                operationID,
                JSON.stringify({
                    ...data,
                    filepath: '',
                    cause: '',
                }),
            ]);
        };
        this.subscribeUsersStatus = (data, operationID = v4()) => {
            return this._invoker('subscribeUsersStatus ', window.subscribeUsersStatus, [operationID, JSON.stringify(data)]);
        };
        this.unsubscribeUsersStatus = (data, operationID = v4()) => {
            return this._invoker('unsubscribeUsersStatus ', window.unsubscribeUsersStatus, [operationID, JSON.stringify(data)]);
        };
        this.getUserStatus = (operationID = v4()) => {
            return this._invoker('getUserStatus ', window.getUserStatus, [operationID]);
        };
        this.getSubscribeUsersStatus = (operationID = v4()) => {
            return this._invoker('getSubscribeUsersStatus ', window.getSubscribeUsersStatus, [operationID]);
        };
        this.signalingInvite = (data, operationID = v4()) => {
            return this._invoker('signalingInvite ', window.signalingInvite, [operationID, JSON.stringify(data)]);
        };
        this.signalingInviteInGroup = (data, operationID = v4()) => {
            return this._invoker('signalingInviteInGroup ', window.signalingInviteInGroup, [operationID, JSON.stringify(data)]);
        };
        this.signalingAccept = (data, operationID = v4()) => {
            return this._invoker('signalingAccept ', window.signalingAccept, [operationID, JSON.stringify(data)]);
        };
        this.signalingReject = (data, operationID = v4()) => {
            return this._invoker('signalingReject ', window.signalingReject, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.signalingCancel = (data, operationID = v4()) => {
            return this._invoker('signalingCancel ', window.signalingCancel, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.signalingHungUp = (data, operationID = v4()) => {
            return this._invoker('signalingHungUp ', window.signalingHungUp, [
                operationID,
                JSON.stringify(data),
            ]);
        };
        this.signalingGetRoomByGroupID = (groupID, operationID = v4()) => {
            return this._invoker('signalingGetRoomByGroupID ', window.signalingGetRoomByGroupID, [operationID, groupID]);
        };
        this.signalingGetTokenByRoomID = (roomID, operationID = v4()) => {
            return this._invoker('signalingGetTokenByRoomID ', window.signalingGetTokenByRoomID, [operationID, roomID]);
        };
        this.signalingSendCustomSignal = (data, operationID = v4()) => {
            return this._invoker('signalingSendCustomSignal ', window.signalingSendCustomSignal, [operationID, data.customInfo, data.roomID]);
        };
        this.signalingCreateMeeting = (data, operationID = v4()) => {
            return this._invoker('signalingCreateMeeting ', window.signalingCreateMeeting, [operationID, JSON.stringify(data)]);
        };
        this.signalingJoinMeeting = (data, operationID = v4()) => {
            return this._invoker('signalingJoinMeeting ', window.signalingJoinMeeting, [
                operationID,
                JSON.stringify({
                    roomID: data,
                }),
            ]);
        };
        this.signalingUpdateMeetingInfo = (data, operationID = v4()) => {
            return this._invoker('signalingUpdateMeetingInfo ', window.signalingUpdateMeetingInfo, [operationID, JSON.stringify(data)]);
        };
        this.signalingCloseRoom = (roomID, operationID = v4()) => {
            return this._invoker('signalingCloseRoom ', window.signalingCloseRoom, [
                operationID,
                roomID,
            ]);
        };
        this.signalingGetMeetings = (operationID = v4()) => {
            return this._invoker('signalingGetMeetings ', window.signalingGetMeetings, [operationID]);
        };
        this.signalingOperateStream = (data, operationID = v4()) => {
            return this._invoker('signalingOperateStream ', window.signalingOperateStream, [
                operationID,
                data.streamType,
                data.roomID,
                data.userID,
                data.mute,
                data.muteAll,
            ]);
        };
        this.setConversationIsMsgDestruct = (data, operationID = v4()) => {
            return this._invoker('setConversationIsMsgDestruct ', window.setConversationIsMsgDestruct, [operationID, data.conversationID, data.isMsgDestruct]);
        };
        this.setConversationMsgDestructTime = (data, operationID = v4()) => {
            return this._invoker('setConversationMsgDestructTime ', window.setConversationMsgDestructTime, [operationID, data.conversationID, data.msgDestructTime]);
        };
        this.fileMapSet = (uuid, file) => window.fileMapSet(uuid, file);
        initDatabaseAPI(debug);
        this.isLogStandardOutput = debug;
        this.wasmInitializedPromise = initializeWasm(url);
        this.goExitPromise = getGoExitPromise();
        if (this.goExitPromise) {
            this.goExitPromise
                .then(() => {
                this._logWrap('SDK => wasm exist');
            })
                .catch(err => {
                this._logWrap('SDK => wasm with error ', err);
            })
                .finally(() => {
                this.goExisted = true;
            });
        }
    }
    _logWrap(...args) {
        if (this.isLogStandardOutput) {
            console.info(...args);
        }
    }
    _invoker(functionName, func, args, processor) {
        return new Promise(async (resolve, reject) => {
            this._logWrap(`%cSDK =>%c [OperationID:${args[0]}] (invoked by js) run ${functionName} with args ${JSON.stringify(args)}`, 'font-size:14px; background:#7CAEFF; border-radius:4px; padding-inline:4px;', '');
            let response = {
                operationID: args[0],
                event: (functionName.slice(0, 1).toUpperCase() +
                    functionName.slice(1).toLowerCase()),
            };
            try {
                if (!getGO() || getGO().exited || this.goExisted) {
                    throw 'wasm exist already, fail to run';
                }
                let data = await func(...args);
                if (processor) {
                    this._logWrap(`%cSDK =>%c [OperationID:${args[0]}] (invoked by js) run ${functionName} with response before processor ${JSON.stringify(data)}`, logBoxStyleValue('#FFDC19'), '');
                    data = processor(data);
                }
                if (this.tryParse) {
                    try {
                        data = JSON.parse(data);
                    }
                    catch (error) {
                        // parse error
                    }
                }
                response.data = data;
                resolve(response);
            }
            catch (error) {
                this._logWrap(`%cSDK =>%c [OperationID:${args[0]}] (invoked by js) run ${functionName} with error ${JSON.stringify(error)}`, logBoxStyleValue('#EE4245'), '');
                response = {
                    ...response,
                    ...error,
                };
                reject(response);
            }
        });
    }
    exportDB(operationID = v4()) {
        return this._invoker('exportDB', window.exportDB, [operationID]);
    }
}
let instance;
function getSDK(config) {
    const { sqlWasmPath, coreWasmPath = '/openIM.wasm', debug = true, } = config || {};
    if (typeof window === 'undefined') {
        return {};
    }
    if (instance) {
        return instance;
    }
    instance = new SDK(coreWasmPath, debug);
    if (sqlWasmPath) {
        window.setSqlWasmPath(sqlWasmPath);
    }
    return instance;
}

var MessageReceiveOptType;
(function (MessageReceiveOptType) {
    MessageReceiveOptType[MessageReceiveOptType["Normal"] = 0] = "Normal";
    MessageReceiveOptType[MessageReceiveOptType["NotReceive"] = 1] = "NotReceive";
    MessageReceiveOptType[MessageReceiveOptType["NotNotify"] = 2] = "NotNotify";
})(MessageReceiveOptType || (MessageReceiveOptType = {}));
var AllowType;
(function (AllowType) {
    AllowType[AllowType["Allowed"] = 0] = "Allowed";
    AllowType[AllowType["NotAllowed"] = 1] = "NotAllowed";
})(AllowType || (AllowType = {}));
var GroupType;
(function (GroupType) {
    GroupType[GroupType["Group"] = 2] = "Group";
    GroupType[GroupType["WorkingGroup"] = 2] = "WorkingGroup";
})(GroupType || (GroupType = {}));
var GroupJoinSource;
(function (GroupJoinSource) {
    GroupJoinSource[GroupJoinSource["Invitation"] = 2] = "Invitation";
    GroupJoinSource[GroupJoinSource["Search"] = 3] = "Search";
    GroupJoinSource[GroupJoinSource["QrCode"] = 4] = "QrCode";
})(GroupJoinSource || (GroupJoinSource = {}));
var GroupMemberRole;
(function (GroupMemberRole) {
    GroupMemberRole[GroupMemberRole["Normal"] = 20] = "Normal";
    GroupMemberRole[GroupMemberRole["Admin"] = 60] = "Admin";
    GroupMemberRole[GroupMemberRole["Owner"] = 100] = "Owner";
})(GroupMemberRole || (GroupMemberRole = {}));
var GroupVerificationType;
(function (GroupVerificationType) {
    GroupVerificationType[GroupVerificationType["ApplyNeedInviteNot"] = 0] = "ApplyNeedInviteNot";
    GroupVerificationType[GroupVerificationType["AllNeed"] = 1] = "AllNeed";
    GroupVerificationType[GroupVerificationType["AllNot"] = 2] = "AllNot";
})(GroupVerificationType || (GroupVerificationType = {}));
var MessageStatus;
(function (MessageStatus) {
    MessageStatus[MessageStatus["Sending"] = 1] = "Sending";
    MessageStatus[MessageStatus["Succeed"] = 2] = "Succeed";
    MessageStatus[MessageStatus["Failed"] = 3] = "Failed";
})(MessageStatus || (MessageStatus = {}));
var Platform;
(function (Platform) {
    Platform[Platform["iOS"] = 1] = "iOS";
    Platform[Platform["Android"] = 2] = "Android";
    Platform[Platform["Windows"] = 3] = "Windows";
    Platform[Platform["MacOSX"] = 4] = "MacOSX";
    Platform[Platform["Web"] = 5] = "Web";
    Platform[Platform["Linux"] = 7] = "Linux";
    Platform[Platform["AndroidPad"] = 8] = "AndroidPad";
    Platform[Platform["iPad"] = 9] = "iPad";
})(Platform || (Platform = {}));
var LogLevel;
(function (LogLevel) {
    LogLevel[LogLevel["Verbose"] = 6] = "Verbose";
    LogLevel[LogLevel["Debug"] = 5] = "Debug";
    LogLevel[LogLevel["Info"] = 4] = "Info";
    LogLevel[LogLevel["Warn"] = 3] = "Warn";
    LogLevel[LogLevel["Error"] = 2] = "Error";
    LogLevel[LogLevel["Fatal"] = 1] = "Fatal";
    LogLevel[LogLevel["Panic"] = 0] = "Panic";
})(LogLevel || (LogLevel = {}));
var ApplicationHandleResult;
(function (ApplicationHandleResult) {
    ApplicationHandleResult[ApplicationHandleResult["Unprocessed"] = 0] = "Unprocessed";
    ApplicationHandleResult[ApplicationHandleResult["Agree"] = 1] = "Agree";
    ApplicationHandleResult[ApplicationHandleResult["Reject"] = -1] = "Reject";
})(ApplicationHandleResult || (ApplicationHandleResult = {}));
var MessageType;
(function (MessageType) {
    MessageType[MessageType["TextMessage"] = 101] = "TextMessage";
    MessageType[MessageType["PictureMessage"] = 102] = "PictureMessage";
    MessageType[MessageType["VoiceMessage"] = 103] = "VoiceMessage";
    MessageType[MessageType["VideoMessage"] = 104] = "VideoMessage";
    MessageType[MessageType["FileMessage"] = 105] = "FileMessage";
    MessageType[MessageType["AtTextMessage"] = 106] = "AtTextMessage";
    MessageType[MessageType["MergeMessage"] = 107] = "MergeMessage";
    MessageType[MessageType["CardMessage"] = 108] = "CardMessage";
    MessageType[MessageType["LocationMessage"] = 109] = "LocationMessage";
    MessageType[MessageType["CustomMessage"] = 110] = "CustomMessage";
    MessageType[MessageType["TypingMessage"] = 113] = "TypingMessage";
    MessageType[MessageType["QuoteMessage"] = 114] = "QuoteMessage";
    MessageType[MessageType["FaceMessage"] = 115] = "FaceMessage";
    MessageType[MessageType["FriendAdded"] = 1201] = "FriendAdded";
    MessageType[MessageType["OANotification"] = 1400] = "OANotification";
    MessageType[MessageType["GroupCreated"] = 1501] = "GroupCreated";
    MessageType[MessageType["GroupInfoUpdated"] = 1502] = "GroupInfoUpdated";
    MessageType[MessageType["MemberQuit"] = 1504] = "MemberQuit";
    MessageType[MessageType["GroupOwnerTransferred"] = 1507] = "GroupOwnerTransferred";
    MessageType[MessageType["MemberKicked"] = 1508] = "MemberKicked";
    MessageType[MessageType["MemberInvited"] = 1509] = "MemberInvited";
    MessageType[MessageType["MemberEnter"] = 1510] = "MemberEnter";
    MessageType[MessageType["GroupDismissed"] = 1511] = "GroupDismissed";
    MessageType[MessageType["GroupMemberMuted"] = 1512] = "GroupMemberMuted";
    MessageType[MessageType["GroupMemberCancelMuted"] = 1513] = "GroupMemberCancelMuted";
    MessageType[MessageType["GroupMuted"] = 1514] = "GroupMuted";
    MessageType[MessageType["GroupCancelMuted"] = 1515] = "GroupCancelMuted";
    MessageType[MessageType["GroupAnnouncementUpdated"] = 1519] = "GroupAnnouncementUpdated";
    MessageType[MessageType["GroupNameUpdated"] = 1520] = "GroupNameUpdated";
    MessageType[MessageType["BurnMessageChange"] = 1701] = "BurnMessageChange";
    MessageType[MessageType["RevokeMessage"] = 2101] = "RevokeMessage";
})(MessageType || (MessageType = {}));
var SessionType;
(function (SessionType) {
    SessionType[SessionType["Single"] = 1] = "Single";
    SessionType[SessionType["Group"] = 3] = "Group";
    SessionType[SessionType["WorkingGroup"] = 3] = "WorkingGroup";
    SessionType[SessionType["Notification"] = 4] = "Notification";
})(SessionType || (SessionType = {}));
var GroupStatus;
(function (GroupStatus) {
    GroupStatus[GroupStatus["Normal"] = 0] = "Normal";
    GroupStatus[GroupStatus["Banned"] = 1] = "Banned";
    GroupStatus[GroupStatus["Dismissed"] = 2] = "Dismissed";
    GroupStatus[GroupStatus["Muted"] = 3] = "Muted";
})(GroupStatus || (GroupStatus = {}));
var GroupAtType;
(function (GroupAtType) {
    GroupAtType[GroupAtType["AtNormal"] = 0] = "AtNormal";
    GroupAtType[GroupAtType["AtMe"] = 1] = "AtMe";
    GroupAtType[GroupAtType["AtAll"] = 2] = "AtAll";
    GroupAtType[GroupAtType["AtAllAtMe"] = 3] = "AtAllAtMe";
    GroupAtType[GroupAtType["AtGroupNotice"] = 4] = "AtGroupNotice";
})(GroupAtType || (GroupAtType = {}));
var GroupMemberFilter;
(function (GroupMemberFilter) {
    GroupMemberFilter[GroupMemberFilter["All"] = 0] = "All";
    GroupMemberFilter[GroupMemberFilter["Owner"] = 1] = "Owner";
    GroupMemberFilter[GroupMemberFilter["Admin"] = 2] = "Admin";
    GroupMemberFilter[GroupMemberFilter["Normal"] = 3] = "Normal";
    GroupMemberFilter[GroupMemberFilter["AdminAndNormal"] = 4] = "AdminAndNormal";
    GroupMemberFilter[GroupMemberFilter["AdminAndOwner"] = 5] = "AdminAndOwner";
})(GroupMemberFilter || (GroupMemberFilter = {}));
var Relationship;
(function (Relationship) {
    Relationship[Relationship["isBlack"] = 0] = "isBlack";
    Relationship[Relationship["isFriend"] = 1] = "isFriend";
})(Relationship || (Relationship = {}));
var LoginStatus;
(function (LoginStatus) {
    LoginStatus[LoginStatus["Logout"] = 1] = "Logout";
    LoginStatus[LoginStatus["Logging"] = 2] = "Logging";
    LoginStatus[LoginStatus["Logged"] = 3] = "Logged";
})(LoginStatus || (LoginStatus = {}));
var OnlineState;
(function (OnlineState) {
    OnlineState[OnlineState["Online"] = 1] = "Online";
    OnlineState[OnlineState["Offline"] = 0] = "Offline";
})(OnlineState || (OnlineState = {}));
var GroupMessageReaderFilter;
(function (GroupMessageReaderFilter) {
    GroupMessageReaderFilter[GroupMessageReaderFilter["Read"] = 0] = "Read";
    GroupMessageReaderFilter[GroupMessageReaderFilter["UnRead"] = 1] = "UnRead";
})(GroupMessageReaderFilter || (GroupMessageReaderFilter = {}));

function decodeBase64(base64, enableUnicode) {
    var binaryString = atob(base64);
    if (enableUnicode) {
        var binaryView = new Uint8Array(binaryString.length);
        for (var i = 0, n = binaryString.length; i < n; ++i) {
            binaryView[i] = binaryString.charCodeAt(i);
        }
        return String.fromCharCode.apply(null, new Uint16Array(binaryView.buffer));
    }
    return binaryString;
}

function createURL(base64, sourcemapArg, enableUnicodeArg) {
    var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
    var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
    var source = decodeBase64(base64, enableUnicode);
    var start = source.indexOf('\n', 10) + 1;
    var body = source.substring(start) + (sourcemap ? '\/\/# sourceMappingURL=' + sourcemap : '');
    var blob = new Blob([body], { type: 'application/javascript' });
    return URL.createObjectURL(blob);
}

function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
    var url;
    return function WorkerFactory(options) {
        url = url || createURL(base64, sourcemapArg, enableUnicodeArg);
        return new Worker(url, options);
    };
}

var WorkerFactory = createBase64WorkerFactory(' ', null, false);

var indexeddbMainThreadWorkerB24e7a21 = /*#__PURE__*/Object.freeze({
  __proto__: null,
  'default': WorkerFactory
});

export { AllowType, ApplicationHandleResult, CbEvents, GroupAtType, GroupJoinSource, GroupMemberFilter, GroupMemberRole, GroupMessageReaderFilter, GroupStatus, GroupType, GroupVerificationType, LogLevel, LoginStatus, MessageReceiveOptType, MessageStatus, MessageType, OnlineState, Platform, Relationship, SessionType, getSDK };
