@mpxjs/api-proxy 2.9.40 → 2.9.41
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 +26 -2
- package/src/common/js/utils.js +22 -2
- package/src/platform/api/base/index.android.js +1 -0
- package/src/platform/api/base/index.ios.js +1 -0
- package/src/platform/api/canvas/index.ali.js +1 -0
- package/src/platform/api/clipboard-data/index.android.js +1 -0
- package/src/platform/api/clipboard-data/index.ios.js +1 -0
- package/src/platform/api/clipboard-data/rnClipboard.js +41 -0
- package/src/platform/api/device/network/index.android.js +1 -0
- package/src/platform/api/device/network/index.ios.js +1 -0
- package/src/platform/api/device/network/rnNetwork.js +59 -0
- package/src/platform/api/make-phone-call/index.andriod.js +1 -0
- package/src/platform/api/make-phone-call/index.ios.js +1 -0
- package/src/platform/api/make-phone-call/rnMakePhone.js +27 -0
- package/src/platform/api/request/index.android.js +1 -0
- package/src/platform/api/request/index.ios.js +1 -0
- package/src/platform/api/request/index.web.js +2 -1
- package/src/platform/api/route/index.android.js +1 -0
- package/src/platform/api/route/index.ios.js +109 -0
- package/src/platform/api/route/index.web.js +4 -4
- package/src/platform/api/socket/SocketTask.js +15 -5
- package/src/platform/api/socket/index.andriod.js +1 -0
- package/src/platform/api/socket/index.ios.js +1 -0
- package/src/platform/api/storage/index.android.js +1 -0
- package/src/platform/api/storage/index.ios.js +1 -0
- package/src/platform/api/storage/rnStorage.js +138 -0
- package/src/platform/api/system/index.ali.js +8 -2
- package/src/platform/api/system/index.android.js +1 -0
- package/src/platform/api/system/index.ios.js +1 -0
- package/src/platform/api/system/index.js +7 -1
- package/src/platform/api/system/index.web.js +8 -2
- package/src/platform/api/system/rnSystem.js +118 -0
- package/src/platform/api/window/index.android.js +1 -0
- package/src/platform/api/window/index.ios.js +1 -0
- package/src/platform/api/window/rnWindow.js +44 -0
- /package/src/platform/api/{route/event-channel.js → event-channel/index.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/api-proxy",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.41",
|
|
4
4
|
"description": "convert miniprogram API at each end",
|
|
5
5
|
"module": "src/index.js",
|
|
6
6
|
"types": "@types/index.d.ts",
|
|
@@ -39,5 +39,29 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"axios": "^1.6.7"
|
|
41
41
|
},
|
|
42
|
-
"
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@react-native-async-storage/async-storage": "^1.23.1",
|
|
44
|
+
"@react-native-clipboard/clipboard": "^1.14.0",
|
|
45
|
+
"@react-native-community/netinfo": "^11.2.1",
|
|
46
|
+
"react-native-device-info": "^10.13.2",
|
|
47
|
+
"react-native-safe-area-context": "^4.10.1"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"@react-native-async-storage/async-storage": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"@react-native-clipboard/clipboard": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"@react-native-community/netinfo": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"react-native-device-info": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
62
|
+
"react-native-safe-area-context": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"gitHead": "0b3ee5d2c1b6c6e0af6a842eb4e12f4a1173c067"
|
|
43
67
|
}
|
package/src/common/js/utils.js
CHANGED
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
*/
|
|
15
15
|
const hasOwnProperty = Object.prototype.hasOwnProperty
|
|
16
16
|
|
|
17
|
+
function type (n) {
|
|
18
|
+
return Object.prototype.toString.call(n).slice(8, -1)
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
function hasOwn (obj, key) {
|
|
18
22
|
return hasOwnProperty.call(obj, key)
|
|
19
23
|
}
|
|
@@ -68,6 +72,8 @@ function getEnvObj () {
|
|
|
68
72
|
case 'dd':
|
|
69
73
|
return dd
|
|
70
74
|
case 'web':
|
|
75
|
+
case 'ios':
|
|
76
|
+
case 'android':
|
|
71
77
|
return {}
|
|
72
78
|
}
|
|
73
79
|
}
|
|
@@ -79,7 +85,6 @@ function warn (msg) {
|
|
|
79
85
|
function error (msg) {
|
|
80
86
|
console.error && console.error(`[@mpxjs/api-proxy error]:\n ${msg}`)
|
|
81
87
|
}
|
|
82
|
-
|
|
83
88
|
function envError (method) {
|
|
84
89
|
return () => {
|
|
85
90
|
console.error && console.error(`[@mpxjs/api-proxy error]:\n ${__mpx_mode__}环境不支持${method}方法`)
|
|
@@ -110,6 +115,19 @@ function parseDataset (dataset) {
|
|
|
110
115
|
return parsed
|
|
111
116
|
}
|
|
112
117
|
|
|
118
|
+
function defineUnsupportedProps (resObj, props) {
|
|
119
|
+
const defineProps = {}
|
|
120
|
+
props.forEach((item) => {
|
|
121
|
+
defineProps[item] = {
|
|
122
|
+
get () {
|
|
123
|
+
warn(`The ${item} attribute is not supported in ${__mpx_mode__} environment`)
|
|
124
|
+
return null
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
Object.defineProperties(resObj, defineProps)
|
|
129
|
+
}
|
|
130
|
+
|
|
113
131
|
const isBrowser = typeof window !== 'undefined'
|
|
114
132
|
|
|
115
133
|
function throwSSRWarning (info) {
|
|
@@ -131,5 +149,7 @@ export {
|
|
|
131
149
|
hasOwn,
|
|
132
150
|
throwSSRWarning,
|
|
133
151
|
ENV_OBJ,
|
|
134
|
-
parseDataset
|
|
152
|
+
parseDataset,
|
|
153
|
+
type,
|
|
154
|
+
defineUnsupportedProps
|
|
135
155
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.web'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.web'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnClipboard'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnClipboard'
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Clipboard from '@react-native-clipboard/clipboard'
|
|
2
|
+
import { webHandleSuccess, webHandleFail } from '../../../common/js/web'
|
|
3
|
+
import { type } from '@mpxjs/utils'
|
|
4
|
+
const setClipboardData = function (options) {
|
|
5
|
+
const { data, success, fail, complete } = options
|
|
6
|
+
if (!data || type(data) !== 'String') {
|
|
7
|
+
const errStr = !data ? 'parameter.data should be String instead of Undefined;' : `parameter.data should be String instead of ${type(data)};`
|
|
8
|
+
const result = {
|
|
9
|
+
errno: 1001,
|
|
10
|
+
errMsg: errStr
|
|
11
|
+
}
|
|
12
|
+
webHandleFail(result, fail, complete)
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
Clipboard.setString(data)
|
|
16
|
+
const result = {
|
|
17
|
+
errMsg: 'setClipboardData:ok'
|
|
18
|
+
}
|
|
19
|
+
webHandleSuccess(result, success, complete)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const getClipboardData = function (options) {
|
|
23
|
+
const { success, fail, complete } = options
|
|
24
|
+
Clipboard.getString().then((data) => {
|
|
25
|
+
const result = {
|
|
26
|
+
data,
|
|
27
|
+
errMsg: 'getClipboardData:ok'
|
|
28
|
+
}
|
|
29
|
+
webHandleSuccess(result, success, complete)
|
|
30
|
+
}).catch(() => {
|
|
31
|
+
const result = {
|
|
32
|
+
errMsg: 'setClipboardData:fail'
|
|
33
|
+
}
|
|
34
|
+
webHandleFail(result, fail, complete)
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
setClipboardData,
|
|
40
|
+
getClipboardData
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnNetwork'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnNetwork'
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { webHandleSuccess, webHandleFail, defineUnsupportedProps } from '../../../../common/js'
|
|
2
|
+
import NetInfo, { NetInfoStateType } from '@react-native-community/netinfo'
|
|
3
|
+
|
|
4
|
+
let _unsubscribe = null
|
|
5
|
+
const _callbacks = new Set()
|
|
6
|
+
const getConnectionType = function (connectionInfo) {
|
|
7
|
+
let type = 'unknown'
|
|
8
|
+
if (connectionInfo.type === NetInfoStateType.cellular && connectionInfo.details.cellularGeneration) {
|
|
9
|
+
type = connectionInfo.details.cellularGeneration
|
|
10
|
+
} else if (connectionInfo.type === NetInfoStateType.wifi || connectionInfo.type === NetInfoStateType.none) {
|
|
11
|
+
type = connectionInfo.type
|
|
12
|
+
}
|
|
13
|
+
return type
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const getNetworkType = function (options) {
|
|
17
|
+
const { success, fail, complete } = options
|
|
18
|
+
NetInfo.fetch().then((connectionInfo) => {
|
|
19
|
+
const result = {
|
|
20
|
+
networkType: getConnectionType(connectionInfo),
|
|
21
|
+
errMsg: 'getNetworkType:ok'
|
|
22
|
+
}
|
|
23
|
+
defineUnsupportedProps(result, ['signalStrength', 'hasSystemProxy'])
|
|
24
|
+
webHandleSuccess(result, success, complete)
|
|
25
|
+
}).catch((err) => {
|
|
26
|
+
const result = {
|
|
27
|
+
errMsg: err.message
|
|
28
|
+
}
|
|
29
|
+
webHandleFail(result, fail, complete)
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const onNetworkStatusChange = function (callback) {
|
|
34
|
+
_callbacks.add(callback)
|
|
35
|
+
if (!_unsubscribe) {
|
|
36
|
+
_unsubscribe = NetInfo.addEventListener((connectionInfo) => {
|
|
37
|
+
_callbacks.forEach(cb => {
|
|
38
|
+
const { isConnected } = connectionInfo
|
|
39
|
+
// eslint-disable-next-line node/no-callback-literal
|
|
40
|
+
cb && cb({ isConnected, networkType: getConnectionType(connectionInfo) })
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const offNetworkStatusChange = function (callback) {
|
|
46
|
+
if (callback && typeof callback === 'function') {
|
|
47
|
+
_callbacks.delete(callback)
|
|
48
|
+
} else if (callback === undefined) {
|
|
49
|
+
_callbacks.clear()
|
|
50
|
+
_unsubscribe && _unsubscribe()
|
|
51
|
+
_unsubscribe = null
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
getNetworkType,
|
|
57
|
+
offNetworkStatusChange,
|
|
58
|
+
onNetworkStatusChange
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnMakePhone'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnMakePhone'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { webHandleSuccess, webHandleFail } from '../../../common/js'
|
|
2
|
+
import { Linking } from 'react-native'
|
|
3
|
+
|
|
4
|
+
const makePhoneCall = function (options) {
|
|
5
|
+
const {
|
|
6
|
+
phoneNumber = '',
|
|
7
|
+
success = null,
|
|
8
|
+
fail = null,
|
|
9
|
+
complete = null
|
|
10
|
+
} = options
|
|
11
|
+
|
|
12
|
+
Linking.openURL(`tel:${phoneNumber}`).then(() => {
|
|
13
|
+
const result = {
|
|
14
|
+
errMsg: 'makePhoneCall:ok'
|
|
15
|
+
}
|
|
16
|
+
webHandleSuccess(result, success, complete)
|
|
17
|
+
}).catch(() => {
|
|
18
|
+
const result = {
|
|
19
|
+
errMsg: 'makePhoneCall:fail cancel'
|
|
20
|
+
}
|
|
21
|
+
webHandleFail(result, fail, complete)
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
makePhoneCall
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.web'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.web'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
|
-
import { webHandleSuccess, webHandleFail } from '../../../common/js'
|
|
2
|
+
import { webHandleSuccess, webHandleFail, defineUnsupportedProps } from '../../../common/js'
|
|
3
3
|
import RequestTask from './RequestTask'
|
|
4
4
|
|
|
5
5
|
function request (options = { url: '' }) {
|
|
@@ -69,6 +69,7 @@ function request (options = { url: '' }) {
|
|
|
69
69
|
statusCode: res.status,
|
|
70
70
|
header: res.headers
|
|
71
71
|
}
|
|
72
|
+
defineUnsupportedProps(result, ['cookies', 'profile', 'exception'])
|
|
72
73
|
webHandleSuccess(result, success, complete)
|
|
73
74
|
return result
|
|
74
75
|
}).catch(err => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.ios'
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { webHandleSuccess, webHandleFail } from '../../../common/js'
|
|
2
|
+
import { parseQuery } from '@mpxjs/utils'
|
|
3
|
+
|
|
4
|
+
function parseUrl (url) {
|
|
5
|
+
if (url.startsWith('/')) {
|
|
6
|
+
url = url.slice(1)
|
|
7
|
+
} else {
|
|
8
|
+
// todo 处理相对路径
|
|
9
|
+
}
|
|
10
|
+
let path = url
|
|
11
|
+
let query = ''
|
|
12
|
+
const queryIndex = url.indexOf('?')
|
|
13
|
+
if (queryIndex >= 0) {
|
|
14
|
+
path = url.slice(0, queryIndex)
|
|
15
|
+
query = url.slice(queryIndex)
|
|
16
|
+
}
|
|
17
|
+
const queryObj = parseQuery(query || '?')
|
|
18
|
+
return {
|
|
19
|
+
path,
|
|
20
|
+
queryObj
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function navigateTo (options = {}) {
|
|
25
|
+
const navigationRef = global.__navigationRef
|
|
26
|
+
const navigationHelper = global.__navigationHelper
|
|
27
|
+
if (navigationHelper && navigationRef && navigationRef.isReady()) {
|
|
28
|
+
const { path, queryObj } = parseUrl(options.url)
|
|
29
|
+
navigationRef.dispatch(navigationHelper.StackActions.push(path, queryObj))
|
|
30
|
+
navigationHelper.lastSuccessCallback = () => {
|
|
31
|
+
const res = { errMsg: 'navigateTo:ok' }
|
|
32
|
+
webHandleSuccess(res, options.success, options.complete)
|
|
33
|
+
}
|
|
34
|
+
navigationHelper.lastFailCallback = (msg) => {
|
|
35
|
+
const res = { errMsg: `navigateTo:fail ${msg}` }
|
|
36
|
+
webHandleFail(res, options.fail, options.complete)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function redirectTo (options = {}) {
|
|
42
|
+
const navigationRef = global.__navigationRef
|
|
43
|
+
const navigationHelper = global.__navigationHelper
|
|
44
|
+
if (navigationHelper && navigationRef && navigationRef.isReady()) {
|
|
45
|
+
const { path, queryObj } = parseUrl(options.url)
|
|
46
|
+
navigationRef.dispatch(navigationHelper.StackActions.replace(path, queryObj))
|
|
47
|
+
navigationHelper.lastSuccessCallback = () => {
|
|
48
|
+
const res = { errMsg: 'redirectTo:ok' }
|
|
49
|
+
webHandleSuccess(res, options.success, options.complete)
|
|
50
|
+
}
|
|
51
|
+
navigationHelper.lastFailCallback = (msg) => {
|
|
52
|
+
const res = { errMsg: `redirectTo:fail ${msg}` }
|
|
53
|
+
webHandleFail(res, options.fail, options.complete)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function navigateBack (options = {}) {
|
|
59
|
+
const navigationRef = global.__navigationRef
|
|
60
|
+
const navigationHelper = global.__navigationHelper
|
|
61
|
+
if (navigationHelper && navigationRef && navigationRef.isReady()) {
|
|
62
|
+
navigationRef.dispatch(navigationHelper.StackActions.pop(options.delta || 1))
|
|
63
|
+
navigationHelper.lastSuccessCallback = () => {
|
|
64
|
+
const res = { errMsg: 'navigateBack:ok' }
|
|
65
|
+
webHandleSuccess(res, options.success, options.complete)
|
|
66
|
+
}
|
|
67
|
+
navigationHelper.lastFailCallback = (msg) => {
|
|
68
|
+
const res = { errMsg: `navigateBack:fail ${msg}` }
|
|
69
|
+
webHandleFail(res, options.fail, options.complete)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function reLaunch (options = {}) {
|
|
75
|
+
const navigationRef = global.__navigationRef
|
|
76
|
+
const navigationHelper = global.__navigationHelper
|
|
77
|
+
if (navigationHelper && navigationRef && navigationRef.isReady()) {
|
|
78
|
+
const { path, queryObj } = parseUrl(options.url)
|
|
79
|
+
navigationRef.reset({
|
|
80
|
+
index: 0,
|
|
81
|
+
routes: [
|
|
82
|
+
{
|
|
83
|
+
name: path,
|
|
84
|
+
params: queryObj
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
})
|
|
88
|
+
navigationHelper.lastSuccessCallback = () => {
|
|
89
|
+
const res = { errMsg: 'redirectTo:ok' }
|
|
90
|
+
webHandleSuccess(res, options.success, options.complete)
|
|
91
|
+
}
|
|
92
|
+
navigationHelper.lastFailCallback = (msg) => {
|
|
93
|
+
const res = { errMsg: `redirectTo:fail ${msg}` }
|
|
94
|
+
webHandleFail(res, options.fail, options.complete)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function switchTab () {
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
redirectTo,
|
|
105
|
+
navigateTo,
|
|
106
|
+
navigateBack,
|
|
107
|
+
reLaunch,
|
|
108
|
+
switchTab
|
|
109
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { webHandleSuccess, webHandleFail, isTabBarPage, throwSSRWarning, isBrowser } from '../../../common/js'
|
|
2
|
-
import { EventChannel } from '
|
|
2
|
+
import { EventChannel } from '../event-channel'
|
|
3
3
|
|
|
4
4
|
let routeCount = 0
|
|
5
5
|
|
|
@@ -69,7 +69,7 @@ function navigateTo (options = {}) {
|
|
|
69
69
|
webHandleSuccess(res, options.success, options.complete)
|
|
70
70
|
},
|
|
71
71
|
err => {
|
|
72
|
-
const res = { errMsg: err }
|
|
72
|
+
const res = { errMsg: `navigateTo:fail ${err}` }
|
|
73
73
|
webHandleFail(res, options.fail, options.complete)
|
|
74
74
|
}
|
|
75
75
|
)
|
|
@@ -130,7 +130,7 @@ function reLaunch (options = {}) {
|
|
|
130
130
|
webHandleSuccess(res, options.success, options.complete)
|
|
131
131
|
},
|
|
132
132
|
err => {
|
|
133
|
-
const res = { errMsg: err }
|
|
133
|
+
const res = { errMsg: `reLaunch:fail ${err}` }
|
|
134
134
|
webHandleFail(res, options.fail, options.complete)
|
|
135
135
|
}
|
|
136
136
|
)
|
|
@@ -174,7 +174,7 @@ function switchTab (options = {}) {
|
|
|
174
174
|
webHandleSuccess(res, options.success, options.complete)
|
|
175
175
|
},
|
|
176
176
|
err => {
|
|
177
|
-
const res = { errMsg: err }
|
|
177
|
+
const res = { errMsg: `switchTab:fail ${err}` }
|
|
178
178
|
webHandleFail(res, options.fail, options.complete)
|
|
179
179
|
}
|
|
180
180
|
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { webHandleSuccess, webHandleFail } from '../../../common/js'
|
|
1
|
+
import { webHandleSuccess, webHandleFail, type } from '../../../common/js'
|
|
2
2
|
|
|
3
3
|
const socketTasks = new Set()
|
|
4
4
|
|
|
@@ -41,7 +41,11 @@ class SocketTask {
|
|
|
41
41
|
|
|
42
42
|
send (options) {
|
|
43
43
|
const { data = '', success, fail, complete } = options
|
|
44
|
-
|
|
44
|
+
if (typeof data !== 'string' || type(data) !== 'ArrayBuffer') {
|
|
45
|
+
const res = { errMsg: 'sendSocketMessage:fail Unsupported data type' }
|
|
46
|
+
webHandleFail(res, fail, complete)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
45
49
|
if (this._socket.readyState === 1) {
|
|
46
50
|
this._socket.send(data)
|
|
47
51
|
const res = { errMsg: 'sendSocketMessage:ok' }
|
|
@@ -77,8 +81,14 @@ class SocketTask {
|
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
addListener (socket) {
|
|
80
|
-
socket.
|
|
81
|
-
|
|
84
|
+
socket.onopen = event => {
|
|
85
|
+
typeof this._openCb === 'function' && this._openCb(event)
|
|
86
|
+
}
|
|
87
|
+
socket.onmessage = event => {
|
|
88
|
+
typeof this._messageCb === 'function' && this._messageCb({
|
|
89
|
+
data: event.data
|
|
90
|
+
})
|
|
91
|
+
}
|
|
82
92
|
socket.onerror = event => {
|
|
83
93
|
socketTasks.delete(this._socket)
|
|
84
94
|
typeof this._errorCb === 'function' && this._errorCb(event)
|
|
@@ -91,7 +101,7 @@ class SocketTask {
|
|
|
91
101
|
if (this._closeData) {
|
|
92
102
|
this._closeCb(event)
|
|
93
103
|
} else {
|
|
94
|
-
this._closeCb({ code:
|
|
104
|
+
this._closeCb({ code: event.code, reason: event.reason })
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
107
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.web'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.web'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnStorage'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnStorage'
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
+
import { envError, webHandleSuccess, webHandleFail, hasOwn, defineUnsupportedProps } from '../../../common/js'
|
|
3
|
+
function setStorage (options) {
|
|
4
|
+
const { key, data, success, fail, complete } = options
|
|
5
|
+
let obj = {}
|
|
6
|
+
if (typeof data === 'symbol') {
|
|
7
|
+
obj = { data: '' }
|
|
8
|
+
} else {
|
|
9
|
+
obj = { data }
|
|
10
|
+
}
|
|
11
|
+
AsyncStorage.setItem(key, JSON.stringify(obj), (err) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
const result = {
|
|
14
|
+
errMsg: `setStorage:fail ${err}`
|
|
15
|
+
}
|
|
16
|
+
webHandleFail(result, fail, complete)
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
const result = {
|
|
20
|
+
errMsg: 'setStorage:ok'
|
|
21
|
+
}
|
|
22
|
+
webHandleSuccess(result, success, complete)
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const setStorageSync = envError('setStorageSync')
|
|
27
|
+
|
|
28
|
+
function getStorage (options) {
|
|
29
|
+
const { key, success, fail, complete } = options
|
|
30
|
+
if (!key) {
|
|
31
|
+
const result = {
|
|
32
|
+
errMsg: 'getStorage:fail parameter error: parameter.key should be String instead of Undefined;'
|
|
33
|
+
}
|
|
34
|
+
webHandleFail(result, fail, complete)
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
AsyncStorage.getItem(key, (err, res) => {
|
|
38
|
+
if (err || !res) {
|
|
39
|
+
const result = {
|
|
40
|
+
errMsg: `getStorage:fail ${err || 'data not found'}`
|
|
41
|
+
}
|
|
42
|
+
webHandleFail(result, fail, complete)
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
let item
|
|
46
|
+
let data = null
|
|
47
|
+
try {
|
|
48
|
+
item = JSON.parse(res)
|
|
49
|
+
} catch (e) {
|
|
50
|
+
}
|
|
51
|
+
if (item && typeof item === 'object' && hasOwn(item, 'data')) {
|
|
52
|
+
data = item.data
|
|
53
|
+
}
|
|
54
|
+
const result = {
|
|
55
|
+
errMsg: 'getStorage:ok',
|
|
56
|
+
data
|
|
57
|
+
}
|
|
58
|
+
webHandleSuccess(result, success, complete)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const getStorageSync = envError('getStorageSync')
|
|
63
|
+
|
|
64
|
+
function getStorageInfo (options) {
|
|
65
|
+
const { success, fail, complete } = options
|
|
66
|
+
AsyncStorage.getAllKeys((err, keys) => {
|
|
67
|
+
if (err) {
|
|
68
|
+
const result = {
|
|
69
|
+
errMsg: `getStorage:fail ${err}`
|
|
70
|
+
}
|
|
71
|
+
webHandleFail(result, fail, complete)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
const result = {
|
|
75
|
+
keys,
|
|
76
|
+
errMsg: 'getStorageInfo:ok'
|
|
77
|
+
}
|
|
78
|
+
defineUnsupportedProps(result, ['currentSize', 'limitSize'])
|
|
79
|
+
webHandleSuccess(result, success, complete)
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const getStorageInfoSync = envError('getStorageInfoSync')
|
|
84
|
+
|
|
85
|
+
function removeStorage (options) {
|
|
86
|
+
const { key, success, fail, complete } = options
|
|
87
|
+
AsyncStorage.removeItem(key, (err) => {
|
|
88
|
+
if (err) {
|
|
89
|
+
const result = {
|
|
90
|
+
errMsg: `removeStorage:fail ${err}`
|
|
91
|
+
}
|
|
92
|
+
webHandleFail(result, fail, complete)
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
const result = {
|
|
96
|
+
errMsg: 'removeStorage:ok'
|
|
97
|
+
}
|
|
98
|
+
webHandleSuccess(result, success, complete)
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function removeStorageSync (key) {
|
|
103
|
+
AsyncStorage.removeItem(key)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function clearStorage (options) {
|
|
107
|
+
const { success, fail, complete } = options
|
|
108
|
+
AsyncStorage.clear((err) => {
|
|
109
|
+
if (err) {
|
|
110
|
+
const result = {
|
|
111
|
+
errMsg: `clearStorage:fail ${err}`
|
|
112
|
+
}
|
|
113
|
+
webHandleFail(result, fail, complete)
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
const result = {
|
|
117
|
+
errMsg: 'clearStorage:ok'
|
|
118
|
+
}
|
|
119
|
+
webHandleSuccess(result, success, complete)
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function clearStorageSync () {
|
|
124
|
+
AsyncStorage.clear()
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export {
|
|
128
|
+
setStorage,
|
|
129
|
+
setStorageSync,
|
|
130
|
+
getStorage,
|
|
131
|
+
getStorageSync,
|
|
132
|
+
getStorageInfo,
|
|
133
|
+
getStorageInfoSync,
|
|
134
|
+
removeStorage,
|
|
135
|
+
removeStorageSync,
|
|
136
|
+
clearStorage,
|
|
137
|
+
clearStorageSync
|
|
138
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ENV_OBJ, changeOpts, handleSuccess } from '../../../common/js'
|
|
1
|
+
import { ENV_OBJ, changeOpts, envError, handleSuccess } from '../../../common/js'
|
|
2
2
|
|
|
3
3
|
function getSystemInfo (options = {}) {
|
|
4
4
|
const opts = changeOpts(options)
|
|
@@ -32,7 +32,13 @@ function getSystemInfoSync () {
|
|
|
32
32
|
return res
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
const getDeviceInfo = ENV_OBJ.getDeviceInfo || envError('getDeviceInfo')
|
|
36
|
+
|
|
37
|
+
const getWindowInfo = ENV_OBJ.getWindowInfo || envError('getWindowInfo')
|
|
38
|
+
|
|
35
39
|
export {
|
|
36
40
|
getSystemInfo,
|
|
37
|
-
getSystemInfoSync
|
|
41
|
+
getSystemInfoSync,
|
|
42
|
+
getDeviceInfo,
|
|
43
|
+
getWindowInfo
|
|
38
44
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnSystem'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnSystem'
|
|
@@ -4,7 +4,13 @@ const getSystemInfo = ENV_OBJ.getSystemInfo || envError('getSystemInfo')
|
|
|
4
4
|
|
|
5
5
|
const getSystemInfoSync = ENV_OBJ.getSystemInfoSync || envError('getSystemInfoSync')
|
|
6
6
|
|
|
7
|
+
const getDeviceInfo = ENV_OBJ.getDeviceInfo || envError('getDeviceInfo')
|
|
8
|
+
|
|
9
|
+
const getWindowInfo = ENV_OBJ.getWindowInfo || envError('getWindowInfo')
|
|
10
|
+
|
|
7
11
|
export {
|
|
8
12
|
getSystemInfo,
|
|
9
|
-
getSystemInfoSync
|
|
13
|
+
getSystemInfoSync,
|
|
14
|
+
getDeviceInfo,
|
|
15
|
+
getWindowInfo
|
|
10
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isBrowser, throwSSRWarning, webHandleSuccess } from '../../../common/js'
|
|
1
|
+
import { envError, isBrowser, throwSSRWarning, webHandleSuccess } from '../../../common/js'
|
|
2
2
|
|
|
3
3
|
function getSystemInfoSync () {
|
|
4
4
|
if (!isBrowser) {
|
|
@@ -79,7 +79,13 @@ function getSystemInfo (options = {}) {
|
|
|
79
79
|
webHandleSuccess(res, options.success, options.complete)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
const getDeviceInfo = envError('getDeviceInfo')
|
|
83
|
+
|
|
84
|
+
const getWindowInfo = envError('getWindowInfo')
|
|
85
|
+
|
|
82
86
|
export {
|
|
83
87
|
getSystemInfo,
|
|
84
|
-
getSystemInfoSync
|
|
88
|
+
getSystemInfoSync,
|
|
89
|
+
getDeviceInfo,
|
|
90
|
+
getWindowInfo
|
|
85
91
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import DeviceInfo from 'react-native-device-info'
|
|
2
|
+
import { Platform, PixelRatio, Dimensions, StatusBar } from 'react-native'
|
|
3
|
+
import { initialWindowMetrics } from 'react-native-safe-area-context'
|
|
4
|
+
import { webHandleSuccess, webHandleFail, defineUnsupportedProps } from '../../../common/js'
|
|
5
|
+
|
|
6
|
+
const getWindowInfo = function () {
|
|
7
|
+
const dimensionsWindow = Dimensions.get('window')
|
|
8
|
+
const dimensionsScreen = Dimensions.get('screen')
|
|
9
|
+
const result = {
|
|
10
|
+
pixelRatio: PixelRatio.get(),
|
|
11
|
+
windowWidth: dimensionsWindow.width,
|
|
12
|
+
windowHeight: dimensionsWindow.height,
|
|
13
|
+
screenWidth: dimensionsScreen.width,
|
|
14
|
+
screenHeight: dimensionsScreen.height
|
|
15
|
+
}
|
|
16
|
+
defineUnsupportedProps(result, ['screenTop'])
|
|
17
|
+
return result
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getSystemInfoSync = function () {
|
|
21
|
+
const windowInfo = getWindowInfo()
|
|
22
|
+
const { screenWidth, screenHeight } = windowInfo
|
|
23
|
+
let safeArea = {}
|
|
24
|
+
let { top = 0, bottom = 0 } = initialWindowMetrics?.insets || {}
|
|
25
|
+
if (Platform.OS === 'android') {
|
|
26
|
+
top = StatusBar.currentHeight || 0
|
|
27
|
+
}
|
|
28
|
+
const iosRes = {}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const width = Math.min(screenWidth, screenHeight)
|
|
32
|
+
const height = Math.max(screenWidth, screenHeight)
|
|
33
|
+
safeArea = {
|
|
34
|
+
left: 0,
|
|
35
|
+
right: width,
|
|
36
|
+
top,
|
|
37
|
+
bottom: height - bottom,
|
|
38
|
+
height: height - bottom - top,
|
|
39
|
+
width
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
}
|
|
43
|
+
const result = {
|
|
44
|
+
brand: DeviceInfo.getBrand(),
|
|
45
|
+
model: DeviceInfo.getModel(),
|
|
46
|
+
system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
|
|
47
|
+
platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
|
|
48
|
+
deviceOrientation: screenWidth > screenHeight ? 'portrait' : 'landscape',
|
|
49
|
+
statusBarHeight: top,
|
|
50
|
+
fontSizeSetting: PixelRatio.getFontScale(),
|
|
51
|
+
safeArea,
|
|
52
|
+
...windowInfo,
|
|
53
|
+
...iosRes
|
|
54
|
+
}
|
|
55
|
+
defineUnsupportedProps(result, [
|
|
56
|
+
'language',
|
|
57
|
+
'version',
|
|
58
|
+
'SDKVersion',
|
|
59
|
+
'benchmarkLevel',
|
|
60
|
+
'albumAuthorized',
|
|
61
|
+
'cameraAuthorized',
|
|
62
|
+
'locationAuthorized',
|
|
63
|
+
'microphoneAuthorized',
|
|
64
|
+
'notificationAuthorized',
|
|
65
|
+
'phoneCalendarAuthorized',
|
|
66
|
+
'host',
|
|
67
|
+
'enableDebug',
|
|
68
|
+
'notificationAlertAuthorized',
|
|
69
|
+
'notificationBadgeAuthorized',
|
|
70
|
+
'notificationSoundAuthorized',
|
|
71
|
+
'bluetoothEnabled',
|
|
72
|
+
'locationEnabled',
|
|
73
|
+
'wifiEnabled',
|
|
74
|
+
'locationReducedAccuracy',
|
|
75
|
+
'theme'
|
|
76
|
+
])
|
|
77
|
+
return result
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const getSystemInfo = function (options) {
|
|
81
|
+
const { success, fail, complete } = options
|
|
82
|
+
try {
|
|
83
|
+
const systemInfo = getSystemInfoSync()
|
|
84
|
+
Object.assign(systemInfo, {
|
|
85
|
+
errMsg: 'setStorage:ok'
|
|
86
|
+
})
|
|
87
|
+
webHandleSuccess(systemInfo, success, complete)
|
|
88
|
+
} catch (err) {
|
|
89
|
+
const result = {
|
|
90
|
+
errMsg: `getSystemInfo:fail ${err}`
|
|
91
|
+
}
|
|
92
|
+
webHandleFail(result, fail, complete)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const getDeviceInfo = function () {
|
|
97
|
+
const deviceInfo = {}
|
|
98
|
+
if (Platform.OS === 'android') {
|
|
99
|
+
const deviceAbi = DeviceInfo.supported64BitAbisSync() || []
|
|
100
|
+
deviceInfo.deviceAbi = deviceAbi[0] || null
|
|
101
|
+
}
|
|
102
|
+
defineUnsupportedProps(deviceInfo, ['benchmarkLevel', 'abi', 'cpuType'])
|
|
103
|
+
Object.assign(deviceInfo, {
|
|
104
|
+
brand: DeviceInfo.getBrand(),
|
|
105
|
+
model: DeviceInfo.getModel(),
|
|
106
|
+
system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
|
|
107
|
+
platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
|
|
108
|
+
memorySize: DeviceInfo.getTotalMemorySync() / (1024 * 1024)
|
|
109
|
+
})
|
|
110
|
+
return deviceInfo
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
getSystemInfo,
|
|
115
|
+
getSystemInfoSync,
|
|
116
|
+
getDeviceInfo,
|
|
117
|
+
getWindowInfo
|
|
118
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnWindow'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnWindow'
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Dimensions } from 'react-native'
|
|
2
|
+
|
|
3
|
+
const callbacks = []
|
|
4
|
+
let subscription
|
|
5
|
+
const addListener = function () {
|
|
6
|
+
subscription = Dimensions.addEventListener(
|
|
7
|
+
'change',
|
|
8
|
+
({ window }) => {
|
|
9
|
+
const result = {
|
|
10
|
+
size: {
|
|
11
|
+
windowWidth: window.width,
|
|
12
|
+
windowHeight: window.height
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
callbacks.forEach(cb => cb(result))
|
|
16
|
+
}
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const removeListener = function () {
|
|
21
|
+
subscription && subscription.remove()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function onWindowResize (callback) {
|
|
25
|
+
if (callbacks.length === 0) {
|
|
26
|
+
addListener()
|
|
27
|
+
}
|
|
28
|
+
callbacks.push(callback)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function offWindowResize (callback) {
|
|
32
|
+
const index = callbacks.indexOf(callback)
|
|
33
|
+
if (index > -1) {
|
|
34
|
+
callbacks.splice(index, 1)
|
|
35
|
+
}
|
|
36
|
+
if (callbacks.length === 0) {
|
|
37
|
+
removeListener()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
onWindowResize,
|
|
43
|
+
offWindowResize
|
|
44
|
+
}
|
|
File without changes
|