munim-wifi 0.1.1 → 0.1.2

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.
@@ -9,6 +9,7 @@ import Foundation
9
9
  import NetworkExtension
10
10
  import CoreLocation
11
11
  import SystemConfiguration.CaptiveNetwork
12
+ import NitroModules
12
13
 
13
14
  class HybridMunimWifi: HybridMunimWifiSpec {
14
15
  private var locationManager: CLLocationManager?
@@ -19,21 +20,27 @@ class HybridMunimWifi: HybridMunimWifiSpec {
19
20
  // CoreWLAN is macOS only - not available on iOS
20
21
  // iOS can only get SSID/BSSID, not RSSI, channel, or frequency
21
22
 
22
- func isWifiEnabled() throws -> Bool {
23
+ func isWifiEnabled() throws -> Promise<Bool> {
24
+ let promise = Promise<Bool>()
23
25
  // On iOS, we can't directly check if Wi-Fi is enabled
24
26
  // We can infer it by checking if we can get current network
25
27
  if let _ = try? getCurrentNetworkSync() {
26
- return true
28
+ promise.resolve(withResult: true)
29
+ } else {
30
+ promise.resolve(withResult: false)
27
31
  }
28
- return false
32
+ return promise
29
33
  }
30
34
 
31
- func requestWifiPermission() throws -> Bool {
35
+ func requestWifiPermission() throws -> Promise<Bool> {
36
+ let promise = Promise<Bool>()
32
37
  let locationManager = CLLocationManager()
33
38
  self.locationManager = locationManager
34
39
 
35
40
  let status = locationManager.authorizationStatus
36
- return status == .authorizedWhenInUse || status == .authorizedAlways
41
+ let hasPermission = status == .authorizedWhenInUse || status == .authorizedAlways
42
+ promise.resolve(withResult: hasPermission)
43
+ return promise
37
44
  }
38
45
 
39
46
  // Helper to get current network synchronously
@@ -55,7 +62,8 @@ class HybridMunimWifi: HybridMunimWifiSpec {
55
62
  return result
56
63
  }
57
64
 
58
- func scanNetworks(maxResults: Double?, timeout: Double?) throws -> [WifiNetwork] {
65
+ func scanNetworks(options: ScanOptions?) throws -> Promise<[WifiNetwork]> {
66
+ let promise = Promise<[WifiNetwork]>()
59
67
  // iOS limitation: Cannot scan for networks directly
60
68
  // Only can get current connected network
61
69
  // For scanning, we can only return the current network if connected
@@ -73,14 +81,15 @@ class HybridMunimWifi: HybridMunimWifiSpec {
73
81
  timestamp: Int64(Date().timeIntervalSince1970 * 1000)
74
82
  )
75
83
  scanResults = [network]
76
- return [network]
84
+ promise.resolve(withResult: [network])
85
+ } else {
86
+ // Return empty array if not connected
87
+ promise.resolve(withResult: [])
77
88
  }
78
-
79
- // Return empty array if not connected
80
- return []
89
+ return promise
81
90
  }
82
91
 
83
- func startScan(maxResults: Double?, timeout: Double?) throws {
92
+ func startScan(options: ScanOptions?) throws {
84
93
  isScanning = true
85
94
  // iOS limitation: Cannot continuously scan
86
95
  // Just get current network once
@@ -104,44 +113,72 @@ class HybridMunimWifi: HybridMunimWifiSpec {
104
113
  isScanning = false
105
114
  }
106
115
 
107
- func getSSIDs() throws -> [String] {
116
+ func getSSIDs() throws -> Promise<[String]> {
117
+ let promise = Promise<[String]>()
108
118
  // iOS limitation: Can only get current network SSID
109
119
  if let current = try? getCurrentNetworkSync() {
110
- return [current.ssid]
120
+ promise.resolve(withResult: [current.ssid])
121
+ } else {
122
+ promise.resolve(withResult: [])
111
123
  }
112
- return []
124
+ return promise
113
125
  }
114
126
 
115
- func getWifiFingerprint() throws -> WifiFingerprint {
127
+ func getWifiFingerprint() throws -> Promise<WifiFingerprint> {
128
+ let promise = Promise<WifiFingerprint>()
116
129
  // iOS limitation: Can only get current network, no RSSI/channel/frequency
117
- let networks = scanResults.isEmpty ? (try? scanNetworks(maxResults: nil, timeout: nil)) ?? [] : scanResults
130
+ var networks: [WifiNetwork] = scanResults
131
+ if networks.isEmpty {
132
+ if let current = try? getCurrentNetworkSync() {
133
+ networks = [WifiNetwork(
134
+ ssid: current.ssid,
135
+ bssid: current.bssid,
136
+ rssi: nil,
137
+ frequency: nil,
138
+ channel: nil,
139
+ capabilities: nil,
140
+ isSecure: nil,
141
+ timestamp: Int64(Date().timeIntervalSince1970 * 1000)
142
+ )]
143
+ }
144
+ }
118
145
 
119
- return WifiFingerprint(
146
+ let fingerprint = WifiFingerprint(
120
147
  networks: networks,
121
148
  timestamp: Int64(Date().timeIntervalSince1970 * 1000)
122
149
  )
150
+ promise.resolve(withResult: fingerprint)
151
+ return promise
123
152
  }
124
153
 
125
- func getRSSI(ssid: String) throws -> Double? {
154
+ func getRSSI(ssid: String) throws -> Promise<Variant_NullType_Double> {
155
+ let promise = Promise<Variant_NullType_Double>()
126
156
  // iOS limitation: RSSI not available for scanned networks
127
- return nil
157
+ promise.resolve(withResult: .first(NullType()))
158
+ return promise
128
159
  }
129
160
 
130
- func getBSSID(ssid: String) throws -> String? {
161
+ func getBSSID(ssid: String) throws -> Promise<Variant_NullType_String> {
162
+ let promise = Promise<Variant_NullType_String>()
131
163
  if let current = try? getCurrentNetworkSync(), current.ssid == ssid {
132
- return current.bssid
164
+ promise.resolve(withResult: .second(current.bssid))
165
+ } else {
166
+ promise.resolve(withResult: .first(NullType()))
133
167
  }
134
- return nil
168
+ return promise
135
169
  }
136
170
 
137
- func getChannelInfo(ssid: String) throws -> ChannelInfo? {
171
+ func getChannelInfo(ssid: String) throws -> Promise<Variant_NullType_ChannelInfo> {
172
+ let promise = Promise<Variant_NullType_ChannelInfo>()
138
173
  // iOS limitation: Channel and frequency not available
139
- return nil
174
+ promise.resolve(withResult: .first(NullType()))
175
+ return promise
140
176
  }
141
177
 
142
- func getNetworkInfo(ssid: String) throws -> WifiNetwork? {
178
+ func getNetworkInfo(ssid: String) throws -> Promise<Variant_NullType_WifiNetwork> {
179
+ let promise = Promise<Variant_NullType_WifiNetwork>()
143
180
  if let current = try? getCurrentNetworkSync(), current.ssid == ssid {
144
- return WifiNetwork(
181
+ let network = WifiNetwork(
145
182
  ssid: current.ssid,
146
183
  bssid: current.bssid,
147
184
  rssi: nil, // Not available on iOS
@@ -151,13 +188,17 @@ class HybridMunimWifi: HybridMunimWifiSpec {
151
188
  isSecure: nil,
152
189
  timestamp: Int64(Date().timeIntervalSince1970 * 1000)
153
190
  )
191
+ promise.resolve(withResult: .second(network))
192
+ } else {
193
+ promise.resolve(withResult: .first(NullType()))
154
194
  }
155
- return nil
195
+ return promise
156
196
  }
157
197
 
158
- func getCurrentNetwork() throws -> CurrentNetworkInfo? {
159
- var result: CurrentNetworkInfo? = nil
198
+ func getCurrentNetwork() throws -> Promise<Variant_NullType_CurrentNetworkInfo> {
199
+ let promise = Promise<Variant_NullType_CurrentNetworkInfo>()
160
200
  let semaphore = DispatchSemaphore(value: 0)
201
+ var result: CurrentNetworkInfo? = nil
161
202
 
162
203
  NEHotspotNetwork.fetchCurrent { network in
163
204
  if let network = network {
@@ -170,10 +211,17 @@ class HybridMunimWifi: HybridMunimWifiSpec {
170
211
  }
171
212
 
172
213
  _ = semaphore.wait(timeout: .now() + 5)
173
- return result
214
+
215
+ if let result = result {
216
+ promise.resolve(withResult: .second(result))
217
+ } else {
218
+ promise.resolve(withResult: .first(NullType()))
219
+ }
220
+ return promise
174
221
  }
175
222
 
176
- func connectToNetwork(options: ConnectionOptions) throws {
223
+ func connectToNetwork(options: ConnectionOptions) throws -> Promise<Void> {
224
+ let promise = Promise<Void>()
177
225
  let configuration: NEHotspotConfiguration
178
226
 
179
227
  if let password = options.password {
@@ -199,11 +247,15 @@ class HybridMunimWifi: HybridMunimWifiSpec {
199
247
  _ = semaphore.wait(timeout: .now() + 30)
200
248
 
201
249
  if let error = error {
202
- throw error
250
+ promise.reject(withError: error)
251
+ } else {
252
+ promise.resolve()
203
253
  }
254
+ return promise
204
255
  }
205
256
 
206
- func disconnect() throws {
257
+ func disconnect() throws -> Promise<Void> {
258
+ let promise = Promise<Void>()
207
259
  // On iOS, we can't directly disconnect from Wi-Fi
208
260
  // We can only remove saved configurations
209
261
  // This is an iOS limitation
@@ -211,9 +263,12 @@ class HybridMunimWifi: HybridMunimWifiSpec {
211
263
  if let current = try? getCurrentNetworkSync() {
212
264
  NEHotspotConfigurationManager.shared.removeConfiguration(forSSID: current.ssid)
213
265
  }
266
+ promise.resolve()
267
+ return promise
214
268
  }
215
269
 
216
- func getIPAddress() throws -> String? {
270
+ func getIPAddress() throws -> Promise<Variant_NullType_String> {
271
+ let promise = Promise<Variant_NullType_String>()
217
272
  var address: String?
218
273
  var ifaddr: UnsafeMutablePointer<ifaddrs>?
219
274
 
@@ -241,7 +296,12 @@ class HybridMunimWifi: HybridMunimWifiSpec {
241
296
  }
242
297
  }
243
298
 
244
- return address
299
+ if let address = address {
300
+ promise.resolve(withResult: .second(address))
301
+ } else {
302
+ promise.resolve(withResult: .first(NullType()))
303
+ }
304
+ return promise
245
305
  }
246
306
 
247
307
  func addListener(eventName: String) throws {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "munim-wifi",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "munim-wifi is a react native package built with Nitro",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",