@mpxjs/api-proxy 2.10.15 → 2.10.16-beta.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.
@@ -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,111 @@
1
+ import { noop } from '@mpxjs/utils'
2
+
3
+ const qualityValue = {
4
+ high: 90,
5
+ normal: 75,
6
+ low: 50,
7
+ original: 100
8
+ }
9
+ export default class CreateCamera {
10
+ constructor () {
11
+ const navigation = Object.values(global.__mpxPagesMap || {})[0]?.[1]
12
+ this.camera = navigation?.camera || {}
13
+ }
14
+
15
+ setZoom (options = {}) {
16
+ const { zoom, success = noop, fail = noop, complete = noop } = options
17
+ if (this.camera.setZoom) {
18
+ this.camera.setZoom(zoom)
19
+ }
20
+ }
21
+ takePhoto (options = {}) {
22
+ const { success = noop, fail = noop, complete = noop } = options
23
+ const takePhoto = this.camera.getTakePhoto?.()
24
+ if (takePhoto) {
25
+ takePhoto({
26
+ quality: qualityValue[options.quality || 'normal']
27
+ }).then((res) => {
28
+ const result = {
29
+ errMsg: 'takePhoto:ok',
30
+ tempImagePath: res.path
31
+ }
32
+ success(result)
33
+ complete(result)
34
+ }).catch(() => {
35
+ const result = {
36
+ errMsg: 'takePhoto:fail'
37
+ }
38
+ fail(result)
39
+ complete(result)
40
+ })
41
+ }
42
+ }
43
+ startRecord (options = {}) {
44
+ let { timeout = 30, success = noop, fail = noop, complete = noop, timeoutCallback = noop } = options
45
+ timeout = timeout > 300 ? 300 : timeout
46
+ let recordTimer = null
47
+ let isTimeout = false
48
+ const startRecord = this.camera.getStartRecord?.()
49
+ if (startRecord) {
50
+ const result = {
51
+ errMsg: 'startRecord:ok'
52
+ }
53
+ success(result)
54
+ complete(result)
55
+ startRecord({
56
+ onRecordingError: (res) => {
57
+ clearTimeout(recordTimer)
58
+ timeoutCallback()
59
+ },
60
+ onRecordingFinished: (res) => {
61
+ if (isTimeout) {
62
+ console.log('record timeout, ignore', res)
63
+ }
64
+ clearTimeout(recordTimer)
65
+ console.log('record finished', res)
66
+ }
67
+ })
68
+ recordTimer = setTimeout(() => { // 超时自动停止
69
+ if (this.camera.stopRecord) {
70
+ this.camera.stopRecord().catch(() => {})
71
+ }
72
+ }, timeout * 1000)
73
+ } else {
74
+ const result = {
75
+ errMsg: 'startRecord:fail to initialize the camera'
76
+ }
77
+ fail(result)
78
+ complete(result)
79
+ }
80
+ }
81
+ stopRecord(options = {}) {
82
+ const { success = noop, fail = noop, complete = noop } = options
83
+ const stopRecord = this.camera.getStopRecord?.()
84
+ if (stopRecord) {
85
+ stopRecord().then((res) => {
86
+ console.log('stopRecord res', res)
87
+ const result = {
88
+ errMsg: 'stopRecord:ok',
89
+ tempVideoPath: res.path,
90
+ duration: res.duration * 1000, // 转成ms
91
+ size: res.fileSize
92
+ }
93
+ success(result)
94
+ complete(result)
95
+ }).catch((e) => {
96
+ console.log('stopRecord error', e)
97
+ const result = {
98
+ errMsg: 'stopRecord:fail'
99
+ }
100
+ fail(result)
101
+ complete(result)
102
+ })
103
+ } else {
104
+ const result = {
105
+ errMsg: 'stopRecord:fail to initialize the camera'
106
+ }
107
+ fail(result)
108
+ complete(result)
109
+ }
110
+ }
111
+ }
@@ -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,231 @@
1
+ import WifiManager from 'react-native-wifi-reborn'
2
+ import { PermissionsAndroid } from 'react-native'
3
+ import { noop } from '@mpxjs/utils'
4
+ import mpx from '@mpxjs/core'
5
+ let startWifiReady = false
6
+ const wifiListListeners = []
7
+
8
+ async function requestWifiPermission () {
9
+ const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, {
10
+ title: 'Location permission is required for WiFi connections',
11
+ message:
12
+ 'This app needs location permission as this is required ' +
13
+ 'to scan for wifi networks.',
14
+ buttonNegative: 'DENY',
15
+ buttonPositive: 'ALLOW'
16
+ })
17
+ if (granted === PermissionsAndroid.RESULTS.GRANTED) {
18
+ return true
19
+ } else {
20
+ return false
21
+ }
22
+ }
23
+
24
+ function startWifi (options = {}) {
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
+ startWifiReady = true
35
+ let wifiPermission = requestWifiPermission
36
+ if (mpx.rnConfig?.wifiPermission) {
37
+ wifiPermission = mpx.rnConfig.wifiPermission
38
+ }
39
+ wifiPermission().then(async () => {
40
+ let enabled
41
+ try {
42
+ enabled = await WifiManager.isEnabled()
43
+ } catch (e) {
44
+ enabled = false
45
+ }
46
+ const result = {
47
+ errMsg: 'startWifi:success'
48
+ }
49
+ if (!enabled) {
50
+ WifiManager.setEnabled(true)
51
+ success(result)
52
+ complete(result)
53
+ } else {
54
+ success(result)
55
+ complete(result)
56
+ }
57
+ }).catch((err) => {
58
+ const result = {
59
+ errMsg: 'startWifi:fail ' + (typeof err === 'string' ? err : ''),
60
+ errCode: 12001
61
+ }
62
+ fail(result)
63
+ complete(result)
64
+ })
65
+ }
66
+
67
+ function stopWifi (options = {}) {
68
+ const { success = noop, fail = noop, complete = noop } = options
69
+ if (__mpx_mode__ === 'ios') {
70
+ const result = {
71
+ errMsg: 'startWifi:fail ios system not support, you need to manually go to the Settings to enable wifi'
72
+ }
73
+ fail(result)
74
+ complete(result)
75
+ return
76
+ }
77
+ WifiManager.setEnabled(false)
78
+ const result = {
79
+ errMsg: 'stopWifi:success'
80
+ }
81
+ success(result)
82
+ complete(result)
83
+ }
84
+
85
+ function getWifiList (options = {}) {
86
+ const { success = noop, fail = noop, complete = noop } = options
87
+ if (__mpx_mode__ === 'ios') {
88
+ const result = {
89
+ errMsg: 'startWifi:fail ios system not support'
90
+ }
91
+ fail(result)
92
+ complete(result)
93
+ return
94
+ }
95
+ if (!startWifiReady) {
96
+ const result = {
97
+ errMsg: 'startWifi:fail not init startWifi',
98
+ errCode: 12000
99
+ }
100
+ fail(result)
101
+ complete(result)
102
+ return
103
+ }
104
+ WifiManager.loadWifiList().then((res) => {
105
+ if (wifiListListeners.length) {
106
+ const result = res.map(item => {
107
+ return {
108
+ SSID: item.SSID,
109
+ BSSID: item.BSSID,
110
+ frequency: item.frequency
111
+ }
112
+ })
113
+ wifiListListeners.forEach(callback => {
114
+ callback({ wifiList: result })
115
+ })
116
+ }
117
+ const result = {
118
+ errMsg: 'getWifiList:success',
119
+ errno: 0,
120
+ errCode: 0
121
+ }
122
+ success(result)
123
+ complete(result)
124
+ }).catch(() => {
125
+ const result = {
126
+ errMsg: 'getWifiList:fail'
127
+ }
128
+ fail(result)
129
+ complete(result)
130
+ })
131
+ }
132
+
133
+ function onGetWifiList (callback) {
134
+ if (!startWifiReady && wifiListListeners.indexOf(callback) > -1) {
135
+ return
136
+ }
137
+ wifiListListeners.push(callback)
138
+ }
139
+
140
+ function offGetWifiList (callback) {
141
+ if (!startWifiReady) {
142
+ return
143
+ }
144
+ const index = wifiListListeners.indexOf(callback)
145
+ if (index > -1) {
146
+ wifiListListeners.splice(index, 1)
147
+ }
148
+ }
149
+
150
+ function getConnectedWifi (options = {}) {
151
+ const { partialInfo = false, success = noop, fail = noop, complete = noop } = options
152
+
153
+ if (!startWifiReady) {
154
+ const result = {
155
+ errMsg: 'startWifi:fail not init startWifi',
156
+ errCode: 12000
157
+ }
158
+ fail(result)
159
+ complete(result)
160
+ return
161
+ }
162
+
163
+ if (partialInfo) {
164
+ WifiManager.getCurrentWifiSSID().then((res) => {
165
+ const wifi = {
166
+ SSID: res,
167
+ BSSID: '', // iOS无法获取BSSID
168
+ signalStrength: 0,
169
+ frequency: 0
170
+ }
171
+ const result = {
172
+ wifi: wifi,
173
+ errMsg: 'getConnectedWifi:ok'
174
+ }
175
+ success(result)
176
+ complete(result)
177
+ }).catch((error) => {
178
+ console.log(error)
179
+ const result = {
180
+ errMsg: 'getConnectedWifi:fail'
181
+ }
182
+ fail(result)
183
+ complete(result)
184
+ })
185
+ } else {
186
+ Promise.all([
187
+ WifiManager.getCurrentWifiSSID().catch(() => null),
188
+ WifiManager.getBSSID().catch(() => ''),
189
+ WifiManager.getCurrentSignalStrength().catch(() => 0),
190
+ WifiManager.getFrequency().catch(() => 0)
191
+ ]).then(([ssid, bssid, signalStrength, frequency]) => {
192
+ if (!ssid) {
193
+ const result = {
194
+ errMsg: 'getConnectedWifi:fail'
195
+ }
196
+ fail(result)
197
+ complete(result)
198
+ return
199
+ }
200
+
201
+ const wifi = {
202
+ SSID: ssid,
203
+ BSSID: bssid,
204
+ signalStrength: signalStrength,
205
+ frequency: frequency
206
+ }
207
+
208
+ const result = {
209
+ wifi: wifi,
210
+ errMsg: 'getConnectedWifi:ok'
211
+ }
212
+ success(result)
213
+ complete(result)
214
+ }).catch(() => {
215
+ const result = {
216
+ errMsg: 'getConnectedWifi:fail'
217
+ }
218
+ fail(result)
219
+ complete(result)
220
+ })
221
+ }
222
+ }
223
+
224
+ export {
225
+ startWifi,
226
+ stopWifi,
227
+ getWifiList,
228
+ onGetWifiList,
229
+ offGetWifiList,
230
+ getConnectedWifi
231
+ }
@@ -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'