diff --git a/WebUI/src/lib/MessageHandlers/Local/index.ts b/WebUI/src/lib/MessageHandlers/Local/index.ts index fdb723fc..9e9d1276 100644 --- a/WebUI/src/lib/MessageHandlers/Local/index.ts +++ b/WebUI/src/lib/MessageHandlers/Local/index.ts @@ -88,7 +88,7 @@ PayloadHandlers[DeviceToLocalMessagePayload.WifiNetworkDiscoveredEvent] = (cli, const bssid = fbsNetwork.bssid(); if (!ssid || !bssid) { - console.warn('[WS] Received invalid network lost event: ', fbsNetwork.ssid(), fbsNetwork.bssid(), fbsNetwork.rssi(), fbsNetwork.channel(), fbsNetwork.authMode(), fbsNetwork.saved()); + console.warn('[WS] Received invalid network lost event'); return; } @@ -101,6 +101,8 @@ PayloadHandlers[DeviceToLocalMessagePayload.WifiNetworkDiscoveredEvent] = (cli, saved: fbsNetwork.saved(), }; + console.log('[WS] Received network discovered event: ', network); + WiFiStateStore.addNetwork(network); }; diff --git a/WebUI/src/lib/components/WiFiList.svelte b/WebUI/src/lib/components/WiFiList.svelte index 3eab0c9d..68c7f2e9 100644 --- a/WebUI/src/lib/components/WiFiList.svelte +++ b/WebUI/src/lib/components/WiFiList.svelte @@ -4,20 +4,31 @@ import type { WiFiNetwork } from '$lib/types/WiFiNetwork'; import { WiFiStateStore } from '$lib/stores'; import { WebSocketClient } from '$lib/WebSocketClient'; + import { Builder as FlatbufferBuilder } from 'flatbuffers'; + import { WifiScanCommand } from '$lib/fbs/open-shock/serialization/local/wifi-scan-command'; + import { LocalToDeviceMessage } from '$lib/fbs/open-shock/serialization/local/local-to-device-message'; + import { LocalToDeviceMessagePayload } from '$lib/fbs/open-shock/serialization/local/local-to-device-message-payload'; + import { WifiAuthMode } from '$lib/fbs/open-shock/wifi-auth-mode'; const modalStore = getModalStore(); let connectedBSSID: string | null = null; function wifiScan() { - if ($WiFiStateStore.scanning) { - WebSocketClient.Instance.Send('{ "type": "wifi", "action": "scan", "run": false }'); - } else { - WebSocketClient.Instance.Send('{ "type": "wifi", "action": "scan", "run": true }'); - } + const fbb = new FlatbufferBuilder(64); + + const cmdOffset = WifiScanCommand.createWifiScanCommand(fbb, !$WiFiStateStore.scanning); + + const payloadOffset = LocalToDeviceMessage.createLocalToDeviceMessage(fbb, LocalToDeviceMessagePayload.WifiScanCommand, cmdOffset); + + fbb.finish(payloadOffset); + + const buf = fbb.asUint8Array(); + + WebSocketClient.Instance.Send(buf); } function wifiAuthenticate(item: WiFiNetwork) { - if (item.security !== 'Open') { + if (item.security !== WifiAuthMode.Open) { modalStore.trigger({ type: 'prompt', title: 'Enter password', @@ -61,27 +72,27 @@