{"version":3,"file":"index.mjs","names":[],"sources":["../../src/wifi/wifi.ts"],"sourcesContent":["/* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD */\n/* SPDX-License-Identifier: Apache-2.0 */\n\n/**\n * Wi-Fi service module for JS apps — wraps `brookesia_service_wifi` RPC.\n *\n * @example\n * import wifi from '@brookesia/service/wifi';\n * if (wifi.available()) {\n *   await wifi.triggerGeneralAction('Init');\n *   wifi.setConnectAp('MySSID', 'secret');\n *   await wifi.triggerGeneralAction('Start');\n *   await wifi.triggerGeneralAction('Connect');\n *   brookesia.print(wifi.getGeneralState());\n *   wifi.close();\n * }\n */\n\nimport {\n  closeWifi,\n  getConnectAp,\n  getConnectedAps,\n  getGeneralState,\n  getSoftApParams,\n  isWifiAvailable,\n  loadWifiData,\n  openWifi,\n  removeConnectedAp,\n  resetWifiData,\n  setConnectAp,\n  setScanParams,\n  setSoftApParams,\n  triggerGeneralAction,\n  triggerScanStart,\n  triggerScanStop,\n  triggerSoftApProvisionStart,\n  triggerSoftApProvisionStop,\n  triggerSoftApStart,\n  triggerSoftApStop,\n  type WifiClientOptions,\n  type WifiHandle,\n} from './wifi-client.ts';\nimport type {\n  WifiConnectApInfo,\n  WifiGeneralAction,\n  WifiGeneralState,\n  WifiScanApInfo,\n  WifiScanParams,\n  WifiSoftApParams,\n} from './wifi-types.ts';\n\nexport type {\n  WifiConnectApInfo,\n  WifiGeneralAction,\n  WifiGeneralState,\n  WifiScanApInfo,\n  WifiScanParams,\n  WifiSoftApParams,\n};\n\nexport type WifiModuleOptions = WifiClientOptions;\n\ntype State = {\n  handle: WifiHandle | null;\n  options: WifiModuleOptions;\n};\n\nconst state: State = { handle: null, options: {} };\n\nfunction handle(): WifiHandle {\n  if (state.handle !== null) {\n    return state.handle;\n  }\n  if (!isWifiAvailable(state.options)) {\n    throw new Error('Wi-Fi service is not available');\n  }\n  state.handle = openWifi(state.options);\n  return state.handle;\n}\n\n/**\n * Inject a mock RPC host and reset the cached service handle (vitest / Node only).\n *\n * @param options - Client options, typically `{ host }` from `@brookesia/service/hosts/wifi`\n */\nexport function configure(options: WifiModuleOptions): void {\n  if (state.handle !== null) {\n    closeWifi(state.handle, state.options);\n  }\n  state.handle = null;\n  state.options = options;\n}\n\nconst wifi = {\n  /** @returns `true` when the Wi-Fi service is registered on the device */\n  available(): boolean {\n    return isWifiAvailable(state.options);\n  },\n\n  /** Release the Wi-Fi service binding. */\n  close(): void {\n    if (state.handle === null) {\n      return;\n    }\n    closeWifi(state.handle, state.options);\n    state.handle = null;\n  },\n\n  /**\n   * Read the Wi-Fi general state machine state.\n   * @returns e.g. `'Disconnected'`, `'Connected'`, `'Scanning'`\n   */\n  getGeneralState(): WifiGeneralState {\n    return getGeneralState(handle(), state.options);\n  },\n\n  /**\n   * Trigger a general Wi-Fi action (maps to C++ `TriggerGeneralAction`).\n   *\n   * @param action - `'Init'` | `'Start'` | `'Stop'` | `'Connect'` | `'Disconnect'`\n   */\n  triggerGeneralAction(action: WifiGeneralAction): void {\n    triggerGeneralAction(handle(), action, state.options);\n  },\n\n  /**\n   * Set the AP to connect to (maps to C++ `SetConnectAp`).\n   *\n   * @param ssid - Network SSID\n   * @param password - WPA passphrase; empty for open networks\n   */\n  setConnectAp(ssid: string, password = ''): void {\n    setConnectAp(handle(), ssid, password, state.options);\n  },\n\n  /** @returns Current connect-target AP info */\n  getConnectAp(): WifiConnectApInfo {\n    return getConnectAp(handle(), state.options);\n  },\n\n  /** @returns List of saved / connected AP records */\n  getConnectedAps(): WifiConnectApInfo[] {\n    return getConnectedAps(handle(), state.options);\n  },\n\n  /**\n   * Configure scan parameters (maps to C++ `SetScanParams`).\n   *\n   * @param params - `{ ap_count, interval_ms, timeout_ms }`\n   */\n  setScanParams(params: WifiScanParams): void {\n    setScanParams(handle(), params, state.options);\n  },\n\n  /** Start Wi-Fi scanning (maps to C++ `TriggerScanStart`). */\n  triggerScanStart(): void {\n    triggerScanStart(handle(), state.options);\n  },\n\n  /** Stop Wi-Fi scanning (maps to C++ `TriggerScanStop`). */\n  triggerScanStop(): void {\n    triggerScanStop(handle(), state.options);\n  },\n\n  /**\n   * Configure SoftAP parameters (maps to C++ `SetSoftApParams`).\n   *\n   * @param params - `{ ssid, password, max_connection }`\n   */\n  setSoftApParams(params: WifiSoftApParams): void {\n    setSoftApParams(handle(), params, state.options);\n  },\n\n  /** @returns Current SoftAP configuration */\n  getSoftApParams(): WifiSoftApParams {\n    return getSoftApParams(handle(), state.options);\n  },\n\n  /** Start SoftAP mode. */\n  triggerSoftApStart(): void {\n    triggerSoftApStart(handle(), state.options);\n  },\n\n  /** Stop SoftAP mode. */\n  triggerSoftApStop(): void {\n    triggerSoftApStop(handle(), state.options);\n  },\n\n  /** Enter SoftAP provisioning mode. */\n  triggerSoftApProvisionStart(): void {\n    triggerSoftApProvisionStart(handle(), state.options);\n  },\n\n  /** Exit SoftAP provisioning mode. */\n  triggerSoftApProvisionStop(): void {\n    triggerSoftApProvisionStop(handle(), state.options);\n  },\n\n  /**\n   * Remove a saved AP from the connected list.\n   *\n   * @param ssid - SSID to remove\n   */\n  removeConnectedAp(ssid: string): void {\n    removeConnectedAp(handle(), ssid, state.options);\n  },\n\n  /** Load persisted Wi-Fi settings from NVS / Storage. */\n  loadData(): void {\n    loadWifiData(handle(), state.options);\n  },\n\n  /** Reset Wi-Fi settings to factory defaults. */\n  resetData(): void {\n    resetWifiData(handle(), state.options);\n  },\n};\n\nexport default wifi;\n"],"mappings":";;;;;;;;;;;;;;;;AAmEA,MAAM,QAAe;CAAE,QAAQ;CAAM,SAAS,CAAC;AAAE;AAEjD,SAAS,SAAqB;CAC5B,IAAI,MAAM,WAAW,MACnB,OAAO,MAAM;CAEf,IAAI,CAAC,gBAAgB,MAAM,OAAO,GAChC,MAAM,IAAI,MAAM,gCAAgC;CAElD,MAAM,SAAS,SAAS,MAAM,OAAO;CACrC,OAAO,MAAM;AACf;;;;;;AAOA,SAAgB,UAAU,SAAkC;CAC1D,IAAI,MAAM,W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