@tarojs/taro-h5 3.4.0-beta.0 → 3.4.0
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/api/ad/index.js +4 -0
- package/dist/api/ai/facial.js +5 -0
- package/dist/api/ai/index.js +2 -0
- package/dist/api/ai/visual.js +3 -0
- package/dist/api/alipay/index.js +3 -0
- package/dist/api/base/crypto.js +3 -0
- package/dist/api/base/debug.js +4 -0
- package/dist/api/base/index.js +17 -0
- package/dist/api/base/performance.js +4 -0
- package/dist/api/base/system/index.js +2 -0
- package/dist/api/base/system/info.js +57 -0
- package/dist/api/base/system/network.js +63 -0
- package/dist/api/base/update.js +4 -0
- package/dist/api/base/weapp/app-event.js +18 -0
- package/dist/api/base/weapp/life-cycle.js +4 -0
- package/dist/api/canvas/CanvasContext.js +191 -0
- package/dist/api/canvas/canvasGetImageData.js +25 -0
- package/dist/api/canvas/canvasPutImageData.js +22 -0
- package/dist/api/canvas/canvasToTempFilePath.js +22 -0
- package/dist/api/canvas/createCanvasContext.js +16 -0
- package/dist/api/canvas/index.js +8 -0
- package/dist/api/cloud/index.js +17 -0
- package/dist/api/data-analysis/index.js +5 -0
- package/dist/api/device/accelerometer.js +83 -0
- package/dist/api/device/accessibility.js +3 -0
- package/dist/api/device/battery.js +4 -0
- package/dist/api/device/bluetooth-ble.js +18 -0
- package/dist/api/device/bluetooth-peripheral.js +5 -0
- package/dist/api/device/bluetooth.js +15 -0
- package/dist/api/device/calendar.js +4 -0
- package/dist/api/device/clipboard.js +65 -0
- package/dist/api/device/compass.js +64 -0
- package/dist/api/device/contact.js +4 -0
- package/dist/api/device/crypto.js +3 -0
- package/dist/api/device/gyroscope.js +6 -0
- package/dist/api/device/iBeacon.js +9 -0
- package/dist/api/device/index.js +22 -0
- package/dist/api/device/keyboard.js +6 -0
- package/dist/api/device/memory.js +4 -0
- package/dist/api/device/motion.js +81 -0
- package/dist/api/device/nfc.js +9 -0
- package/dist/api/device/phone.js +24 -0
- package/dist/api/device/scan.js +6 -0
- package/dist/api/device/screen.js +8 -0
- package/dist/api/device/vibrate.js +35 -0
- package/dist/api/device/wifi.js +12 -0
- package/dist/api/ext/index.js +4 -0
- package/dist/api/files/index.js +10 -0
- package/dist/api/framework/index.js +7 -0
- package/dist/api/index.js +24 -0
- package/dist/api/location/chooseLocation.js +93 -0
- package/dist/api/location/index.js +13 -0
- package/dist/api/location/style.css +79 -0
- package/dist/api/media/audio/index.js +88 -0
- package/dist/api/media/background-audio.js +11 -0
- package/dist/api/media/camera.js +3 -0
- package/dist/api/media/editor.js +18 -0
- package/dist/api/media/image/chooseImage.js +74 -0
- package/dist/api/media/image/getImageInfo.js +31 -0
- package/dist/api/media/image/index.js +9 -0
- package/dist/api/media/image/previewImage.js +67 -0
- package/dist/api/media/index.js +13 -0
- package/dist/api/media/live.js +4 -0
- package/dist/api/media/map.js +3 -0
- package/dist/api/media/media-recorder.js +3 -0
- package/dist/api/media/recorder.js +5 -0
- package/dist/api/media/video/index.js +74 -0
- package/dist/api/media/video-decoder.js +3 -0
- package/dist/api/media/video-processing.js +3 -0
- package/dist/api/media/voip.js +16 -0
- package/dist/api/navigate/index.js +6 -0
- package/dist/api/network/download.js +124 -0
- package/dist/api/network/index.js +7 -0
- package/dist/api/network/mdns.js +12 -0
- package/dist/api/network/request/index.js +125 -0
- package/dist/api/network/tcp.js +3 -0
- package/dist/api/network/udp.js +3 -0
- package/dist/api/network/upload.js +151 -0
- package/dist/api/network/utils.js +65 -0
- package/dist/api/network/websocket/index.js +70 -0
- package/dist/api/network/websocket/socketTask.js +63 -0
- package/dist/api/open-api/account.js +3 -0
- package/dist/api/open-api/address.js +3 -0
- package/dist/api/open-api/authorize.js +4 -0
- package/dist/api/open-api/card.js +4 -0
- package/dist/api/open-api/channels-live.js +8 -0
- package/dist/api/open-api/customer-service.js +3 -0
- package/dist/api/open-api/facial.js +6 -0
- package/dist/api/open-api/favorites.js +4 -0
- package/dist/api/open-api/group.js +3 -0
- package/dist/api/open-api/index.js +18 -0
- package/dist/api/open-api/invoice.js +4 -0
- package/dist/api/open-api/license-plate.js +3 -0
- package/dist/api/open-api/login.js +5 -0
- package/dist/api/open-api/red-package.js +3 -0
- package/dist/api/open-api/settings.js +4 -0
- package/dist/api/open-api/soter.js +5 -0
- package/dist/api/open-api/subscribe-message.js +3 -0
- package/dist/api/open-api/user-info.js +4 -0
- package/dist/api/open-api/werun.js +4 -0
- package/dist/api/payment/index.js +4 -0
- package/dist/api/route/index.js +3 -0
- package/dist/api/share/index.js +12 -0
- package/dist/api/storage/background-fetch.js +6 -0
- package/dist/api/storage/index.js +157 -0
- package/dist/api/swan/index.js +26 -0
- package/dist/api/taro.js +47 -0
- package/dist/api/ui/animation/index.js +284 -0
- package/dist/api/ui/background.js +4 -0
- package/dist/api/ui/custom-component.js +3 -0
- package/dist/api/ui/fonts.js +3 -0
- package/dist/api/ui/index.js +12 -0
- package/dist/api/ui/interaction/actionSheet.js +188 -0
- package/dist/api/ui/interaction/index.js +268 -0
- package/dist/api/ui/interaction/modal.js +207 -0
- package/dist/api/ui/interaction/toast.js +195 -0
- package/dist/api/ui/menu.js +3 -0
- package/dist/api/ui/navigation-bar/index.js +42 -0
- package/dist/api/ui/pull-down-refresh.js +26 -0
- package/dist/api/ui/scroll/index.js +83 -0
- package/dist/api/ui/sticky.js +3 -0
- package/dist/api/ui/tab-bar.js +282 -0
- package/dist/api/ui/window.js +31 -0
- package/dist/api/utils/handler.js +80 -0
- package/dist/api/utils/index.js +148 -0
- package/dist/api/worker/index.js +3 -0
- package/dist/api/wxml/index.js +6 -0
- package/dist/api/wxml/nodesRef.js +42 -0
- package/dist/api/wxml/selectorQuery.js +201 -0
- package/dist/index.cjs.js +7852 -11638
- package/dist/index.js +4 -0
- package/dist/taroApis.js +1 -1
- package/dist/types/type.js +2 -0
- package/package.json +14 -16
- 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 +233 -0
- package/src/api/canvas/canvasGetImageData.ts +27 -0
- package/src/api/canvas/canvasPutImageData.ts +24 -0
- package/src/api/canvas/canvasToTempFilePath.ts +24 -0
- package/src/api/canvas/createCanvasContext.ts +18 -0
- package/src/api/canvas/index.ts +10 -0
- package/src/api/cloud/index.ts +27 -0
- package/src/api/data-analysis/index.ts +6 -0
- package/src/api/device/accelerometer.ts +87 -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 +67 -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 +85 -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 +105 -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 +78 -0
- package/src/api/media/image/getImageInfo.ts +35 -0
- package/src/api/media/image/index.ts +13 -0
- package/src/api/media/image/previewImage.ts +80 -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 -27
- 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 -32
- package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
- package/src/api/network/websocket/index.ts +88 -0
- package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +17 -7
- 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 +181 -0
- package/src/api/swan/index.ts +31 -0
- package/src/{taro/index.js → api/taro.ts} +89 -104
- package/src/api/{createAnimation/index.js → ui/animation/index.ts} +52 -41
- 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} +95 -77
- 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 +27 -0
- package/src/api/ui/scroll/index.ts +85 -0
- 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} +36 -115
- package/src/api/worker/index.ts +4 -0
- package/src/api/wxml/index.ts +9 -0
- package/src/api/wxml/nodesRef.ts +56 -0
- package/src/api/wxml/selectorQuery.ts +219 -0
- 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/canvas/index.js +0 -4
- package/src/api/clipboard/index.js +0 -113
- package/src/api/compass/index.js +0 -99
- package/src/api/createSelectorQuery/index.js +0 -193
- 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/getImageInfo.js +0 -74
- package/src/api/image/index.js +0 -7
- package/src/api/image/previewImage.js +0 -94
- 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/scroll/index.js +0 -99
- 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 -402
- 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/webSocket/index.js +0 -103
- package/src/api/window/index.js +0 -38
- package/src/index.cjs.js +0 -11
- package/src/index.js +0 -6
package/src/api/vibrate/index.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { successHandler, errorHandler } from '../utils/index'
|
|
2
|
-
|
|
3
|
-
const vibrator = function vibrator (mm) {
|
|
4
|
-
try {
|
|
5
|
-
return window.navigator.vibrate(mm)
|
|
6
|
-
} catch (e) {
|
|
7
|
-
console.warn('当前浏览器不支持vibrate')
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 使手机发生较短时间的振动(15 ms)。仅在 iPhone 7 / 7 Plus 以上及 Android 机型生效
|
|
13
|
-
* @param {Object} object 参数
|
|
14
|
-
* @param {function} [object.success] 接口调用成功的回调函数
|
|
15
|
-
* @param {function} [object.fail] 接口调用失败的回调函数
|
|
16
|
-
* @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
17
|
-
*/
|
|
18
|
-
export const vibrateShort = ({ success, fail, complete } = {}) => {
|
|
19
|
-
if (vibrator) {
|
|
20
|
-
vibrator(15)
|
|
21
|
-
return successHandler(success, complete)({
|
|
22
|
-
errMsg: 'vibrateShort:ok'
|
|
23
|
-
})
|
|
24
|
-
} else {
|
|
25
|
-
return errorHandler(fail, complete)({
|
|
26
|
-
errMsg: 'vibrateShort:fail'
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 使手机发生较长时间的振动(400 ms)
|
|
33
|
-
* @param {Object} object 参数
|
|
34
|
-
* @param {function} [object.success] 接口调用成功的回调函数
|
|
35
|
-
* @param {function} [object.fail] 接口调用失败的回调函数
|
|
36
|
-
* @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
37
|
-
*/
|
|
38
|
-
export const vibrateLong = ({ success, fail, complete } = {}) => {
|
|
39
|
-
if (vibrator) {
|
|
40
|
-
vibrator(400)
|
|
41
|
-
return successHandler(success, complete)({
|
|
42
|
-
errMsg: 'vibrateLong:ok'
|
|
43
|
-
})
|
|
44
|
-
} else {
|
|
45
|
-
return errorHandler(fail, complete)({
|
|
46
|
-
errMsg: 'vibrateLong:fail'
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
}
|
package/src/api/video/index.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { shouldBeObject, getParameterError, findDOM } from '../utils'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {Object} ChooseVideoParam
|
|
5
|
-
* @property {Array.<string>} [sourceType=['album', 'camera']] 视频选择的来源
|
|
6
|
-
* @property {boolean} [compressed=true] 是否压缩所选择的视频文件
|
|
7
|
-
* @property {number} [maxDuration=60] 拍摄视频最长拍摄时间,单位秒
|
|
8
|
-
* @property {string} [camera=back] 默认拉起的是前置或者后置摄像头。部分 Android 手机下由于系统 ROM 不支持无法生效
|
|
9
|
-
* @property {function} [success] 接口调用成功的回调函数
|
|
10
|
-
* @property {function} [fail] 接口调用失败的回调函数
|
|
11
|
-
* @property {function} [complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 拍摄视频或从手机相册中选视频。
|
|
16
|
-
* @param {ChooseVideoParam} options
|
|
17
|
-
*/
|
|
18
|
-
export function chooseVideo (options) {
|
|
19
|
-
// options must be an Object
|
|
20
|
-
|
|
21
|
-
const isObject = shouldBeObject(options)
|
|
22
|
-
if (!isObject.res) {
|
|
23
|
-
const res = { errMsg: `chooseVideo${isObject.msg}` }
|
|
24
|
-
console.error(res.errMsg)
|
|
25
|
-
return Promise.reject(res)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const { count = 1, success, fail, complete } = options
|
|
29
|
-
const res = {
|
|
30
|
-
errMsg: 'chooseVideo:ok',
|
|
31
|
-
tempFilePaths: [],
|
|
32
|
-
tempFiles: []
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (count && typeof count !== 'number') {
|
|
36
|
-
res.errMsg = getParameterError({
|
|
37
|
-
name: 'chooseVideo',
|
|
38
|
-
para: 'count',
|
|
39
|
-
correct: 'Number',
|
|
40
|
-
wrong: count
|
|
41
|
-
})
|
|
42
|
-
console.error(res.errMsg)
|
|
43
|
-
typeof fail === 'function' && fail(res)
|
|
44
|
-
typeof complete === 'function' && complete(res)
|
|
45
|
-
return Promise.reject(res)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const taroChooseVideo = document.createElement('input')
|
|
49
|
-
taroChooseVideo.setAttribute('type', 'file')
|
|
50
|
-
taroChooseVideo.setAttribute('multiple', 'multiple')
|
|
51
|
-
taroChooseVideo.setAttribute('accept', 'video/*')
|
|
52
|
-
taroChooseVideo.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;')
|
|
53
|
-
document.body.appendChild(taroChooseVideo)
|
|
54
|
-
|
|
55
|
-
let taroChooseVideoCallback
|
|
56
|
-
const taroChooseVideoPromise = new Promise(resolve => {
|
|
57
|
-
taroChooseVideoCallback = resolve
|
|
58
|
-
})
|
|
59
|
-
const TaroMouseEvents = document.createEvent('MouseEvents')
|
|
60
|
-
TaroMouseEvents.initEvent('click', true, true)
|
|
61
|
-
taroChooseVideo.dispatchEvent(TaroMouseEvents)
|
|
62
|
-
taroChooseVideo.onchange = function (e) {
|
|
63
|
-
const arr = [...e.target.files]
|
|
64
|
-
arr && arr.forEach(item => {
|
|
65
|
-
const blob = new Blob([item])
|
|
66
|
-
const url = URL.createObjectURL(blob)
|
|
67
|
-
res.tempFilePaths.push(url)
|
|
68
|
-
res.tempFiles.push({ path: url, size: item.size, type: item.type })
|
|
69
|
-
})
|
|
70
|
-
typeof success === 'function' && success(res)
|
|
71
|
-
typeof complete === 'function' && complete(res)
|
|
72
|
-
taroChooseVideoCallback(res)
|
|
73
|
-
}
|
|
74
|
-
taroChooseVideoPromise.finally(() => {
|
|
75
|
-
document.body.removeChild(taroChooseVideo)
|
|
76
|
-
})
|
|
77
|
-
return taroChooseVideoPromise
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 创建 video 上下文 VideoContext 对象。
|
|
82
|
-
* @param {string} id <video> 组件的 id
|
|
83
|
-
*/
|
|
84
|
-
export function createVideoContext (id, inst) {
|
|
85
|
-
/** @type {HTMLVideoElement} */
|
|
86
|
-
return findDOM(inst).querySelector(`taro-video-core[id=${id}]`)
|
|
87
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import SocketTask from './socketTask'
|
|
2
|
-
import { shouldBeObject, getParameterError } from '../utils'
|
|
3
|
-
|
|
4
|
-
let socketTasks = []
|
|
5
|
-
let socketsCounter = 1
|
|
6
|
-
|
|
7
|
-
function connectSocket (options) {
|
|
8
|
-
const name = 'connectSocket'
|
|
9
|
-
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
// options must be an Object
|
|
12
|
-
const isObject = shouldBeObject(options)
|
|
13
|
-
if (!isObject.res) {
|
|
14
|
-
const res = { errMsg: `${name}${isObject.msg}` }
|
|
15
|
-
console.error(res.errMsg)
|
|
16
|
-
return reject(res)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const { url, protocols, success, fail, complete } = options
|
|
20
|
-
const res = { errMsg: 'connectSocket:ok' }
|
|
21
|
-
|
|
22
|
-
// options.url must be String
|
|
23
|
-
if (typeof url !== 'string') {
|
|
24
|
-
res.errMsg = getParameterError({
|
|
25
|
-
name,
|
|
26
|
-
para: 'url',
|
|
27
|
-
correct: 'String',
|
|
28
|
-
wrong: url
|
|
29
|
-
})
|
|
30
|
-
console.error(res.errMsg)
|
|
31
|
-
typeof fail === 'function' && fail(res)
|
|
32
|
-
typeof complete === 'function' && complete(res)
|
|
33
|
-
return reject(res)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// options.url must be invalid
|
|
37
|
-
if (!url.startsWith('ws://') && !url.startsWith('wss://')) {
|
|
38
|
-
res.errMsg = `request:fail invalid url "${url}"`
|
|
39
|
-
console.error(res.errMsg)
|
|
40
|
-
typeof fail === 'function' && fail(res)
|
|
41
|
-
typeof complete === 'function' && complete(res)
|
|
42
|
-
return reject(res)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// protocols must be array
|
|
46
|
-
const _protocols = Array.isArray(protocols) ? protocols : null
|
|
47
|
-
|
|
48
|
-
// 2 connection at most
|
|
49
|
-
if (socketTasks.length > 1) {
|
|
50
|
-
res.errMsg = '同时最多发起 2 个 socket 请求,更多请参考文档。'
|
|
51
|
-
console.error(res.errMsg)
|
|
52
|
-
typeof fail === 'function' && fail(res)
|
|
53
|
-
typeof complete === 'function' && complete(res)
|
|
54
|
-
return reject(res)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const task = new SocketTask(url, _protocols)
|
|
58
|
-
task._destroyWhenClose = function () {
|
|
59
|
-
socketTasks = socketTasks.filter(socketTask => socketTask !== this)
|
|
60
|
-
}
|
|
61
|
-
socketTasks.push(task)
|
|
62
|
-
|
|
63
|
-
res.socketTaskId = socketsCounter++
|
|
64
|
-
typeof success === 'function' && success(res)
|
|
65
|
-
typeof complete === 'function' && complete(res)
|
|
66
|
-
|
|
67
|
-
return resolve(task)
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
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
|
-
function closeSocket () {
|
|
88
|
-
console.warn('Deprecated.Please use socketTask.close instead.')
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function onSocketClose () {
|
|
92
|
-
console.warn('Deprecated.Please use socketTask.onClose instead.')
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export {
|
|
96
|
-
connectSocket,
|
|
97
|
-
onSocketOpen,
|
|
98
|
-
onSocketError,
|
|
99
|
-
sendSocketMessage,
|
|
100
|
-
onSocketMessage,
|
|
101
|
-
closeSocket,
|
|
102
|
-
onSocketClose
|
|
103
|
-
}
|
package/src/api/window/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { createCallbackManager } from '../utils/index'
|
|
2
|
-
|
|
3
|
-
const callbackManager = createCallbackManager()
|
|
4
|
-
|
|
5
|
-
const resizeListener = () => {
|
|
6
|
-
callbackManager.trigger({
|
|
7
|
-
windowWidth: window.screen.width,
|
|
8
|
-
windowHeight: window.screen.height
|
|
9
|
-
})
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @typedef {Object} WindowResizeParam
|
|
14
|
-
* @property {number} windowWidth 变化后的窗口宽度,单位 px
|
|
15
|
-
* @property {number} windowHeight 变化后的窗口高度,单位 px
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 监听窗口尺寸变化事件
|
|
20
|
-
* @param {(size: WindowResizeParam) => void} callback 窗口尺寸变化事件的回调函数
|
|
21
|
-
*/
|
|
22
|
-
export const onWindowResize = callback => {
|
|
23
|
-
callbackManager.add(callback)
|
|
24
|
-
if (callbackManager.count() === 1) {
|
|
25
|
-
window.addEventListener('resize', resizeListener)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 取消监听窗口尺寸变化事件
|
|
31
|
-
* @param {(size: WindowResizeParam) => void} callback 窗口尺寸变化事件的回调函数
|
|
32
|
-
*/
|
|
33
|
-
export const offWindowResize = callback => {
|
|
34
|
-
callbackManager.remove(callback)
|
|
35
|
-
if (callbackManager.count() === 0) {
|
|
36
|
-
window.removeEventListener('resize', resizeListener)
|
|
37
|
-
}
|
|
38
|
-
}
|
package/src/index.cjs.js
DELETED