@mpxjs/api-proxy 2.10.16-beta.7 → 2.10.17

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.
@@ -1,9 +0,0 @@
1
- import CreateCamera from './rnCamera'
2
-
3
- function createCameraContext () {
4
- return new CreateCamera()
5
- }
6
-
7
- export {
8
- createCameraContext
9
- }
@@ -1,7 +0,0 @@
1
- import { ENV_OBJ, envError } from '../../../common/js'
2
-
3
- const createCameraContext = ENV_OBJ.createCameraContext || envError('createCameraContext')
4
-
5
- export {
6
- createCameraContext
7
- }
@@ -1,114 +0,0 @@
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 } = options
17
- if (this.camera.setZoom) {
18
- this.camera.setZoom(zoom)
19
- }
20
- }
21
-
22
- takePhoto (options = {}) {
23
- const { success = noop, fail = noop, complete = noop } = options
24
- const takePhoto = this.camera.getTakePhoto?.()
25
- if (takePhoto) {
26
- takePhoto({
27
- quality: qualityValue[options.quality || 'normal']
28
- }).then((res) => {
29
- const result = {
30
- errMsg: 'takePhoto:ok',
31
- tempImagePath: res.path
32
- }
33
- success(result)
34
- complete(result)
35
- }).catch(() => {
36
- const result = {
37
- errMsg: 'takePhoto:fail'
38
- }
39
- fail(result)
40
- complete(result)
41
- })
42
- }
43
- }
44
-
45
- startRecord (options = {}) {
46
- let { timeout = 30, success = noop, fail = noop, complete = noop, timeoutCallback = noop } = options
47
- timeout = timeout > 300 ? 300 : timeout
48
- let recordTimer = null
49
- const isTimeout = false
50
- const startRecord = this.camera.getStartRecord?.()
51
- if (startRecord) {
52
- const result = {
53
- errMsg: 'startRecord:ok'
54
- }
55
- success(result)
56
- complete(result)
57
- startRecord({
58
- onRecordingError: (res) => {
59
- clearTimeout(recordTimer)
60
- timeoutCallback()
61
- },
62
- onRecordingFinished: (res) => {
63
- if (isTimeout) {
64
- console.log('record timeout, ignore', res)
65
- }
66
- clearTimeout(recordTimer)
67
- console.log('record finished', res)
68
- }
69
- })
70
- recordTimer = setTimeout(() => { // 超时自动停止
71
- if (this.camera.stopRecord) {
72
- this.camera.stopRecord().catch(() => {})
73
- }
74
- }, timeout * 1000)
75
- } else {
76
- const result = {
77
- errMsg: 'startRecord:fail to initialize the camera'
78
- }
79
- fail(result)
80
- complete(result)
81
- }
82
- }
83
-
84
- stopRecord (options = {}) {
85
- const { success = noop, fail = noop, complete = noop } = options
86
- const stopRecord = this.camera.getStopRecord?.()
87
- if (stopRecord) {
88
- stopRecord().then((res) => {
89
- console.log('stopRecord res', res)
90
- const result = {
91
- errMsg: 'stopRecord:ok',
92
- tempVideoPath: res.path,
93
- duration: res.duration * 1000, // 转成ms
94
- size: res.fileSize
95
- }
96
- success(result)
97
- complete(result)
98
- }).catch((e) => {
99
- console.log('stopRecord error', e)
100
- const result = {
101
- errMsg: 'stopRecord:fail'
102
- }
103
- fail(result)
104
- complete(result)
105
- })
106
- } else {
107
- const result = {
108
- errMsg: 'stopRecord:fail to initialize the camera'
109
- }
110
- fail(result)
111
- complete(result)
112
- }
113
- }
114
- }
@@ -1,231 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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
- }