@mikrojs/native 0.15.0 → 0.16.0-next.20260618225923
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikrojs/native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0-next.20260618225923",
|
|
4
4
|
"description": "Mikro.js C++ runtime library and Node.js native addon",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esp32",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"cmake-js": "^8.0.0",
|
|
85
85
|
"node-addon-api": "^8.7.0",
|
|
86
86
|
"node-gyp-build": "^4.8.4",
|
|
87
|
-
"@mikrojs/quickjs": "0.
|
|
87
|
+
"@mikrojs/quickjs": "0.16.0-next.20260618225923+79c8761"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@swc/core": "^1.15.30",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/runtime/internal.d.ts
CHANGED
|
@@ -425,7 +425,7 @@ declare module 'native:mikro/wifi' {
|
|
|
425
425
|
ssid: string,
|
|
426
426
|
passphrase: string,
|
|
427
427
|
): R<Promise<R<{ip: string; netmask: string; gateway: string}>>>
|
|
428
|
-
disconnect(): R<void>
|
|
428
|
+
disconnect(shutdown?: boolean): R<void>
|
|
429
429
|
rssi(): R<number>
|
|
430
430
|
ip(): string
|
|
431
431
|
status(): number
|
package/runtime/wifi/types.ts
CHANGED
|
@@ -116,9 +116,24 @@ export interface WifiAp {
|
|
|
116
116
|
readonly onStationDisconnect: Observable<ApStationInfo>
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
export interface WifiConnectOptions {
|
|
120
|
+
ssid: string
|
|
121
|
+
passphrase: string
|
|
122
|
+
/** Max transmit power in dBm. Applies to the radio; quantized by the driver. */
|
|
123
|
+
txPower?: number
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface WifiDisconnectOptions {
|
|
127
|
+
/**
|
|
128
|
+
* Power the radio down and release its heap after disconnecting. Defaults to
|
|
129
|
+
* `true`. Pass `false` to keep the radio up for a faster reconnect.
|
|
130
|
+
*/
|
|
131
|
+
shutdown?: boolean
|
|
132
|
+
}
|
|
133
|
+
|
|
119
134
|
export interface Wifi {
|
|
120
|
-
connect(
|
|
121
|
-
disconnect(): Result<void, WifiError>
|
|
135
|
+
connect(options: WifiConnectOptions): Promise<Result<WifiConnectionInfo, WifiError>>
|
|
136
|
+
disconnect(options?: WifiDisconnectOptions): Result<void, WifiError>
|
|
122
137
|
rssi(): Result<number, WifiError>
|
|
123
138
|
ip(): string | undefined
|
|
124
139
|
status(): WifiStatus
|
|
@@ -137,7 +152,7 @@ export interface Wifi {
|
|
|
137
152
|
|
|
138
153
|
readonly ap: WifiAp
|
|
139
154
|
|
|
140
|
-
txPower: number
|
|
155
|
+
readonly txPower: number
|
|
141
156
|
rssiThreshold: number
|
|
142
157
|
|
|
143
158
|
powerSave: PowerSaveMode
|
package/runtime/wifi/wifi.ts
CHANGED
|
@@ -14,7 +14,9 @@ import type {
|
|
|
14
14
|
Wifi,
|
|
15
15
|
WifiAp,
|
|
16
16
|
WifiConnectionInfo,
|
|
17
|
+
WifiConnectOptions,
|
|
17
18
|
WifiCountryCode,
|
|
19
|
+
WifiDisconnectOptions,
|
|
18
20
|
WifiDisconnectReason,
|
|
19
21
|
WifiError,
|
|
20
22
|
WifiStatus,
|
|
@@ -81,7 +83,12 @@ const RETRY_DELAY_MS = 2000
|
|
|
81
83
|
const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))
|
|
82
84
|
|
|
83
85
|
const wifi: Wifi = {
|
|
84
|
-
async connect(
|
|
86
|
+
async connect(options: WifiConnectOptions): Promise<Result<WifiConnectionInfo, WifiError>> {
|
|
87
|
+
const {ssid, passphrase, txPower} = options
|
|
88
|
+
if (txPower !== undefined) {
|
|
89
|
+
const txResult = native.setTxPower(txPower)
|
|
90
|
+
if (!txResult.ok) return txResult
|
|
91
|
+
}
|
|
85
92
|
for (let attempt = 0; attempt <= MAX_CONNECT_RETRIES; attempt++) {
|
|
86
93
|
const startResult = native.connect(ssid, passphrase)
|
|
87
94
|
if (!startResult.ok) return startResult
|
|
@@ -93,14 +100,15 @@ const wifi: Wifi = {
|
|
|
93
100
|
|
|
94
101
|
// eslint-disable-next-line no-console
|
|
95
102
|
console.warn(`WiFi connect failed, retrying in ${RETRY_DELAY_MS}ms…`)
|
|
96
|
-
|
|
103
|
+
// Keep the radio up between retries so the next attempt reconnects fast.
|
|
104
|
+
native.disconnect(false)
|
|
97
105
|
await sleep(RETRY_DELAY_MS)
|
|
98
106
|
}
|
|
99
107
|
return err({name: 'ConnectFailed' as const, message: 'max retries exceeded'})
|
|
100
108
|
},
|
|
101
109
|
|
|
102
|
-
disconnect(): Result<void, WifiError> {
|
|
103
|
-
return native.disconnect()
|
|
110
|
+
disconnect(options?: WifiDisconnectOptions): Result<void, WifiError> {
|
|
111
|
+
return native.disconnect(options?.shutdown)
|
|
104
112
|
},
|
|
105
113
|
|
|
106
114
|
rssi(): Result<number, WifiError> {
|
|
@@ -159,10 +167,6 @@ const wifi: Wifi = {
|
|
|
159
167
|
return result.ok ? result.value : 0
|
|
160
168
|
},
|
|
161
169
|
|
|
162
|
-
set txPower(dbm: number) {
|
|
163
|
-
native.setTxPower(dbm)
|
|
164
|
-
},
|
|
165
|
-
|
|
166
170
|
get rssiThreshold(): number {
|
|
167
171
|
return native.getRssiThreshold()
|
|
168
172
|
},
|