@mpxjs/api-proxy 2.10.17-beta.1 → 2.10.17-beta.13

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
+ }
@@ -201,6 +201,9 @@ class RNIntersectionObserver {
201
201
 
202
202
  // 计算节点的rect信息
203
203
  _measureTarget (isInit = false) {
204
+ if (!this.observerRefs || !this.relativeRef) {
205
+ return
206
+ }
204
207
  Promise.all([
205
208
  this._getReferenceRect(this.observerRefs),
206
209
  this._getReferenceRect(this.relativeRef)
@@ -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 { success = noop, fail = noop, complete = noop } = options
25
+ if (__mpx_mode__ === 'ios') {
26
+ const result = {
27
+ errMsg: 'startWifi:fail ios system not support, you need to manually go to the Settings to enable wifi'
28
+ }
29
+ fail(result)
30
+ complete(result)
31
+ return
32
+ }
33
+ const WifiManager = require('react-native-wifi-reborn').default
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: 'stopWifi: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
+ wifiListListeners.length = 0
82
+ const result = {
83
+ errMsg: 'stopWifi:success'
84
+ }
85
+ success(result)
86
+ complete(result)
87
+ }
88
+
89
+ function getWifiList (options = {}) {
90
+ const { success = noop, fail = noop, complete = noop } = options
91
+ if (__mpx_mode__ === 'ios') {
92
+ const result = {
93
+ errMsg: 'getWifiList:fail ios system not support'
94
+ }
95
+ fail(result)
96
+ complete(result)
97
+ return
98
+ }
99
+ if (!startWifiReady) {
100
+ const result = {
101
+ errMsg: 'getWifiList:fail not init startWifi',
102
+ errCode: 12000
103
+ }
104
+ fail(result)
105
+ complete(result)
106
+ return
107
+ }
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
+ })
123
+ const result = {
124
+ errMsg: 'getWifiList:success',
125
+ errno: 0,
126
+ errCode: 0
127
+ }
128
+ success(result)
129
+ complete(result)
130
+ }).catch(() => {
131
+ const result = {
132
+ errMsg: 'getWifiList:fail'
133
+ }
134
+ fail(result)
135
+ complete(result)
136
+ })
137
+ }
138
+
139
+ function onGetWifiList (callback) {
140
+ if (!startWifiReady && wifiListListeners.indexOf(callback) > -1) {
141
+ return
142
+ }
143
+ wifiListListeners.push(callback)
144
+ }
145
+
146
+ function offGetWifiList (callback) {
147
+ if (!startWifiReady) {
148
+ return
149
+ }
150
+ const index = wifiListListeners.indexOf(callback)
151
+ if (index > -1) {
152
+ wifiListListeners.splice(index, 1)
153
+ }
154
+ }
155
+
156
+ function getConnectedWifi (options = {}) {
157
+ const { partialInfo = false, success = noop, fail = noop, complete = noop } = options
158
+
159
+ if (!startWifiReady) {
160
+ const result = {
161
+ errMsg: 'getConnectedWifi:fail not init startWifi',
162
+ errCode: 12000
163
+ }
164
+ fail(result)
165
+ complete(result)
166
+ return
167
+ }
168
+ const WifiManager = require('react-native-wifi-reborn').default
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
+ }
@@ -22,13 +22,18 @@ const getImageInfo = function (options = {}) {
22
22
  failHandle(result, fail, complete)
23
23
  return
24
24
  }
25
+ let path = ''
26
+ if (src.toLowerCase().startsWith('http')) {
27
+ path = src
28
+ }
25
29
  Image.getSize(src, (width, height) => {
26
30
  const result = {
27
31
  errMsg: 'getImageInfo:ok',
28
32
  width,
29
- height
33
+ height,
34
+ path
30
35
  }
31
- defineUnsupportedProps(result, ['path', 'orientation', 'type'])
36
+ defineUnsupportedProps(result, ['orientation', 'type'])
32
37
  successHandle(result, success, complete)
33
38
  }, (err) => {
34
39
  const result = {
@@ -43,7 +43,7 @@ function navigateTo (options = {}) {
43
43
  if (options.events) {
44
44
  eventChannel._addListeners(options.events)
45
45
  }
46
- const { path, queryObj } = parseUrl(options.url)
46
+ const { path, queryObj } = parseUrl(options.url, true)
47
47
  const basePath = getBasePath(navigation)
48
48
  const finalPath = resolvePath(path, basePath).slice(1)
49
49
 
@@ -70,7 +70,7 @@ function redirectTo (options = {}) {
70
70
  return
71
71
  }
72
72
  if (navigation && navigationHelper) {
73
- const { path, queryObj } = parseUrl(options.url)
73
+ const { path, queryObj } = parseUrl(options.url, true)
74
74
  const basePath = getBasePath(navigation)
75
75
  const finalPath = resolvePath(path, basePath).slice(1)
76
76
  navigation.replace(finalPath, queryObj)
@@ -104,8 +104,10 @@ function navigateBack (options = {}) {
104
104
  }
105
105
  if (delta >= routeLength && global.__mpx?.config.rnConfig.onAppBack?.(delta - routeLength + 1)) {
106
106
  nextTick(() => {
107
- navigationHelper.lastSuccessCallback()
108
- navigationHelper.lastSuccessCallback = null
107
+ if (navigationHelper.lastSuccessCallback) {
108
+ navigationHelper.lastSuccessCallback()
109
+ navigationHelper.lastSuccessCallback = null
110
+ }
109
111
  })
110
112
  } else {
111
113
  navigation.pop(delta)
@@ -120,7 +122,7 @@ function reLaunch (options = {}) {
120
122
  return
121
123
  }
122
124
  if (navigation && navigationHelper) {
123
- const { path, queryObj } = parseUrl(options.url)
125
+ const { path, queryObj } = parseUrl(options.url, true)
124
126
  const basePath = getBasePath(navigation)
125
127
  const finalPath = resolvePath(path, basePath).slice(1)
126
128
  navigation.reset({
@@ -0,0 +1,36 @@
1
+ import { getWindowInfo } from '../system/rnSystem'
2
+
3
+ /**
4
+ * RN 平台模拟胶囊按钮的布局位置
5
+ * 由于 RN 应用没有微信的右上角胶囊按钮,这里返回一个基于屏幕尺寸和安全区计算的模拟值
6
+ * 主要用于保持代码兼容性,让开发者可以获取顶部导航区域的参考尺寸
7
+ */
8
+ const getMenuButtonBoundingClientRect = function () {
9
+ const windowInfo = getWindowInfo()
10
+ const { screenWidth, statusBarHeight } = windowInfo
11
+
12
+ // 微信小程序胶囊按钮的典型尺寸
13
+ const CAPSULE_WIDTH = 87 // 胶囊宽度
14
+ const CAPSULE_HEIGHT = 32 // 胶囊高度
15
+ const MARGIN_RIGHT = 7 // 距离右边距离
16
+ const MARGIN_TOP = 4 // 状态栏下方的间距
17
+
18
+ // 计算胶囊按钮的位置
19
+ const top = statusBarHeight + MARGIN_TOP
20
+ const right = screenWidth - MARGIN_RIGHT
21
+ const left = right - CAPSULE_WIDTH
22
+ const bottom = top + CAPSULE_HEIGHT
23
+
24
+ return {
25
+ width: CAPSULE_WIDTH,
26
+ height: CAPSULE_HEIGHT,
27
+ top,
28
+ right,
29
+ bottom,
30
+ left
31
+ }
32
+ }
33
+
34
+ export {
35
+ getMenuButtonBoundingClientRect
36
+ }
@@ -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'