@mpxjs/api-proxy 2.10.15 → 2.10.16-beta.10

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.
@@ -6,8 +6,71 @@ const createBLEConnection = ENV_OBJ.createBLEConnection || envError('createBLECo
6
6
 
7
7
  const onBLEConnectionStateChange = ENV_OBJ.onBLEConnectionStateChange || envError('onBLEConnectionStateChange')
8
8
 
9
+ const offBLEConnectionStateChange = ENV_OBJ.offBLEConnectionStateChange || envError('offBLEConnectionStateChange')
10
+
11
+ const openBluetoothAdapter = ENV_OBJ.openBluetoothAdapter || envError('openBluetoothAdapter')
12
+
13
+ const closeBluetoothAdapter = ENV_OBJ.closeBluetoothAdapter || envError('closeBluetoothAdapter')
14
+
15
+ const startBluetoothDevicesDiscovery = ENV_OBJ.startBluetoothDevicesDiscovery || envError('startBluetoothDevicesDiscovery')
16
+
17
+ const stopBluetoothDevicesDiscovery = ENV_OBJ.stopBluetoothDevicesDiscovery || envError('stopBluetoothDevicesDiscovery')
18
+
19
+ const onBluetoothDeviceFound = ENV_OBJ.onBluetoothDeviceFound || envError('onBluetoothDeviceFound')
20
+
21
+ const offBluetoothDeviceFound = ENV_OBJ.offBluetoothDeviceFound || envError('offBluetoothDeviceFound')
22
+
23
+ const getConnectedBluetoothDevices = ENV_OBJ.getConnectedBluetoothDevices || envError('getConnectedBluetoothDevices')
24
+
25
+ const getBluetoothAdapterState = ENV_OBJ.getBluetoothAdapterState || envError('getBluetoothAdapterState')
26
+
27
+ const onBluetoothAdapterStateChange = ENV_OBJ.onBluetoothAdapterStateChange || envError('onBluetoothAdapterStateChange')
28
+
29
+ const offBluetoothAdapterStateChange = ENV_OBJ.offBluetoothAdapterStateChange || envError('offBluetoothAdapterStateChange')
30
+
31
+ const getBluetoothDevices = ENV_OBJ.getBluetoothDevices || envError('getBluetoothDevices')
32
+
33
+ const writeBLECharacteristicValue = ENV_OBJ.writeBLECharacteristicValue || envError('writeBLECharacteristicValue')
34
+
35
+ const readBLECharacteristicValue = ENV_OBJ.readBLECharacteristicValue || envError('readBLECharacteristicValue')
36
+
37
+ const notifyBLECharacteristicValueChange = ENV_OBJ.notifyBLECharacteristicValueChange || envError('notifyBLECharacteristicValueChange')
38
+
39
+ const onBLECharacteristicValueChange = ENV_OBJ.onBLECharacteristicValueChange || envError('onBLECharacteristicValueChange')
40
+
41
+ const offBLECharacteristicValueChange = ENV_OBJ.offBLECharacteristicValueChange || envError('offBLECharacteristicValueChange')
42
+
43
+ const setBLEMTU = ENV_OBJ.setBLEMTU || envError('setBLEMTU')
44
+
45
+ const getBLEDeviceRSSI = ENV_OBJ.getBLEDeviceRSSI || envError('getBLEDeviceRSSI')
46
+
47
+ const getBLEDeviceServices = ENV_OBJ.getBLEDeviceServices || envError('getBLEDeviceServices')
48
+
49
+ const getBLEDeviceCharacteristics = ENV_OBJ.getBLEDeviceCharacteristics || envError('getBLEDeviceCharacteristics')
50
+
9
51
  export {
10
- closeBLEConnection,
52
+ onBLEConnectionStateChange,
53
+ offBLEConnectionStateChange,
54
+ openBluetoothAdapter,
55
+ closeBluetoothAdapter,
56
+ startBluetoothDevicesDiscovery,
57
+ stopBluetoothDevicesDiscovery,
58
+ onBluetoothDeviceFound,
59
+ offBluetoothDeviceFound,
60
+ getConnectedBluetoothDevices,
61
+ getBluetoothAdapterState,
62
+ onBluetoothAdapterStateChange,
63
+ offBluetoothAdapterStateChange,
64
+ getBluetoothDevices,
65
+ writeBLECharacteristicValue,
66
+ readBLECharacteristicValue,
67
+ notifyBLECharacteristicValueChange,
68
+ onBLECharacteristicValueChange,
69
+ offBLECharacteristicValueChange,
70
+ setBLEMTU,
71
+ getBLEDeviceRSSI,
72
+ getBLEDeviceServices,
73
+ getBLEDeviceCharacteristics,
11
74
  createBLEConnection,
12
- onBLEConnectionStateChange
75
+ closeBLEConnection
13
76
  }
@@ -0,0 +1,9 @@
1
+ import CreateCamera from './rnCamera'
2
+
3
+ function createCameraContext () {
4
+ return new CreateCamera()
5
+ }
6
+
7
+ export {
8
+ createCameraContext
9
+ }
@@ -0,0 +1,7 @@
1
+ import { ENV_OBJ, envError } from '../../../common/js'
2
+
3
+ const createCameraContext = ENV_OBJ.createCameraContext || envError('createCameraContext')
4
+
5
+ export {
6
+ createCameraContext
7
+ }
@@ -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
+ }
@@ -5,10 +5,10 @@ const oldObserveList = new Set()
5
5
 
6
6
  if (isBrowser) {
7
7
  window.addEventListener('offline', () => {
8
- oldObserveList.forEach(fn => fn({ isConnected: false, type: 'none' }))
8
+ oldObserveList.forEach(fn => fn({ isConnected: false, networkType: 'none' }))
9
9
  })
10
10
  window.addEventListener('online', () => {
11
- oldObserveList.forEach(fn => fn({ isConnected: true, type: 'unknow' }))
11
+ oldObserveList.forEach(fn => fn({ isConnected: true, networkType: 'unknow' }))
12
12
  })
13
13
  }
14
14
 
@@ -22,7 +22,7 @@ export function onNetworkStatusChange (callbackFn) {
22
22
  const isConnected = navigator.onLine
23
23
  callbackFn({
24
24
  isConnected,
25
- type: isConnected ? evt.currentTarget.effectiveType : 'none'
25
+ networkType: isConnected ? evt.currentTarget.effectiveType : 'none'
26
26
  })
27
27
  }
28
28
  fnMap.set(callbackFn, proxyCallback)
@@ -0,0 +1,236 @@
1
+ import { PermissionsAndroid } from 'react-native'
2
+ import { noop, type } from '@mpxjs/utils'
3
+ import mpx from '@mpxjs/core'
4
+ let startWifiReady = false
5
+ const wifiListListeners = []
6
+
7
+ async function requestWifiPermission () {
8
+ const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, {
9
+ title: 'Location permission is required for WiFi connections',
10
+ message:
11
+ 'This app needs location permission as this is required ' +
12
+ 'to scan for wifi networks.',
13
+ buttonNegative: 'DENY',
14
+ buttonPositive: 'ALLOW'
15
+ })
16
+ if (granted === PermissionsAndroid.RESULTS.GRANTED) {
17
+ return true
18
+ } else {
19
+ return false
20
+ }
21
+ }
22
+
23
+ function startWifi (options = {}) {
24
+ const WifiManager = require('react-native-wifi-reborn').default
25
+ const { success = noop, fail = noop, complete = noop } = options
26
+ if (__mpx_mode__ === 'ios') {
27
+ const result = {
28
+ errMsg: 'startWifi:fail ios system not support, you need to manually go to the Settings to enable wifi'
29
+ }
30
+ fail(result)
31
+ complete(result)
32
+ return
33
+ }
34
+ let wifiPermission = requestWifiPermission
35
+ if (mpx.config?.rnConfig?.wifiPermission) {
36
+ wifiPermission = mpx.config.rnConfig.wifiPermission
37
+ }
38
+ wifiPermission().then(async () => {
39
+ let enabled
40
+ try {
41
+ enabled = await WifiManager.isEnabled()
42
+ } catch (e) {
43
+ enabled = false
44
+ }
45
+ if (!enabled) {
46
+ const result = {
47
+ errMsg: 'startWifi:fail wifi not turned on',
48
+ errCode: 12005
49
+ }
50
+ fail(result)
51
+ complete(result)
52
+ return
53
+ }
54
+ startWifiReady = true
55
+ const result = {
56
+ errMsg: 'startWifi:success'
57
+ }
58
+ success(result)
59
+ complete(result)
60
+ }).catch((err) => {
61
+ const result = {
62
+ errMsg: 'startWifi:fail ' + (typeof err === 'string' ? err : ''),
63
+ errCode: 12001
64
+ }
65
+ fail(result)
66
+ complete(result)
67
+ })
68
+ }
69
+
70
+ function stopWifi (options = {}) {
71
+ const { success = noop, fail = noop, complete = noop } = options
72
+ if (__mpx_mode__ === 'ios') {
73
+ const result = {
74
+ errMsg: 'startWifi:fail ios system not support, you need to manually go to the Settings to enable wifi'
75
+ }
76
+ fail(result)
77
+ complete(result)
78
+ return
79
+ }
80
+ startWifiReady = false
81
+ const result = {
82
+ errMsg: 'stopWifi:success'
83
+ }
84
+ success(result)
85
+ complete(result)
86
+ }
87
+
88
+ function getWifiList (options = {}) {
89
+ const WifiManager = require('react-native-wifi-reborn').default
90
+ const { success = noop, fail = noop, complete = noop } = options
91
+ if (__mpx_mode__ === 'ios') {
92
+ const result = {
93
+ errMsg: 'startWifi:fail ios system not support'
94
+ }
95
+ fail(result)
96
+ complete(result)
97
+ return
98
+ }
99
+ if (!startWifiReady) {
100
+ const result = {
101
+ errMsg: 'startWifi:fail not init startWifi',
102
+ errCode: 12000
103
+ }
104
+ fail(result)
105
+ complete(result)
106
+ return
107
+ }
108
+ WifiManager.reScanAndLoadWifiList().then((res) => {
109
+ const wifiList = res.map(item => {
110
+ return {
111
+ SSID: item.SSID,
112
+ BSSID: item.BSSID,
113
+ frequency: item.frequency,
114
+ signalStrength: 100 + (item.level || 0)
115
+ }
116
+ })
117
+ wifiListListeners.forEach(callback => {
118
+ if (type(callback) === 'Function') {
119
+ callback({ wifiList })
120
+ }
121
+ })
122
+ const result = {
123
+ errMsg: 'getWifiList:success',
124
+ errno: 0,
125
+ errCode: 0
126
+ }
127
+ success(result)
128
+ complete(result)
129
+ }).catch(() => {
130
+ const result = {
131
+ errMsg: 'getWifiList:fail'
132
+ }
133
+ fail(result)
134
+ complete(result)
135
+ })
136
+ }
137
+
138
+ function onGetWifiList (callback) {
139
+ if (!startWifiReady && wifiListListeners.indexOf(callback) > -1) {
140
+ return
141
+ }
142
+ wifiListListeners.push(callback)
143
+ }
144
+
145
+ function offGetWifiList (callback) {
146
+ if (!startWifiReady) {
147
+ return
148
+ }
149
+ const index = wifiListListeners.indexOf(callback)
150
+ if (index > -1) {
151
+ wifiListListeners.splice(index, 1)
152
+ }
153
+ }
154
+
155
+ function getConnectedWifi (options = {}) {
156
+ const WifiManager = require('react-native-wifi-reborn').default
157
+ const { partialInfo = false, success = noop, fail = noop, complete = noop } = options
158
+
159
+ if (!startWifiReady) {
160
+ const result = {
161
+ errMsg: 'startWifi:fail not init startWifi',
162
+ errCode: 12000
163
+ }
164
+ fail(result)
165
+ complete(result)
166
+ return
167
+ }
168
+
169
+ if (partialInfo) {
170
+ WifiManager.getCurrentWifiSSID().then((res) => {
171
+ const wifi = {
172
+ SSID: res,
173
+ BSSID: '', // iOS无法获取BSSID
174
+ signalStrength: 0,
175
+ frequency: 0
176
+ }
177
+ const result = {
178
+ wifi: wifi,
179
+ errMsg: 'getConnectedWifi:ok'
180
+ }
181
+ success(result)
182
+ complete(result)
183
+ }).catch(() => {
184
+ const result = {
185
+ errMsg: 'getConnectedWifi:fail'
186
+ }
187
+ fail(result)
188
+ complete(result)
189
+ })
190
+ } else {
191
+ Promise.all([
192
+ WifiManager.getCurrentWifiSSID().catch(() => null),
193
+ WifiManager.getBSSID().catch(() => ''),
194
+ WifiManager.getCurrentSignalStrength().catch(() => 0),
195
+ WifiManager.getFrequency().catch(() => 0)
196
+ ]).then(([ssid, bssid, signalStrength, frequency]) => {
197
+ if (!ssid) {
198
+ const result = {
199
+ errMsg: 'getConnectedWifi:fail'
200
+ }
201
+ fail(result)
202
+ complete(result)
203
+ return
204
+ }
205
+
206
+ const wifi = {
207
+ SSID: ssid,
208
+ BSSID: bssid,
209
+ signalStrength: signalStrength,
210
+ frequency: frequency
211
+ }
212
+
213
+ const result = {
214
+ wifi: wifi,
215
+ errMsg: 'getConnectedWifi:ok'
216
+ }
217
+ success(result)
218
+ complete(result)
219
+ }).catch(() => {
220
+ const result = {
221
+ errMsg: 'getConnectedWifi:fail'
222
+ }
223
+ fail(result)
224
+ complete(result)
225
+ })
226
+ }
227
+ }
228
+
229
+ export {
230
+ startWifi,
231
+ stopWifi,
232
+ getWifiList,
233
+ onGetWifiList,
234
+ offGetWifiList,
235
+ getConnectedWifi
236
+ }
@@ -0,0 +1,22 @@
1
+ import { ENV_OBJ, envError } from '../../../../common/js'
2
+
3
+ const startWifi = ENV_OBJ.startWifi || envError('startWifi')
4
+
5
+ const stopWifi = ENV_OBJ.stopWifi || envError('stopWifi')
6
+
7
+ const getWifiList = ENV_OBJ.getWifiList || envError('getWifiList')
8
+
9
+ const getConnectedWifi = ENV_OBJ.getConnectedWifi || envError('getConnectedWifi')
10
+
11
+ const onGetWifiList = ENV_OBJ.onGetWifiList || envError('onGetWifiList')
12
+
13
+ const offGetWifiList = ENV_OBJ.offGetWifiList || envError('offGetWifiList')
14
+
15
+ export {
16
+ startWifi,
17
+ stopWifi,
18
+ getWifiList,
19
+ onGetWifiList,
20
+ offGetWifiList,
21
+ getConnectedWifi
22
+ }
@@ -11,7 +11,7 @@ const getSystemInfoSync = function () {
11
11
  brand: DeviceInfo.getBrand(),
12
12
  model: DeviceInfo.getModel(),
13
13
  system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
14
- platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
14
+ platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName().toLowerCase(),
15
15
  deviceOrientation: screenWidth > screenHeight ? 'portrait' : 'landscape',
16
16
  fontSizeSetting: PixelRatio.getFontScale()
17
17
  }
@@ -68,7 +68,7 @@ const getDeviceInfo = function () {
68
68
  brand: DeviceInfo.getBrand(),
69
69
  model: DeviceInfo.getModel(),
70
70
  system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
71
- platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
71
+ platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName().toLowerCase(),
72
72
  memorySize: DeviceInfo.getTotalMemorySync() / (1024 * 1024)
73
73
  })
74
74
  return deviceInfo
@@ -9,10 +9,10 @@ const getWindowInfo = function () {
9
9
  const navigationInsets = navigation.insets || {}
10
10
  const insets = Object.assign({}, initialWindowMetricsInset, navigationInsets)
11
11
  let safeArea = {}
12
- const { top = 0, bottom = 0, left = 0, right = 0 } = insets
13
- const screenHeight = __mpx_mode__ === 'ios' ? dimensionsScreen.height : dimensionsScreen.height - bottom // 解决安卓开启屏幕内三建导航安卓把安全区计算进去后产生的影响
14
- const screenWidth = __mpx_mode__ === 'ios' ? dimensionsScreen.width : dimensionsScreen.width - right
12
+ const { top = 0, left = 0, bottom = 0, right = 0 } = insets
15
13
  const layout = navigation.layout || {}
14
+ const screenHeight = __mpx_mode__ === 'ios' ? dimensionsScreen.height : dimensionsScreen.height - (layout.bottomVirtualHeight || 0) // 解决安卓开启屏幕内导航安卓把安全区计算进去后产生的影响
15
+ const screenWidth = __mpx_mode__ === 'ios' ? dimensionsScreen.width : dimensionsScreen.width - right
16
16
  const layoutHeight = layout.height || 0
17
17
  const layoutWidth = layout.width || 0
18
18
  const windowHeight = layoutHeight || screenHeight
@@ -37,6 +37,9 @@ export * from './api/create-selector-query'
37
37
  // getNetworkType, onNetworkStatusChange, offNetworkStatusChange
38
38
  export * from './api/device/network'
39
39
 
40
+ // startWifi, stopWifi, getWifiList, onGetWifiList, offGetWifiList, getConnectedWifi
41
+ export * from './api/device/wifi'
42
+
40
43
  // downloadFile, uploadFile
41
44
  export * from './api/file'
42
45
 
@@ -119,3 +122,6 @@ export * from './api/keyboard'
119
122
 
120
123
  // getSetting, openSetting, enableAlertBeforeUnload, disableAlertBeforeUnload, getMenuButtonBoundingClientRect
121
124
  export * from './api/setting'
125
+
126
+ // createCameraContext
127
+ export * from './api/camera'