@mpxjs/api-proxy 2.10.16-beta.1 → 2.10.16-beta.11
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 +2 -2
- package/src/platform/api/ble-connection/index.ios.js +75 -35
- package/src/platform/api/camera/index.ios.js +9 -0
- package/src/platform/api/camera/index.js +7 -0
- package/src/platform/api/camera/rnCamera.js +44 -0
- package/src/platform/api/device/wifi/index.ios.js +39 -34
- package/src/platform/index.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/api-proxy",
|
|
3
|
-
"version": "2.10.16-beta.
|
|
3
|
+
"version": "2.10.16-beta.11",
|
|
4
4
|
"description": "convert miniprogram API at each end",
|
|
5
5
|
"module": "src/index.js",
|
|
6
6
|
"types": "@types/index.d.ts",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/didi/mpx#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@mpxjs/utils": "^2.10.16",
|
|
40
|
+
"@mpxjs/utils": "^2.10.16-beta.6",
|
|
41
41
|
"axios": "^1.7.3"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { noop } from '@mpxjs/utils'
|
|
1
|
+
import { noop, type } from '@mpxjs/utils'
|
|
3
2
|
import mpx from '@mpxjs/core'
|
|
4
3
|
import { Platform, PermissionsAndroid } from 'react-native'
|
|
5
4
|
import { base64ToArrayBuffer } from '../base/index'
|
|
@@ -72,10 +71,11 @@ const commonFailHandler = function (errMsg, fail, complete) {
|
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
function openBluetoothAdapter (options = {}) {
|
|
74
|
+
const BleManager = require('react-native-ble-manager').default
|
|
75
75
|
const { success = noop, fail = noop, complete = noop } = options
|
|
76
76
|
let bluetoothPermission = requestBluetoothPermission
|
|
77
|
-
if (
|
|
78
|
-
bluetoothPermission = mpx.rnConfig.bluetoothPermission
|
|
77
|
+
if (mpx.config?.rnConfig?.bluetoothPermission) { // 安卓需要验证权限,开放给用户可以自定义验证权限的方法
|
|
78
|
+
bluetoothPermission = mpx.config.rnConfig.bluetoothPermission
|
|
79
79
|
}
|
|
80
80
|
// 先请求权限,再初始化蓝牙管理器
|
|
81
81
|
bluetoothPermission().then((hasPermissions) => {
|
|
@@ -118,6 +118,7 @@ function openBluetoothAdapter (options = {}) {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
function closeBluetoothAdapter (options = {}) {
|
|
121
|
+
const BleManager = require('react-native-ble-manager').default
|
|
121
122
|
const { success = noop, fail = noop, complete = noop } = options
|
|
122
123
|
if (!bleManagerInitialized) {
|
|
123
124
|
const result = {
|
|
@@ -183,6 +184,7 @@ function closeBluetoothAdapter (options = {}) {
|
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
function startBluetoothDevicesDiscovery (options = {}) {
|
|
187
|
+
const BleManager = require('react-native-ble-manager').default
|
|
186
188
|
const {
|
|
187
189
|
services = [],
|
|
188
190
|
allowDuplicatesKey = false,
|
|
@@ -197,12 +199,12 @@ function startBluetoothDevicesDiscovery (options = {}) {
|
|
|
197
199
|
}
|
|
198
200
|
DiscoverPeripheralSubscription = BleManager.onDiscoverPeripheral((device) => {
|
|
199
201
|
const advertising = device.advertising || {}
|
|
200
|
-
const advertisData = advertising.manufacturerData?.data || null
|
|
202
|
+
const advertisData = (advertising.manufacturerData && Object.values(advertising.manufacturerData)[0]?.data) || null
|
|
201
203
|
const deviceInfo = {
|
|
202
204
|
deviceId: device.id,
|
|
203
205
|
name: device.name || advertising.localName || '未知设备',
|
|
204
206
|
RSSI: device.rssi || 0,
|
|
205
|
-
advertisData: advertisData ? base64ToArrayBuffer(advertisData) : advertisData,
|
|
207
|
+
advertisData: advertisData ? base64ToArrayBuffer(advertisData) : advertisData,
|
|
206
208
|
advertisServiceUUIDs: advertising.serviceUUIDs || [],
|
|
207
209
|
localName: advertising.localName || '',
|
|
208
210
|
serviceData: advertising.serviceData || {},
|
|
@@ -211,23 +213,30 @@ function startBluetoothDevicesDiscovery (options = {}) {
|
|
|
211
213
|
if (allowDuplicatesKey === false) {
|
|
212
214
|
const existingDeviceIndex = getDevices.findIndex(existingDevice => existingDevice.deviceId === deviceInfo.deviceId)
|
|
213
215
|
if (existingDeviceIndex > -1) {
|
|
216
|
+
if (device.name) {
|
|
217
|
+
getDevices.splice(existingDeviceIndex, 1, deviceInfo)
|
|
218
|
+
}
|
|
214
219
|
return
|
|
215
220
|
}
|
|
216
221
|
}
|
|
217
222
|
deviceFoundCallbacks.forEach(cb => {
|
|
218
|
-
cb
|
|
219
|
-
|
|
220
|
-
|
|
223
|
+
if (type(cb) === 'Function') {
|
|
224
|
+
cb({
|
|
225
|
+
devices: [deviceInfo]
|
|
226
|
+
})
|
|
227
|
+
}
|
|
221
228
|
})
|
|
222
229
|
getDevices.push(deviceInfo)
|
|
223
230
|
// 处理设备发现逻辑
|
|
224
231
|
})
|
|
225
232
|
BleManager.scan(services, 0, allowDuplicatesKey).then((res) => { // 必须,没有开启扫描,onDiscoverPeripheral回调不会触发
|
|
226
233
|
onStateChangeCallbacks.forEach(cb => {
|
|
227
|
-
cb
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
234
|
+
if (type(cb) === 'Function') {
|
|
235
|
+
cb({
|
|
236
|
+
available: true,
|
|
237
|
+
discovering: true
|
|
238
|
+
})
|
|
239
|
+
}
|
|
231
240
|
})
|
|
232
241
|
discovering = true
|
|
233
242
|
getDevices = [] // 清空之前的发现设备列表
|
|
@@ -243,6 +252,7 @@ function startBluetoothDevicesDiscovery (options = {}) {
|
|
|
243
252
|
}
|
|
244
253
|
|
|
245
254
|
function stopBluetoothDevicesDiscovery (options = {}) {
|
|
255
|
+
const BleManager = require('react-native-ble-manager').default
|
|
246
256
|
const { success = noop, fail = noop, complete = noop } = options
|
|
247
257
|
|
|
248
258
|
if (!bleManagerInitialized) {
|
|
@@ -253,10 +263,12 @@ function stopBluetoothDevicesDiscovery (options = {}) {
|
|
|
253
263
|
BleManager.stopScan().then(() => {
|
|
254
264
|
discovering = false
|
|
255
265
|
onStateChangeCallbacks.forEach(cb => {
|
|
256
|
-
cb
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
266
|
+
if (type(cb) === 'Function') {
|
|
267
|
+
cb({
|
|
268
|
+
available: true,
|
|
269
|
+
discovering: false
|
|
270
|
+
})
|
|
271
|
+
}
|
|
260
272
|
})
|
|
261
273
|
const result = {
|
|
262
274
|
errMsg: 'stopBluetoothDevicesDiscovery:ok'
|
|
@@ -282,6 +294,7 @@ function offBluetoothDeviceFound (callback) {
|
|
|
282
294
|
}
|
|
283
295
|
|
|
284
296
|
function getConnectedBluetoothDevices (options = {}) {
|
|
297
|
+
const BleManager = require('react-native-ble-manager').default
|
|
285
298
|
const { services = [], success = noop, fail = noop, complete = noop } = options
|
|
286
299
|
|
|
287
300
|
if (!bleManagerInitialized) {
|
|
@@ -306,6 +319,7 @@ function getConnectedBluetoothDevices (options = {}) {
|
|
|
306
319
|
}
|
|
307
320
|
|
|
308
321
|
function getBluetoothAdapterState (options = {}) {
|
|
322
|
+
const BleManager = require('react-native-ble-manager').default
|
|
309
323
|
const { success = noop, fail = noop, complete = noop } = options
|
|
310
324
|
|
|
311
325
|
if (!bleManagerInitialized) {
|
|
@@ -326,20 +340,25 @@ function getBluetoothAdapterState (options = {}) {
|
|
|
326
340
|
})
|
|
327
341
|
}
|
|
328
342
|
function onDidUpdateState () {
|
|
343
|
+
const BleManager = require('react-native-ble-manager').default
|
|
329
344
|
updateStateSubscription = BleManager.onDidUpdateState((state) => {
|
|
330
345
|
onStateChangeCallbacks.forEach(cb => {
|
|
331
|
-
cb
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
346
|
+
if (type(cb) === 'Function') {
|
|
347
|
+
cb({
|
|
348
|
+
available: state.state === 'on',
|
|
349
|
+
discovering: state.state === 'on' ? discovering : false
|
|
350
|
+
})
|
|
351
|
+
}
|
|
335
352
|
})
|
|
336
353
|
if (onBLEConnectionStateCallbacks.length && connectedDeviceId.length && state.state !== 'on') {
|
|
337
354
|
connectedDeviceId.forEach((id) => {
|
|
338
355
|
onBLEConnectionStateCallbacks.forEach(cb => {
|
|
339
|
-
cb
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
356
|
+
if (type(cb) === 'Function') {
|
|
357
|
+
cb({
|
|
358
|
+
deviceId: id,
|
|
359
|
+
connected: false
|
|
360
|
+
})
|
|
361
|
+
}
|
|
343
362
|
})
|
|
344
363
|
})
|
|
345
364
|
}
|
|
@@ -384,6 +403,7 @@ function getBluetoothDevices (options = {}) { // 该能力只是获取应用级
|
|
|
384
403
|
}
|
|
385
404
|
|
|
386
405
|
function writeBLECharacteristicValue (options = {}) {
|
|
406
|
+
const BleManager = require('react-native-ble-manager').default
|
|
387
407
|
const { deviceId, serviceId, characteristicId, value, success = noop, fail = noop, complete = noop } = options
|
|
388
408
|
if (!deviceId || !serviceId || !characteristicId || !value) {
|
|
389
409
|
const result = {
|
|
@@ -413,6 +433,7 @@ function writeBLECharacteristicValue (options = {}) {
|
|
|
413
433
|
}
|
|
414
434
|
|
|
415
435
|
function readBLECharacteristicValue (options = {}) {
|
|
436
|
+
const BleManager = require('react-native-ble-manager').default
|
|
416
437
|
const { deviceId, serviceId, characteristicId, success = noop, fail = noop, complete = noop } = options
|
|
417
438
|
|
|
418
439
|
if (!deviceId || !serviceId || !characteristicId) {
|
|
@@ -449,6 +470,7 @@ function readBLECharacteristicValue (options = {}) {
|
|
|
449
470
|
}
|
|
450
471
|
|
|
451
472
|
function notifyBLECharacteristicValueChange (options = {}) {
|
|
473
|
+
const BleManager = require('react-native-ble-manager').default
|
|
452
474
|
const { deviceId, serviceId, characteristicId, state = true, success = noop, fail = noop, complete = noop } = options
|
|
453
475
|
|
|
454
476
|
if (!deviceId || !serviceId || !characteristicId) {
|
|
@@ -502,6 +524,7 @@ function notifyBLECharacteristicValueChange (options = {}) {
|
|
|
502
524
|
|
|
503
525
|
let valueForCharacteristicSubscriptions = null
|
|
504
526
|
function onBLECharacteristicValueChange (callback) {
|
|
527
|
+
const BleManager = require('react-native-ble-manager').default
|
|
505
528
|
if (characteristicCallbacks.length === 0) {
|
|
506
529
|
valueForCharacteristicSubscriptions = BleManager.onDidUpdateValueForCharacteristic((data) => {
|
|
507
530
|
// 将byte array转换为ArrayBuffer
|
|
@@ -517,7 +540,9 @@ function onBLECharacteristicValueChange (callback) {
|
|
|
517
540
|
value: buffer
|
|
518
541
|
}
|
|
519
542
|
characteristicCallbacks.forEach(cb => {
|
|
520
|
-
cb
|
|
543
|
+
if (type(cb) === 'Function') {
|
|
544
|
+
cb(result)
|
|
545
|
+
}
|
|
521
546
|
})
|
|
522
547
|
})
|
|
523
548
|
}
|
|
@@ -538,6 +563,7 @@ function offBLECharacteristicValueChange (callback) {
|
|
|
538
563
|
}
|
|
539
564
|
|
|
540
565
|
function setBLEMTU (options = {}) {
|
|
566
|
+
const BleManager = require('react-native-ble-manager').default
|
|
541
567
|
const { deviceId, mtu, success = noop, fail = noop, complete = noop } = options
|
|
542
568
|
if (!mtu) {
|
|
543
569
|
commonFailHandler('setBLEMTU:fail parameter error: parameter.mtu should be Number instead of Undefined;', fail, complete)
|
|
@@ -569,6 +595,7 @@ function setBLEMTU (options = {}) {
|
|
|
569
595
|
}
|
|
570
596
|
|
|
571
597
|
function getBLEDeviceRSSI (options = {}) {
|
|
598
|
+
const BleManager = require('react-native-ble-manager').default
|
|
572
599
|
const { deviceId, success = noop, fail = noop, complete = noop } = options
|
|
573
600
|
|
|
574
601
|
if (!deviceId) {
|
|
@@ -599,6 +626,7 @@ function getBLEDeviceRSSI (options = {}) {
|
|
|
599
626
|
}
|
|
600
627
|
|
|
601
628
|
function getBLEDeviceServices (options = {}) {
|
|
629
|
+
const BleManager = require('react-native-ble-manager').default
|
|
602
630
|
const { deviceId, success = noop, fail = noop, complete = noop } = options
|
|
603
631
|
|
|
604
632
|
if (!deviceId) {
|
|
@@ -671,7 +699,13 @@ function getBLEDeviceCharacteristics (options = {}) {
|
|
|
671
699
|
}
|
|
672
700
|
const characteristics = characteristicsList.map(char => ({
|
|
673
701
|
uuid: char.characteristic,
|
|
674
|
-
properties:
|
|
702
|
+
properties: {
|
|
703
|
+
read: !!char.properties.Read,
|
|
704
|
+
write: !!char.properties.Write,
|
|
705
|
+
notify: !!char.properties.Notify,
|
|
706
|
+
indicate: !!char.properties.Indicate,
|
|
707
|
+
writeNoResponse: !!char.properties.writeWithoutResponse
|
|
708
|
+
}
|
|
675
709
|
}))
|
|
676
710
|
|
|
677
711
|
const result = {
|
|
@@ -683,6 +717,7 @@ function getBLEDeviceCharacteristics (options = {}) {
|
|
|
683
717
|
}
|
|
684
718
|
|
|
685
719
|
function createBLEConnection (options = {}) {
|
|
720
|
+
const BleManager = require('react-native-ble-manager').default
|
|
686
721
|
const { deviceId, timeout, success = noop, fail = noop, complete = noop } = options
|
|
687
722
|
|
|
688
723
|
if (!deviceId) {
|
|
@@ -703,10 +738,12 @@ function createBLEConnection (options = {}) {
|
|
|
703
738
|
}
|
|
704
739
|
clearTimeout(createBLEConnectionTimeout)
|
|
705
740
|
onBLEConnectionStateCallbacks.forEach(cb => {
|
|
706
|
-
cb
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
741
|
+
if (type(cb) === 'Function') {
|
|
742
|
+
cb({
|
|
743
|
+
deviceId,
|
|
744
|
+
connected: true
|
|
745
|
+
})
|
|
746
|
+
}
|
|
710
747
|
})
|
|
711
748
|
connectedDevices.add(deviceId)
|
|
712
749
|
const result = {
|
|
@@ -730,6 +767,7 @@ function createBLEConnection (options = {}) {
|
|
|
730
767
|
}
|
|
731
768
|
|
|
732
769
|
function closeBLEConnection (options = {}) {
|
|
770
|
+
const BleManager = require('react-native-ble-manager').default
|
|
733
771
|
const { deviceId, success = noop, fail = noop, complete = noop } = options
|
|
734
772
|
|
|
735
773
|
if (!deviceId) {
|
|
@@ -748,10 +786,12 @@ function closeBLEConnection (options = {}) {
|
|
|
748
786
|
connectedDeviceId.splice(index, 1) // 记录一下已连接的设备id
|
|
749
787
|
}
|
|
750
788
|
onBLEConnectionStateCallbacks.forEach(cb => {
|
|
751
|
-
cb
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
789
|
+
if (type(cb) === 'Function') {
|
|
790
|
+
cb({
|
|
791
|
+
deviceId,
|
|
792
|
+
connected: false
|
|
793
|
+
})
|
|
794
|
+
}
|
|
755
795
|
})
|
|
756
796
|
connectedDevices.delete(deviceId)
|
|
757
797
|
const result = {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { noop, getFocusedNavigation } from '@mpxjs/utils'
|
|
2
|
+
|
|
3
|
+
export default class CreateCamera {
|
|
4
|
+
constructor () {
|
|
5
|
+
const navigation = getFocusedNavigation() || {}
|
|
6
|
+
this.camera = navigation.camera || {}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
setZoom (options = {}) {
|
|
10
|
+
const { zoom, success = noop, fail = noop, complete = noop } = options
|
|
11
|
+
try {
|
|
12
|
+
if (this.camera.setZoom) {
|
|
13
|
+
const result = { errMsg: 'setZoom:ok' }
|
|
14
|
+
success(result)
|
|
15
|
+
complete(result)
|
|
16
|
+
this.camera.setZoom(zoom)
|
|
17
|
+
} else {
|
|
18
|
+
const result = {
|
|
19
|
+
errMsg: 'setZoom:fail camera instance not found'
|
|
20
|
+
}
|
|
21
|
+
fail(result)
|
|
22
|
+
complete(result)
|
|
23
|
+
}
|
|
24
|
+
} catch (error) {
|
|
25
|
+
const result = {
|
|
26
|
+
errMsg: 'setZoom:fail ' + (error?.message || '')
|
|
27
|
+
}
|
|
28
|
+
fail(result)
|
|
29
|
+
complete(result)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
takePhoto (options) {
|
|
34
|
+
this.camera?.takePhoto(options)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
startRecord (options) {
|
|
38
|
+
this.camera?.startRecord(options)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
stopRecord (options) {
|
|
42
|
+
this.camera?.stopRecord(options)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import WifiManager from 'react-native-wifi-reborn'
|
|
2
1
|
import { PermissionsAndroid } from 'react-native'
|
|
3
|
-
import { noop } from '@mpxjs/utils'
|
|
2
|
+
import { noop, type } from '@mpxjs/utils'
|
|
4
3
|
import mpx from '@mpxjs/core'
|
|
5
4
|
let startWifiReady = false
|
|
6
5
|
const wifiListListeners = []
|
|
@@ -31,10 +30,10 @@ function startWifi (options = {}) {
|
|
|
31
30
|
complete(result)
|
|
32
31
|
return
|
|
33
32
|
}
|
|
34
|
-
|
|
33
|
+
const WifiManager = require('react-native-wifi-reborn').default
|
|
35
34
|
let wifiPermission = requestWifiPermission
|
|
36
|
-
if (mpx.rnConfig?.wifiPermission) {
|
|
37
|
-
wifiPermission = mpx.rnConfig.wifiPermission
|
|
35
|
+
if (mpx.config?.rnConfig?.wifiPermission) {
|
|
36
|
+
wifiPermission = mpx.config.rnConfig.wifiPermission
|
|
38
37
|
}
|
|
39
38
|
wifiPermission().then(async () => {
|
|
40
39
|
let enabled
|
|
@@ -43,17 +42,21 @@ function startWifi (options = {}) {
|
|
|
43
42
|
} catch (e) {
|
|
44
43
|
enabled = false
|
|
45
44
|
}
|
|
46
|
-
const result = {
|
|
47
|
-
errMsg: 'startWifi:success'
|
|
48
|
-
}
|
|
49
45
|
if (!enabled) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
const result = {
|
|
47
|
+
errMsg: 'startWifi:fail wifi not turned on',
|
|
48
|
+
errCode: 12005
|
|
49
|
+
}
|
|
50
|
+
fail(result)
|
|
55
51
|
complete(result)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
startWifiReady = true
|
|
55
|
+
const result = {
|
|
56
|
+
errMsg: 'startWifi:success'
|
|
56
57
|
}
|
|
58
|
+
success(result)
|
|
59
|
+
complete(result)
|
|
57
60
|
}).catch((err) => {
|
|
58
61
|
const result = {
|
|
59
62
|
errMsg: 'startWifi:fail ' + (typeof err === 'string' ? err : ''),
|
|
@@ -68,13 +71,14 @@ function stopWifi (options = {}) {
|
|
|
68
71
|
const { success = noop, fail = noop, complete = noop } = options
|
|
69
72
|
if (__mpx_mode__ === 'ios') {
|
|
70
73
|
const result = {
|
|
71
|
-
errMsg: '
|
|
74
|
+
errMsg: 'stopWifi:fail ios system not support, you need to manually go to the Settings to enable wifi'
|
|
72
75
|
}
|
|
73
76
|
fail(result)
|
|
74
77
|
complete(result)
|
|
75
78
|
return
|
|
76
79
|
}
|
|
77
|
-
|
|
80
|
+
startWifiReady = false
|
|
81
|
+
wifiListListeners.length = 0
|
|
78
82
|
const result = {
|
|
79
83
|
errMsg: 'stopWifi:success'
|
|
80
84
|
}
|
|
@@ -86,7 +90,7 @@ function getWifiList (options = {}) {
|
|
|
86
90
|
const { success = noop, fail = noop, complete = noop } = options
|
|
87
91
|
if (__mpx_mode__ === 'ios') {
|
|
88
92
|
const result = {
|
|
89
|
-
errMsg: '
|
|
93
|
+
errMsg: 'getWifiList:fail ios system not support'
|
|
90
94
|
}
|
|
91
95
|
fail(result)
|
|
92
96
|
complete(result)
|
|
@@ -94,26 +98,28 @@ function getWifiList (options = {}) {
|
|
|
94
98
|
}
|
|
95
99
|
if (!startWifiReady) {
|
|
96
100
|
const result = {
|
|
97
|
-
errMsg: '
|
|
101
|
+
errMsg: 'getWifiList:fail not init startWifi',
|
|
98
102
|
errCode: 12000
|
|
99
103
|
}
|
|
100
104
|
fail(result)
|
|
101
105
|
complete(result)
|
|
102
106
|
return
|
|
103
107
|
}
|
|
104
|
-
WifiManager
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
108
|
+
const WifiManager = require('react-native-wifi-reborn').default
|
|
109
|
+
WifiManager.reScanAndLoadWifiList().then((res) => {
|
|
110
|
+
const wifiList = res.map(item => {
|
|
111
|
+
return {
|
|
112
|
+
SSID: item.SSID,
|
|
113
|
+
BSSID: item.BSSID,
|
|
114
|
+
frequency: item.frequency,
|
|
115
|
+
signalStrength: 100 + (item.level || 0)
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
wifiListListeners.forEach(callback => {
|
|
119
|
+
if (type(callback) === 'Function') {
|
|
120
|
+
callback({ wifiList })
|
|
121
|
+
}
|
|
122
|
+
})
|
|
117
123
|
const result = {
|
|
118
124
|
errMsg: 'getWifiList:success',
|
|
119
125
|
errno: 0,
|
|
@@ -152,14 +158,14 @@ function getConnectedWifi (options = {}) {
|
|
|
152
158
|
|
|
153
159
|
if (!startWifiReady) {
|
|
154
160
|
const result = {
|
|
155
|
-
errMsg: '
|
|
161
|
+
errMsg: 'getConnectedWifi:fail not init startWifi',
|
|
156
162
|
errCode: 12000
|
|
157
163
|
}
|
|
158
164
|
fail(result)
|
|
159
165
|
complete(result)
|
|
160
166
|
return
|
|
161
167
|
}
|
|
162
|
-
|
|
168
|
+
const WifiManager = require('react-native-wifi-reborn').default
|
|
163
169
|
if (partialInfo) {
|
|
164
170
|
WifiManager.getCurrentWifiSSID().then((res) => {
|
|
165
171
|
const wifi = {
|
|
@@ -174,8 +180,7 @@ function getConnectedWifi (options = {}) {
|
|
|
174
180
|
}
|
|
175
181
|
success(result)
|
|
176
182
|
complete(result)
|
|
177
|
-
}).catch((
|
|
178
|
-
console.log(error)
|
|
183
|
+
}).catch(() => {
|
|
179
184
|
const result = {
|
|
180
185
|
errMsg: 'getConnectedWifi:fail'
|
|
181
186
|
}
|
package/src/platform/index.js
CHANGED