@tarojs/taro-h5 3.3.13 → 3.3.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.
- package/dist/index.cjs.js +6134 -8352
- package/dist/index.js +9044 -0
- package/dist/taroApis.js +1 -1
- package/package.json +9 -9
- package/src/api/ad/index.ts +5 -0
- package/src/api/ai/facial.ts +6 -0
- package/src/api/ai/index.ts +2 -0
- package/src/api/ai/visual.ts +4 -0
- package/src/api/alipay/index.ts +4 -0
- package/src/api/base/crypto.ts +4 -0
- package/src/api/base/debug.ts +5 -0
- package/src/api/base/index.ts +23 -0
- package/src/api/base/performance.ts +5 -0
- package/src/api/base/system/index.ts +2 -0
- package/src/api/base/system/info.ts +64 -0
- package/src/api/base/system/network.ts +70 -0
- package/src/api/base/update.ts +5 -0
- package/src/api/base/weapp/app-event.ts +19 -0
- package/src/api/base/weapp/life-cycle.ts +5 -0
- package/src/api/canvas/CanvasContext.ts +230 -0
- package/src/api/canvas/canvasGetImageData.ts +29 -0
- package/src/api/canvas/canvasPutImageData.ts +26 -0
- package/src/api/canvas/canvasToTempFilePath.ts +26 -0
- package/src/api/canvas/createCanvasContext.ts +20 -0
- package/src/api/canvas/{index.js → index.ts} +9 -3
- package/src/api/cloud/index.ts +27 -0
- package/src/api/data-analysis/index.ts +6 -0
- package/src/api/device/accelerometer.ts +89 -0
- package/src/api/device/accessibility.ts +4 -0
- package/src/api/device/battery.ts +5 -0
- package/src/api/device/bluetooth-ble.ts +19 -0
- package/src/api/device/bluetooth-peripheral.ts +6 -0
- package/src/api/device/bluetooth.ts +16 -0
- package/src/api/device/calendar.ts +5 -0
- package/src/api/device/clipboard.ts +67 -0
- package/src/api/device/compass.ts +74 -0
- package/src/api/device/contact.ts +5 -0
- package/src/api/device/crypto.ts +4 -0
- package/src/api/device/gyroscope.ts +7 -0
- package/src/api/device/iBeacon.ts +10 -0
- package/src/api/device/index.ts +22 -0
- package/src/api/device/keyboard.ts +7 -0
- package/src/api/device/memory.ts +5 -0
- package/src/api/device/motion.ts +92 -0
- package/src/api/device/nfc.ts +10 -0
- package/src/api/device/phone.ts +30 -0
- package/src/api/device/scan.ts +7 -0
- package/src/api/device/screen.ts +9 -0
- package/src/api/device/vibrate.ts +36 -0
- package/src/api/device/wifi.ts +13 -0
- package/src/api/ext/index.ts +5 -0
- package/src/api/files/index.ts +11 -0
- package/src/api/framework/index.ts +10 -0
- package/src/api/index.ts +25 -0
- package/src/api/location/chooseLocation.ts +106 -0
- package/src/api/location/index.ts +19 -0
- package/src/api/location/style.css +8 -8
- package/src/api/media/audio/index.ts +99 -0
- package/src/api/media/background-audio.ts +12 -0
- package/src/api/media/camera.ts +4 -0
- package/src/api/media/editor.ts +29 -0
- package/src/api/media/image/chooseImage.ts +80 -0
- package/src/api/{image → media/image}/getImageInfo.js +0 -0
- package/src/api/media/image/index.ts +13 -0
- package/src/api/{image → media/image}/previewImage.js +4 -0
- package/src/api/media/index.ts +13 -0
- package/src/api/media/live.ts +5 -0
- package/src/api/media/map.ts +4 -0
- package/src/api/media/media-recorder.ts +4 -0
- package/src/api/media/recorder.ts +6 -0
- package/src/api/media/video/index.ts +82 -0
- package/src/api/media/video-decoder.ts +4 -0
- package/src/api/media/video-processing.ts +4 -0
- package/src/api/media/voip.ts +17 -0
- package/src/api/navigate/index.ts +7 -0
- package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -25
- package/src/api/network/index.ts +7 -0
- package/src/api/network/mdns.ts +13 -0
- package/src/api/{request/index.js → network/request/index.ts} +9 -6
- package/src/api/network/tcp.ts +4 -0
- package/src/api/network/udp.ts +4 -0
- package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -30
- package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
- package/src/api/{webSocket/index.js → network/websocket/index.ts} +50 -57
- package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +16 -6
- package/src/api/open-api/account.ts +4 -0
- package/src/api/open-api/address.ts +4 -0
- package/src/api/open-api/authorize.ts +5 -0
- package/src/api/open-api/card.ts +5 -0
- package/src/api/open-api/channels-live.ts +9 -0
- package/src/api/open-api/customer-service.ts +4 -0
- package/src/api/open-api/facial.ts +7 -0
- package/src/api/open-api/favorites.ts +5 -0
- package/src/api/open-api/group.ts +4 -0
- package/src/api/open-api/index.ts +18 -0
- package/src/api/open-api/invoice.ts +5 -0
- package/src/api/open-api/license-plate.ts +4 -0
- package/src/api/open-api/login.ts +6 -0
- package/src/api/open-api/red-package.ts +4 -0
- package/src/api/open-api/settings.ts +5 -0
- package/src/api/open-api/soter.ts +6 -0
- package/src/api/open-api/subscribe-message.ts +4 -0
- package/src/api/open-api/user-info.ts +5 -0
- package/src/api/open-api/werun.ts +5 -0
- package/src/api/payment/index.ts +5 -0
- package/src/api/route/index.ts +10 -0
- package/src/api/share/index.ts +13 -0
- package/src/api/storage/background-fetch.ts +7 -0
- package/src/api/storage/index.ts +193 -0
- package/src/api/swan/index.ts +31 -0
- package/src/{taro/index.js → api/taro.ts} +133 -149
- package/src/api/{createAnimation/index.js → ui/animation/index.ts} +26 -14
- package/src/api/ui/background.ts +5 -0
- package/src/api/ui/custom-component.ts +4 -0
- package/src/api/ui/fonts.ts +4 -0
- package/src/api/ui/index.ts +12 -0
- package/src/api/ui/interaction/actionSheet.ts +212 -0
- package/src/api/{interactive/index.js → ui/interaction/index.ts} +102 -90
- package/src/api/ui/interaction/modal.ts +237 -0
- package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
- package/src/api/ui/menu.ts +4 -0
- package/src/api/ui/navigation-bar/index.ts +52 -0
- package/src/api/ui/pull-down-refresh.ts +32 -0
- package/src/api/{scroll/index.js → ui/scroll/index.ts} +16 -28
- package/src/api/ui/sticky.ts +4 -0
- package/src/api/ui/tab-bar.ts +326 -0
- package/src/api/ui/window.ts +37 -0
- package/src/api/utils/handler.ts +105 -0
- package/src/api/utils/{index.js → index.ts} +24 -87
- package/src/api/worker/index.ts +4 -0
- package/src/api/wxml/index.ts +9 -0
- package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +86 -59
- package/src/index.ts +6 -0
- package/src/types/api.d.ts +4 -0
- package/src/types/define.d.ts +2 -0
- package/{types → src/types}/index.d.ts +0 -0
- package/{types → src/types}/type.ts +1 -1
- package/src/api/accelerometer/index.js +0 -105
- package/src/api/audio/index.js +0 -137
- package/src/api/canvas/canvasGetImageData.js +0 -44
- package/src/api/canvas/canvasPutImageData.js +0 -45
- package/src/api/canvas/canvasToTempFilePath.js +0 -49
- package/src/api/canvas/createCanvasContext.js +0 -340
- package/src/api/clipboard/index.js +0 -113
- package/src/api/compass/index.js +0 -99
- package/src/api/deviceMotion/index.js +0 -105
- package/src/api/fileTransfer/index.js +0 -2
- package/src/api/image/chooseImage.js +0 -87
- package/src/api/image/index.js +0 -7
- package/src/api/index.js +0 -29
- package/src/api/interactive/actionSheet.js +0 -214
- package/src/api/interactive/modal.js +0 -256
- package/src/api/location/chooseLocation.js +0 -143
- package/src/api/location/index.js +0 -5
- package/src/api/navigationBar/index.js +0 -57
- package/src/api/open/index.js +0 -5
- package/src/api/others/index.js +0 -43
- package/src/api/pullDownRefresh/index.js +0 -51
- package/src/api/storage/index.js +0 -211
- package/src/api/system/index.js +0 -9
- package/src/api/system/info.js +0 -36
- package/src/api/system/network.js +0 -68
- package/src/api/tabBar/index.js +0 -424
- package/src/api/unsupportedApi/index.js +0 -278
- package/src/api/vibrate/index.js +0 -49
- package/src/api/video/index.js +0 -87
- package/src/api/window/index.js +0 -38
- package/src/index.cjs.js +0 -11
- package/src/index.js +0 -6
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { CallbackManager } from '../utils/handler'
|
|
2
3
|
import { NETWORK_TIMEOUT, setHeader, XHR_STATS } from './utils'
|
|
3
4
|
|
|
4
|
-
const createDownloadTask = ({ url, header, success, error }) => {
|
|
5
|
+
const createDownloadTask = ({ url, header, success, error }): Taro.DownloadTask => {
|
|
5
6
|
let timeout
|
|
6
7
|
const apiName = 'downloadFile'
|
|
7
8
|
const xhr = new XMLHttpRequest()
|
|
8
9
|
const callbackManager = {
|
|
9
|
-
headersReceived:
|
|
10
|
-
progressUpdate:
|
|
10
|
+
headersReceived: new CallbackManager(),
|
|
11
|
+
progressUpdate: new CallbackManager()
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
xhr.open('GET', url, true)
|
|
@@ -47,7 +48,7 @@ const createDownloadTask = ({ url, header, success, error }) => {
|
|
|
47
48
|
})
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
xhr.onerror = e => {
|
|
51
|
+
xhr.onerror = (e: ProgressEvent<EventTarget> & { message?: string }) => {
|
|
51
52
|
error({
|
|
52
53
|
errMsg: `${apiName}:fail ${e.message}`
|
|
53
54
|
})
|
|
@@ -111,41 +112,31 @@ const createDownloadTask = ({ url, header, success, error }) => {
|
|
|
111
112
|
/**
|
|
112
113
|
* 下载文件资源到本地。客户端直接发起一个 HTTPS GET 请求,返回文件的本地临时路径。使用前请注意阅读相关说明。
|
|
113
114
|
* 注意:请在服务端响应的 header 中指定合理的 Content-Type 字段,以保证客户端正确处理文件类型。
|
|
114
|
-
* @todo 未挂载 task.offHeadersReceived
|
|
115
|
-
* @todo 未挂载 task.offProgressUpdate
|
|
116
|
-
* @param {Object} object 参数
|
|
117
|
-
* @param {string} object.url 下载资源的 url
|
|
118
|
-
* @param {Object} [object.header] HTTP 请求的 Header,Header 中不能设置 Referer
|
|
119
|
-
* @param {string} [object.filePath] *指定文件下载后存储的路径
|
|
120
|
-
* @param {function} [object.success] 接口调用成功的回调函数
|
|
121
|
-
* @param {function} [object.fail] 接口调用失败的回调函数
|
|
122
|
-
* @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
123
|
-
* @returns {DownloadTask}
|
|
124
115
|
*/
|
|
125
|
-
const downloadFile = ({ url, header, success, fail, complete }) => {
|
|
126
|
-
let task
|
|
127
|
-
const
|
|
116
|
+
const downloadFile: typeof Taro.downloadFile = ({ url, header, success, fail, complete }) => {
|
|
117
|
+
let task: Taro.DownloadTask
|
|
118
|
+
const result: ReturnType<typeof Taro.downloadFile> = new Promise((resolve, reject) => {
|
|
128
119
|
task = createDownloadTask({
|
|
129
120
|
url,
|
|
130
121
|
header,
|
|
131
122
|
success: res => {
|
|
132
123
|
success && success(res)
|
|
133
|
-
complete && complete()
|
|
124
|
+
complete && complete(res)
|
|
134
125
|
resolve(res)
|
|
135
126
|
},
|
|
136
127
|
error: res => {
|
|
137
128
|
fail && fail(res)
|
|
138
|
-
complete && complete()
|
|
129
|
+
complete && complete(res)
|
|
139
130
|
reject(res)
|
|
140
131
|
}
|
|
141
132
|
})
|
|
142
|
-
})
|
|
143
133
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
134
|
+
result.headersReceive = task.onHeadersReceived
|
|
135
|
+
result.progress = task.onProgressUpdate
|
|
136
|
+
result.abort = task.abort
|
|
137
|
+
}) as any
|
|
147
138
|
|
|
148
|
-
return
|
|
139
|
+
return result
|
|
149
140
|
}
|
|
150
141
|
|
|
151
142
|
export default downloadFile
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// mDNS
|
|
4
|
+
export const stopLocalServiceDiscovery = temporarilyNotSupport('stopLocalServiceDiscovery')
|
|
5
|
+
export const startLocalServiceDiscovery = temporarilyNotSupport('startLocalServiceDiscovery')
|
|
6
|
+
export const onLocalServiceResolveFail = temporarilyNotSupport('onLocalServiceResolveFail')
|
|
7
|
+
export const onLocalServiceLost = temporarilyNotSupport('onLocalServiceLost')
|
|
8
|
+
export const onLocalServiceFound = temporarilyNotSupport('onLocalServiceFound')
|
|
9
|
+
export const onLocalServiceDiscoveryStop = temporarilyNotSupport('onLocalServiceDiscoveryStop')
|
|
10
|
+
export const offLocalServiceResolveFail = temporarilyNotSupport('offLocalServiceResolveFail')
|
|
11
|
+
export const offLocalServiceLost = temporarilyNotSupport('offLocalServiceLost')
|
|
12
|
+
export const offLocalServiceFound = temporarilyNotSupport('offLocalServiceFound')
|
|
13
|
+
export const offLocalServiceDiscoveryStop = temporarilyNotSupport('offLocalServiceDiscoveryStop')
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import Taro from '@tarojs/api'
|
|
2
2
|
import 'whatwg-fetch'
|
|
3
3
|
import jsonpRetry from 'jsonp-retry'
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
import { serializeParams } from '../../utils'
|
|
6
|
+
|
|
7
|
+
// @ts-ignore
|
|
5
8
|
const { Link } = Taro
|
|
6
9
|
|
|
7
|
-
function generateRequestUrlWithParams (url, params) {
|
|
10
|
+
function generateRequestUrlWithParams (url: string, params?: unknown) {
|
|
8
11
|
params = typeof params === 'string' ? params : serializeParams(params)
|
|
9
12
|
if (params) {
|
|
10
13
|
url += (~url.indexOf('?') ? '&' : '?') + params
|
|
@@ -13,6 +16,7 @@ function generateRequestUrlWithParams (url, params) {
|
|
|
13
16
|
return url
|
|
14
17
|
}
|
|
15
18
|
|
|
19
|
+
// FIXME 移除 any 标注
|
|
16
20
|
function _request (options) {
|
|
17
21
|
options = options || {}
|
|
18
22
|
if (typeof options === 'string') {
|
|
@@ -22,8 +26,8 @@ function _request (options) {
|
|
|
22
26
|
}
|
|
23
27
|
const { success, complete, fail } = options
|
|
24
28
|
let url = options.url
|
|
25
|
-
const params = {}
|
|
26
|
-
const res = {}
|
|
29
|
+
const params: any = {}
|
|
30
|
+
const res: any = {}
|
|
27
31
|
if (options.jsonp) {
|
|
28
32
|
Object.assign(params, options)
|
|
29
33
|
params.params = options.data
|
|
@@ -122,6 +126,5 @@ function taroInterceptor (chain) {
|
|
|
122
126
|
|
|
123
127
|
const link = new Link(taroInterceptor)
|
|
124
128
|
|
|
125
|
-
|
|
126
|
-
export const request = link.request.bind(link)
|
|
129
|
+
export const request: typeof Taro.request = link.request.bind(link)
|
|
127
130
|
export const addInterceptor = link.addInterceptor.bind(link)
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { temporarilyNotSupport } from '../utils'
|
|
3
|
+
import { CallbackManager } from '../utils/handler'
|
|
2
4
|
import {
|
|
3
5
|
convertObjectUrlToBlob,
|
|
4
6
|
NETWORK_TIMEOUT,
|
|
@@ -6,15 +8,15 @@ import {
|
|
|
6
8
|
XHR_STATS
|
|
7
9
|
} from './utils'
|
|
8
10
|
|
|
9
|
-
const createUploadTask = ({ url, filePath, formData, name, header, timeout, fileName, success, error }) => {
|
|
11
|
+
const createUploadTask = ({ url, filePath, formData, name, header, timeout, fileName, success, error }): Taro.UploadTask => {
|
|
10
12
|
let timeoutInter
|
|
11
13
|
let formKey
|
|
12
14
|
const apiName = 'uploadFile'
|
|
13
15
|
const xhr = new XMLHttpRequest()
|
|
14
16
|
const form = new FormData()
|
|
15
17
|
const callbackManager = {
|
|
16
|
-
headersReceived:
|
|
17
|
-
progressUpdate:
|
|
18
|
+
headersReceived: new CallbackManager(),
|
|
19
|
+
progressUpdate: new CallbackManager()
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
xhr.open('POST', url)
|
|
@@ -57,7 +59,7 @@ const createUploadTask = ({ url, filePath, formData, name, header, timeout, file
|
|
|
57
59
|
})
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
xhr.onerror = e => {
|
|
62
|
+
xhr.onerror = (e: ProgressEvent<EventTarget> & { message?: string }) => {
|
|
61
63
|
clearTimeout(timeoutInter)
|
|
62
64
|
error({
|
|
63
65
|
errMsg: `${apiName}:fail ${e.message}`
|
|
@@ -88,8 +90,11 @@ const createUploadTask = ({ url, filePath, formData, name, header, timeout, file
|
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
convertObjectUrlToBlob(filePath)
|
|
91
|
-
.then(fileObj => {
|
|
92
|
-
|
|
93
|
+
.then((fileObj: string | (Blob & { name?: string })) => {
|
|
94
|
+
if (!fileName) {
|
|
95
|
+
fileName = typeof fileObj !== 'string' && fileObj.name
|
|
96
|
+
}
|
|
97
|
+
form.append(name, fileObj, fileName || `file-${Date.now()}`)
|
|
93
98
|
send()
|
|
94
99
|
})
|
|
95
100
|
.catch(e => {
|
|
@@ -120,33 +125,26 @@ const createUploadTask = ({ url, filePath, formData, name, header, timeout, file
|
|
|
120
125
|
*/
|
|
121
126
|
const offProgressUpdate = callbackManager.progressUpdate.remove
|
|
122
127
|
|
|
128
|
+
const headersReceived = temporarilyNotSupport('UploadTask.headersReceived')
|
|
129
|
+
const progress = temporarilyNotSupport('UploadTask.progress')
|
|
130
|
+
|
|
123
131
|
return {
|
|
124
132
|
abort,
|
|
125
133
|
onHeadersReceived,
|
|
126
134
|
offHeadersReceived,
|
|
127
135
|
onProgressUpdate,
|
|
128
|
-
offProgressUpdate
|
|
136
|
+
offProgressUpdate,
|
|
137
|
+
headersReceived,
|
|
138
|
+
progress
|
|
129
139
|
}
|
|
130
140
|
}
|
|
131
141
|
|
|
132
142
|
/**
|
|
133
143
|
* 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。
|
|
134
|
-
* @param {Object} object 参数
|
|
135
|
-
* @param {string} object.url 开发者服务器地址
|
|
136
|
-
* @param {string} object.filePath 要上传文件资源的路径
|
|
137
|
-
* @param {string} object.name 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容
|
|
138
|
-
* @param {Object} [object.header] HTTP 请求 Header,Header 中不能设置 Referer
|
|
139
|
-
* @param {Object} [object.formData] HTTP 请求中其他额外的 form data
|
|
140
|
-
* @param {number} [object.timeout] 超时时间,单位为毫秒
|
|
141
|
-
* @param {string} [object.fileName] 上传的文件名
|
|
142
|
-
* @param {function} [object.success] 接口调用成功的回调函数
|
|
143
|
-
* @param {function} [object.fail] 接口调用失败的回调函数
|
|
144
|
-
* @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
145
|
-
* @returns {UploadTask}
|
|
146
144
|
*/
|
|
147
|
-
const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, success, fail, complete }) => {
|
|
148
|
-
let task
|
|
149
|
-
const
|
|
145
|
+
const uploadFile: typeof Taro.uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, success, fail, complete }) => {
|
|
146
|
+
let task: Taro.UploadTask
|
|
147
|
+
const result: ReturnType<typeof Taro.uploadFile> = new Promise((resolve, reject) => {
|
|
150
148
|
task = createUploadTask({
|
|
151
149
|
url,
|
|
152
150
|
header,
|
|
@@ -157,22 +155,22 @@ const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName,
|
|
|
157
155
|
fileName,
|
|
158
156
|
success: res => {
|
|
159
157
|
success && success(res)
|
|
160
|
-
complete && complete()
|
|
158
|
+
complete && complete(res)
|
|
161
159
|
resolve(res)
|
|
162
160
|
},
|
|
163
161
|
error: res => {
|
|
164
162
|
fail && fail(res)
|
|
165
|
-
complete && complete()
|
|
163
|
+
complete && complete(res)
|
|
166
164
|
reject(res)
|
|
167
165
|
}
|
|
168
166
|
})
|
|
169
|
-
})
|
|
170
167
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
168
|
+
result.headersReceive = task.onHeadersReceived
|
|
169
|
+
result.progress = task.onProgressUpdate
|
|
170
|
+
result.abort = task.abort
|
|
171
|
+
}) as any
|
|
174
172
|
|
|
175
|
-
return
|
|
173
|
+
return result
|
|
176
174
|
}
|
|
177
175
|
|
|
178
176
|
export default uploadFile
|
|
File without changes
|
|
@@ -1,45 +1,62 @@
|
|
|
1
1
|
import SocketTask from './socketTask'
|
|
2
|
-
import {
|
|
2
|
+
import { shouldBeObject, getParameterError } from '../../utils'
|
|
3
|
+
import { MethodHandler } from 'src/api/utils/handler'
|
|
3
4
|
|
|
4
|
-
let socketTasks = []
|
|
5
|
+
let socketTasks: SocketTask[] = []
|
|
5
6
|
let socketsCounter = 1
|
|
6
7
|
|
|
8
|
+
function sendSocketMessage () {
|
|
9
|
+
console.warn('Deprecated.Please use socketTask.send instead.')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function onSocketOpen () {
|
|
13
|
+
console.warn('Deprecated.Please use socketTask.onOpen instead.')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function onSocketMessage () {
|
|
17
|
+
console.warn('Deprecated.Please use socketTask.onMessage instead.')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function onSocketError () {
|
|
21
|
+
console.warn('Deprecated.Please use socketTask.onError instead.')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function onSocketClose () {
|
|
25
|
+
console.warn('Deprecated.Please use socketTask.onClose instead.')
|
|
26
|
+
}
|
|
27
|
+
|
|
7
28
|
function connectSocket (options) {
|
|
8
29
|
const name = 'connectSocket'
|
|
9
30
|
|
|
10
31
|
return new Promise((resolve, reject) => {
|
|
11
32
|
// options must be an Object
|
|
12
|
-
const isObject =
|
|
13
|
-
if (!isObject.
|
|
14
|
-
const res = { errMsg: `${name}${isObject.msg}` }
|
|
33
|
+
const isObject = shouldBeObject(options)
|
|
34
|
+
if (!isObject.flag) {
|
|
35
|
+
const res = { errMsg: `${name}:fail ${isObject.msg}` }
|
|
15
36
|
console.error(res.errMsg)
|
|
16
37
|
return reject(res)
|
|
17
38
|
}
|
|
18
|
-
|
|
19
39
|
const { url, protocols, success, fail, complete } = options
|
|
20
|
-
const
|
|
40
|
+
const handle = new MethodHandler<{
|
|
41
|
+
socketTaskId?: number
|
|
42
|
+
}>({ name, success, fail, complete })
|
|
21
43
|
|
|
22
44
|
// options.url must be String
|
|
23
45
|
if (typeof url !== 'string') {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
typeof fail === 'function' && fail(res)
|
|
32
|
-
typeof complete === 'function' && complete(res)
|
|
33
|
-
return reject(res)
|
|
46
|
+
return handle.fail({
|
|
47
|
+
errMsg: getParameterError({
|
|
48
|
+
para: 'url',
|
|
49
|
+
correct: 'String',
|
|
50
|
+
wrong: url
|
|
51
|
+
})
|
|
52
|
+
}, reject)
|
|
34
53
|
}
|
|
35
54
|
|
|
36
55
|
// options.url must be invalid
|
|
37
56
|
if (!url.startsWith('ws://') && !url.startsWith('wss://')) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
typeof complete === 'function' && complete(res)
|
|
42
|
-
return reject(res)
|
|
57
|
+
return handle.fail({
|
|
58
|
+
errMsg: `request:fail invalid url "${url}"`
|
|
59
|
+
}, reject)
|
|
43
60
|
}
|
|
44
61
|
|
|
45
62
|
// protocols must be array
|
|
@@ -47,11 +64,9 @@ function connectSocket (options) {
|
|
|
47
64
|
|
|
48
65
|
// 2 connection at most
|
|
49
66
|
if (socketTasks.length > 1) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
typeof complete === 'function' && complete(res)
|
|
54
|
-
return reject(res)
|
|
67
|
+
return handle.fail({
|
|
68
|
+
errMsg: '同时最多发起 2 个 socket 请求,更多请参考文档。'
|
|
69
|
+
}, reject)
|
|
55
70
|
}
|
|
56
71
|
|
|
57
72
|
const task = new SocketTask(url, _protocols)
|
|
@@ -60,44 +75,22 @@ function connectSocket (options) {
|
|
|
60
75
|
}
|
|
61
76
|
socketTasks.push(task)
|
|
62
77
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return resolve(task)
|
|
78
|
+
return handle.success({
|
|
79
|
+
socketTaskId: socketsCounter++
|
|
80
|
+
}, resolve)
|
|
68
81
|
})
|
|
69
82
|
}
|
|
70
83
|
|
|
71
|
-
function onSocketOpen () {
|
|
72
|
-
console.warn('Deprecated.Please use socketTask.onOpen instead.')
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function onSocketError () {
|
|
76
|
-
console.warn('Deprecated.Please use socketTask.onError instead.')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function sendSocketMessage () {
|
|
80
|
-
console.warn('Deprecated.Please use socketTask.send instead.')
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function onSocketMessage () {
|
|
84
|
-
console.warn('Deprecated.Please use socketTask.onMessage instead.')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
84
|
function closeSocket () {
|
|
88
85
|
console.warn('Deprecated.Please use socketTask.close instead.')
|
|
89
86
|
}
|
|
90
87
|
|
|
91
|
-
function onSocketClose () {
|
|
92
|
-
console.warn('Deprecated.Please use socketTask.onClose instead.')
|
|
93
|
-
}
|
|
94
|
-
|
|
95
88
|
export {
|
|
96
|
-
connectSocket,
|
|
97
|
-
onSocketOpen,
|
|
98
|
-
onSocketError,
|
|
99
89
|
sendSocketMessage,
|
|
90
|
+
onSocketOpen,
|
|
100
91
|
onSocketMessage,
|
|
101
|
-
|
|
102
|
-
onSocketClose
|
|
92
|
+
onSocketError,
|
|
93
|
+
onSocketClose,
|
|
94
|
+
connectSocket,
|
|
95
|
+
closeSocket
|
|
103
96
|
}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
|
|
1
3
|
export default class SocketTask {
|
|
4
|
+
ws: WebSocket
|
|
5
|
+
CONNECTING: number
|
|
6
|
+
OPEN: number
|
|
7
|
+
CLOSING: number
|
|
8
|
+
CLOSED: number
|
|
9
|
+
closeDetail: { code: any; reason: any }
|
|
10
|
+
_destroyWhenClose?: () => void
|
|
11
|
+
|
|
2
12
|
constructor (url, protocols) {
|
|
3
13
|
if (protocols && protocols.length) {
|
|
4
14
|
this.ws = new WebSocket(url, protocols)
|
|
@@ -15,10 +25,10 @@ export default class SocketTask {
|
|
|
15
25
|
return this.ws.readyState
|
|
16
26
|
}
|
|
17
27
|
|
|
18
|
-
send (
|
|
19
|
-
if (typeof
|
|
28
|
+
send (opts: Partial<Taro.SocketTask.SendOption> = {}) {
|
|
29
|
+
if (typeof opts !== 'object' || !opts) opts = {}
|
|
20
30
|
|
|
21
|
-
const { data = '', success, fail, complete } =
|
|
31
|
+
const { data = '', success, fail, complete } = opts
|
|
22
32
|
|
|
23
33
|
if (this.readyState !== 1) {
|
|
24
34
|
const res = { errMsg: 'SocketTask.send:fail SocketTask.readState is not OPEN' }
|
|
@@ -36,15 +46,15 @@ export default class SocketTask {
|
|
|
36
46
|
return Promise.resolve(res)
|
|
37
47
|
}
|
|
38
48
|
|
|
39
|
-
close (
|
|
40
|
-
if (typeof
|
|
49
|
+
close (opts: Partial<Taro.SocketTask.CloseOption> = {}) {
|
|
50
|
+
if (typeof opts !== 'object' || !opts) opts = {}
|
|
41
51
|
|
|
42
52
|
const {
|
|
43
53
|
code = 1000,
|
|
44
54
|
reason = 'server complete,close',
|
|
45
55
|
success,
|
|
46
56
|
complete
|
|
47
|
-
} =
|
|
57
|
+
} = opts
|
|
48
58
|
|
|
49
59
|
this.closeDetail = { code, reason }
|
|
50
60
|
// 主动断开时需要重置链接数
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 视频号
|
|
4
|
+
export const reserveChannelsLive = temporarilyNotSupport('reserveChannelsLive')
|
|
5
|
+
export const openChannelsLive = temporarilyNotSupport('openChannelsLive')
|
|
6
|
+
export const openChannelsEvent = temporarilyNotSupport('openChannelsEvent')
|
|
7
|
+
export const openChannelsActivity = temporarilyNotSupport('openChannelsActivity')
|
|
8
|
+
export const getChannelsLiveNoticeInfo = temporarilyNotSupport('getChannelsLiveNoticeInfo')
|
|
9
|
+
export const getChannelsLiveInfo = temporarilyNotSupport('getChannelsLiveInfo')
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 过往接口
|
|
4
|
+
export const checkIsSupportFacialRecognition = temporarilyNotSupport('checkIsSupportFacialRecognition')
|
|
5
|
+
export const startFacialRecognitionVerify = temporarilyNotSupport('startFacialRecognitionVerify')
|
|
6
|
+
export const startFacialRecognitionVerifyAndUploadVideo = temporarilyNotSupport('startFacialRecognitionVerifyAndUploadVideo')
|
|
7
|
+
export const faceVerifyForPay = temporarilyNotSupport('faceVerifyForPay')
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './account'
|
|
2
|
+
export * from './address'
|
|
3
|
+
export * from './authorize'
|
|
4
|
+
export * from './card'
|
|
5
|
+
export * from './channels-live'
|
|
6
|
+
export * from './customer-service'
|
|
7
|
+
export * from './facial'
|
|
8
|
+
export * from './favorites'
|
|
9
|
+
export * from './group'
|
|
10
|
+
export * from './invoice'
|
|
11
|
+
export * from './license-plate'
|
|
12
|
+
export * from './login'
|
|
13
|
+
export * from './red-package'
|
|
14
|
+
export * from './settings'
|
|
15
|
+
export * from './soter'
|
|
16
|
+
export * from './subscribe-message'
|
|
17
|
+
export * from './user-info'
|
|
18
|
+
export * from './werun'
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 生物认证
|
|
4
|
+
export const startSoterAuthentication = temporarilyNotSupport('startSoterAuthentication')
|
|
5
|
+
export const checkIsSupportSoterAuthentication = temporarilyNotSupport('checkIsSupportSoterAuthentication')
|
|
6
|
+
export const checkIsSoterEnrolledInDevice = temporarilyNotSupport('checkIsSoterEnrolledInDevice')
|