@tarojs/taro-h5 3.3.18 → 3.3.19
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 +3 -0
- package/dist/api/ai/facial.js +4 -0
- package/dist/api/ai/index.js +2 -0
- package/dist/api/ai/visual.js +2 -0
- package/dist/api/alipay/index.js +2 -0
- package/dist/api/base/crypto.js +2 -0
- package/dist/api/base/debug.js +4 -0
- package/dist/api/base/index.js +16 -0
- package/dist/api/base/performance.js +3 -0
- package/dist/api/base/system/index.js +2 -0
- package/dist/api/base/system/info.js +56 -0
- package/dist/api/base/system/network.js +52 -0
- package/dist/api/base/update.js +3 -0
- package/dist/api/base/weapp/app-event.js +17 -0
- package/dist/api/base/weapp/life-cycle.js +3 -0
- package/dist/api/canvas/CanvasContext.js +182 -0
- package/dist/api/canvas/canvasGetImageData.js +21 -0
- package/dist/api/canvas/canvasPutImageData.js +17 -0
- package/dist/api/canvas/canvasToTempFilePath.js +18 -0
- package/dist/api/canvas/createCanvasContext.js +13 -0
- package/dist/api/canvas/index.js +7 -0
- package/dist/api/cloud/index.js +14 -0
- package/dist/api/data-analysis/index.js +5 -0
- package/dist/api/device/accelerometer.js +71 -0
- package/dist/api/device/accessibility.js +2 -0
- package/dist/api/device/battery.js +3 -0
- package/dist/api/device/bluetooth-ble.js +17 -0
- package/dist/api/device/bluetooth-peripheral.js +4 -0
- package/dist/api/device/bluetooth.js +14 -0
- package/dist/api/device/calendar.js +3 -0
- package/dist/api/device/clipboard.js +48 -0
- package/dist/api/device/compass.js +52 -0
- package/dist/api/device/contact.js +3 -0
- package/dist/api/device/crypto.js +2 -0
- package/dist/api/device/gyroscope.js +5 -0
- package/dist/api/device/iBeacon.js +8 -0
- package/dist/api/device/index.js +22 -0
- package/dist/api/device/keyboard.js +5 -0
- package/dist/api/device/memory.js +3 -0
- package/dist/api/device/motion.js +69 -0
- package/dist/api/device/nfc.js +8 -0
- package/dist/api/device/phone.js +23 -0
- package/dist/api/device/scan.js +5 -0
- package/dist/api/device/screen.js +7 -0
- package/dist/api/device/vibrate.js +29 -0
- package/dist/api/device/wifi.js +11 -0
- package/dist/api/ext/index.js +3 -0
- package/dist/api/files/index.js +9 -0
- package/dist/api/framework/index.js +6 -0
- package/dist/api/index.js +24 -0
- package/dist/api/location/chooseLocation.js +88 -0
- package/dist/api/location/index.js +12 -0
- package/dist/api/location/style.css +79 -0
- package/dist/api/media/audio/index.js +81 -0
- package/dist/api/media/background-audio.js +10 -0
- package/dist/api/media/camera.js +2 -0
- package/dist/api/media/editor.js +17 -0
- package/dist/api/media/image/chooseImage.js +70 -0
- package/dist/api/media/image/getImageInfo.js +27 -0
- package/dist/api/media/image/index.js +8 -0
- package/dist/api/media/image/previewImage.js +78 -0
- package/dist/api/media/index.js +13 -0
- package/dist/api/media/live.js +3 -0
- package/dist/api/media/map.js +2 -0
- package/dist/api/media/media-recorder.js +2 -0
- package/dist/api/media/recorder.js +4 -0
- package/dist/api/media/video/index.js +65 -0
- package/dist/api/media/video-decoder.js +2 -0
- package/dist/api/media/video-processing.js +2 -0
- package/dist/api/media/voip.js +15 -0
- package/dist/api/navigate/index.js +5 -0
- package/dist/api/network/download.js +101 -0
- package/dist/api/network/index.js +7 -0
- package/dist/api/network/mdns.js +11 -0
- package/dist/api/network/request/index.js +123 -0
- package/dist/api/network/tcp.js +2 -0
- package/dist/api/network/udp.js +2 -0
- package/dist/api/network/upload.js +129 -0
- package/dist/api/network/utils.js +30 -0
- package/dist/api/network/websocket/index.js +65 -0
- package/dist/api/network/websocket/socketTask.js +61 -0
- package/dist/api/open-api/account.js +2 -0
- package/dist/api/open-api/address.js +2 -0
- package/dist/api/open-api/authorize.js +3 -0
- package/dist/api/open-api/card.js +3 -0
- package/dist/api/open-api/channels-live.js +7 -0
- package/dist/api/open-api/customer-service.js +2 -0
- package/dist/api/open-api/facial.js +5 -0
- package/dist/api/open-api/favorites.js +3 -0
- package/dist/api/open-api/group.js +2 -0
- package/dist/api/open-api/index.js +18 -0
- package/dist/api/open-api/invoice.js +3 -0
- package/dist/api/open-api/license-plate.js +2 -0
- package/dist/api/open-api/login.js +4 -0
- package/dist/api/open-api/red-package.js +2 -0
- package/dist/api/open-api/settings.js +3 -0
- package/dist/api/open-api/soter.js +4 -0
- package/dist/api/open-api/subscribe-message.js +2 -0
- package/dist/api/open-api/user-info.js +3 -0
- package/dist/api/open-api/werun.js +3 -0
- package/dist/api/payment/index.js +3 -0
- package/dist/api/route/index.js +1 -0
- package/dist/api/share/index.js +11 -0
- package/dist/api/storage/background-fetch.js +5 -0
- package/dist/api/storage/index.js +152 -0
- package/dist/api/swan/index.js +22 -0
- package/dist/api/taro.js +59 -0
- package/dist/api/ui/animation/index.js +255 -0
- package/dist/api/ui/background.js +3 -0
- package/dist/api/ui/custom-component.js +2 -0
- package/dist/api/ui/fonts.js +2 -0
- package/dist/api/ui/index.js +12 -0
- package/dist/api/ui/interaction/actionSheet.js +172 -0
- package/dist/api/ui/interaction/index.js +263 -0
- package/dist/api/ui/interaction/modal.js +185 -0
- package/dist/api/ui/interaction/toast.js +179 -0
- package/dist/api/ui/menu.js +2 -0
- package/dist/api/ui/navigation-bar/index.js +37 -0
- package/dist/api/ui/pull-down-refresh.js +20 -0
- package/dist/api/ui/scroll/index.js +80 -0
- package/dist/api/ui/sticky.js +2 -0
- package/dist/api/ui/tab-bar.js +250 -0
- package/dist/api/ui/window.js +22 -0
- package/dist/api/utils/handler.js +64 -0
- package/dist/api/utils/index.js +141 -0
- package/dist/api/worker/index.js +2 -0
- package/dist/api/wxml/index.js +6 -0
- package/dist/api/wxml/nodesRef.js +35 -0
- package/dist/api/wxml/selectorQuery.js +140 -0
- package/dist/index.cjs.js +4261 -5796
- package/dist/index.js +4 -9493
- package/dist/types/type.js +2 -0
- package/package.json +8 -11
- package/src/api/network/download.ts +5 -5
- package/src/api/network/upload.ts +5 -5
- package/src/api/network/websocket/index.ts +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
export class EditorContext {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.blur = temporarilyNotSupport('EditorContext.blur');
|
|
5
|
+
this.clear = temporarilyNotSupport('EditorContext.clear');
|
|
6
|
+
this.format = temporarilyNotSupport('EditorContext.format');
|
|
7
|
+
this.getContents = temporarilyNotSupport('EditorContext.getContents');
|
|
8
|
+
this.insertDivider = temporarilyNotSupport('EditorContext.insertDivider');
|
|
9
|
+
this.insertImage = temporarilyNotSupport('EditorContext.insertImage');
|
|
10
|
+
this.insertText = temporarilyNotSupport('EditorContext.insertText');
|
|
11
|
+
this.redo = temporarilyNotSupport('EditorContext.redo');
|
|
12
|
+
this.removeFormat = temporarilyNotSupport('EditorContext.removeFormat');
|
|
13
|
+
this.scrollIntoView = temporarilyNotSupport('EditorContext.scrollIntoView');
|
|
14
|
+
this.setContents = temporarilyNotSupport('EditorContext.setContents');
|
|
15
|
+
this.undo = temporarilyNotSupport('EditorContext.undo');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { MethodHandler } from '../../utils/handler';
|
|
2
|
+
import { shouldBeObject, getParameterError } from '../../utils';
|
|
3
|
+
export const chooseImage = function (options) {
|
|
4
|
+
const isObject = shouldBeObject(options);
|
|
5
|
+
if (!isObject.flag) {
|
|
6
|
+
const res = { errMsg: `chooseImage:fail ${isObject.msg}` };
|
|
7
|
+
console.error(res.errMsg);
|
|
8
|
+
return Promise.reject(res);
|
|
9
|
+
}
|
|
10
|
+
const { count = 1, success, fail, complete, imageId = 'taroChooseImage' } = options;
|
|
11
|
+
const handle = new MethodHandler({ name: 'chooseImage', success, fail, complete });
|
|
12
|
+
const res = {
|
|
13
|
+
tempFilePaths: [],
|
|
14
|
+
tempFiles: []
|
|
15
|
+
};
|
|
16
|
+
if (count && typeof count !== 'number') {
|
|
17
|
+
res.errMsg = getParameterError({
|
|
18
|
+
para: 'count',
|
|
19
|
+
correct: 'Number',
|
|
20
|
+
wrong: count
|
|
21
|
+
});
|
|
22
|
+
return handle.fail(res);
|
|
23
|
+
}
|
|
24
|
+
let el = document.getElementById(imageId);
|
|
25
|
+
if (!el) {
|
|
26
|
+
const obj = document.createElement('input');
|
|
27
|
+
obj.setAttribute('type', 'file');
|
|
28
|
+
obj.setAttribute('id', imageId);
|
|
29
|
+
if (count > 1) {
|
|
30
|
+
obj.setAttribute('multiple', 'multiple');
|
|
31
|
+
}
|
|
32
|
+
obj.setAttribute('accept', 'image/*');
|
|
33
|
+
obj.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;');
|
|
34
|
+
document.body.appendChild(obj);
|
|
35
|
+
el = document.getElementById(imageId);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (count > 1) {
|
|
39
|
+
el.setAttribute('multiple', 'multiple');
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
el.removeAttribute('multiple');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return new Promise(resolve => {
|
|
46
|
+
const TaroMouseEvents = document.createEvent('MouseEvents');
|
|
47
|
+
TaroMouseEvents.initEvent('click', true, true);
|
|
48
|
+
if (el) {
|
|
49
|
+
el.dispatchEvent(TaroMouseEvents);
|
|
50
|
+
el.onchange = function (e) {
|
|
51
|
+
const target = e.target;
|
|
52
|
+
if (target) {
|
|
53
|
+
const files = target.files || [];
|
|
54
|
+
const arr = [...files];
|
|
55
|
+
arr && arr.forEach(item => {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const blob = new Blob([item], {
|
|
58
|
+
type: item.type
|
|
59
|
+
});
|
|
60
|
+
const url = URL.createObjectURL(blob);
|
|
61
|
+
(_a = res.tempFilePaths) === null || _a === void 0 ? void 0 : _a.push(url);
|
|
62
|
+
(_b = res.tempFiles) === null || _b === void 0 ? void 0 : _b.push({ path: url, size: item.size, type: item.type, originalFileObj: item });
|
|
63
|
+
});
|
|
64
|
+
handle.success(res, resolve);
|
|
65
|
+
target.value = '';
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { shouldBeObject } from '../../utils';
|
|
2
|
+
import { MethodHandler } from '../../utils/handler';
|
|
3
|
+
export const getImageInfo = (options) => {
|
|
4
|
+
const isObject = shouldBeObject(options);
|
|
5
|
+
if (!isObject.flag) {
|
|
6
|
+
const res = { errMsg: `getImageInfo:fail ${isObject.msg}` };
|
|
7
|
+
console.error(res.errMsg);
|
|
8
|
+
return Promise.reject(res);
|
|
9
|
+
}
|
|
10
|
+
const { src, success, fail, complete } = options;
|
|
11
|
+
const handle = new MethodHandler({ name: 'getImageInfo', success, fail, complete });
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const image = new Image();
|
|
14
|
+
image.onload = () => {
|
|
15
|
+
handle.success({
|
|
16
|
+
width: image.naturalWidth,
|
|
17
|
+
height: image.naturalHeight
|
|
18
|
+
}, resolve);
|
|
19
|
+
};
|
|
20
|
+
image.onerror = (e) => {
|
|
21
|
+
handle.fail({
|
|
22
|
+
errMsg: e.message
|
|
23
|
+
}, reject);
|
|
24
|
+
};
|
|
25
|
+
image.src = src;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../../utils';
|
|
2
|
+
export const saveImageToPhotosAlbum = temporarilyNotSupport('saveImageToPhotosAlbum');
|
|
3
|
+
export const previewMedia = temporarilyNotSupport('previewMedia');
|
|
4
|
+
export * from './previewImage';
|
|
5
|
+
export * from './getImageInfo';
|
|
6
|
+
export const compressImage = temporarilyNotSupport('compressImage');
|
|
7
|
+
export const chooseMessageFile = temporarilyNotSupport('chooseMessageFile');
|
|
8
|
+
export * from './chooseImage';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { shouldBeObject } from '../../utils';
|
|
2
|
+
import { MethodHandler } from '../../utils/handler';
|
|
3
|
+
export const previewImage = async (options) => {
|
|
4
|
+
function loadImage(url, loadFail) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
const item = document.createElement('taro-swiper-item-core');
|
|
7
|
+
item.style.cssText = `
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: start;
|
|
10
|
+
justify-content: center;
|
|
11
|
+
overflow-y: scroll;
|
|
12
|
+
`;
|
|
13
|
+
const image = new Image();
|
|
14
|
+
image.style.maxWidth = '100%';
|
|
15
|
+
image.src = url;
|
|
16
|
+
const div = document.createElement('div');
|
|
17
|
+
div.style.cssText = `
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: center;
|
|
21
|
+
max-width: 100%;
|
|
22
|
+
min-height: 100%;
|
|
23
|
+
`;
|
|
24
|
+
div.appendChild(image);
|
|
25
|
+
item.appendChild(div);
|
|
26
|
+
resolve(item);
|
|
27
|
+
if (typeof loadFail === 'function') {
|
|
28
|
+
image.addEventListener('error', (err) => {
|
|
29
|
+
loadFail({ errMsg: err.message });
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const isObject = shouldBeObject(options);
|
|
35
|
+
if (!isObject.flag) {
|
|
36
|
+
const res = { errMsg: `previewImage:fail ${isObject.msg}` };
|
|
37
|
+
console.error(res.errMsg);
|
|
38
|
+
return Promise.reject(res);
|
|
39
|
+
}
|
|
40
|
+
const { urls = [], current = '', success, fail, complete } = options;
|
|
41
|
+
const handle = new MethodHandler({ name: 'previewImage', success, fail, complete });
|
|
42
|
+
const container = document.createElement('div');
|
|
43
|
+
container.classList.add('preview-image');
|
|
44
|
+
container.style.cssText = `
|
|
45
|
+
position: fixed;
|
|
46
|
+
top: 0;
|
|
47
|
+
left: 0;
|
|
48
|
+
z-index: 1050;
|
|
49
|
+
width: 100%;
|
|
50
|
+
height: 100%;
|
|
51
|
+
overflow: hidden;
|
|
52
|
+
outline: 0;
|
|
53
|
+
background-color: #111;
|
|
54
|
+
`;
|
|
55
|
+
container.addEventListener('click', () => {
|
|
56
|
+
container.remove();
|
|
57
|
+
});
|
|
58
|
+
const swiper = document.createElement('taro-swiper-core');
|
|
59
|
+
swiper.full = true;
|
|
60
|
+
let children = [];
|
|
61
|
+
try {
|
|
62
|
+
children = await Promise.all(urls.map(e => loadImage(e, fail)));
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return handle.fail({
|
|
66
|
+
errMsg: error
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
for (let i = 0; i < children.length; i++) {
|
|
70
|
+
const child = children[i];
|
|
71
|
+
swiper.appendChild(child);
|
|
72
|
+
}
|
|
73
|
+
const currentIndex = urls.indexOf(current);
|
|
74
|
+
swiper.current = currentIndex;
|
|
75
|
+
container.appendChild(swiper);
|
|
76
|
+
document.body.appendChild(container);
|
|
77
|
+
return handle.success();
|
|
78
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './audio';
|
|
2
|
+
export * from './background-audio';
|
|
3
|
+
export * from './camera';
|
|
4
|
+
export * from './editor';
|
|
5
|
+
export * from './image';
|
|
6
|
+
export * from './live';
|
|
7
|
+
export * from './map';
|
|
8
|
+
export * from './media-recorder';
|
|
9
|
+
export * from './recorder';
|
|
10
|
+
export * from './video';
|
|
11
|
+
export * from './video-decoder';
|
|
12
|
+
export * from './video-processing';
|
|
13
|
+
export * from './voip';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { MethodHandler } from '../../utils/handler';
|
|
2
|
+
import { findDOM, shouldBeObject, temporarilyNotSupport } from '../../utils';
|
|
3
|
+
export const saveVideoToPhotosAlbum = temporarilyNotSupport('saveVideoToPhotosAlbum');
|
|
4
|
+
export const openVideoEditor = temporarilyNotSupport('openVideoEditor');
|
|
5
|
+
export const getVideoInfo = temporarilyNotSupport('getVideoInfo');
|
|
6
|
+
export const createVideoContext = (id, inst) => {
|
|
7
|
+
const el = findDOM(inst);
|
|
8
|
+
return el === null || el === void 0 ? void 0 : el.querySelector(`taro-video-core[id=${id}]`);
|
|
9
|
+
};
|
|
10
|
+
export const compressVideo = temporarilyNotSupport('compressVideo');
|
|
11
|
+
export const chooseVideo = (options) => {
|
|
12
|
+
const isObject = shouldBeObject(options);
|
|
13
|
+
if (!isObject.flag) {
|
|
14
|
+
const res = { errMsg: `chooseVideo:fail ${isObject.msg}` };
|
|
15
|
+
console.error(res.errMsg);
|
|
16
|
+
return Promise.reject(res);
|
|
17
|
+
}
|
|
18
|
+
const { success, fail, complete } = options;
|
|
19
|
+
const handle = new MethodHandler({ name: 'chooseVideo', success, fail, complete });
|
|
20
|
+
const res = {
|
|
21
|
+
tempFilePath: '',
|
|
22
|
+
duration: 0,
|
|
23
|
+
size: 0,
|
|
24
|
+
height: 0,
|
|
25
|
+
width: 0
|
|
26
|
+
};
|
|
27
|
+
const inputEl = document.createElement('input');
|
|
28
|
+
inputEl.setAttribute('type', 'file');
|
|
29
|
+
inputEl.setAttribute('multiple', 'multiple');
|
|
30
|
+
inputEl.setAttribute('accept', 'video/*');
|
|
31
|
+
inputEl.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;');
|
|
32
|
+
document.body.appendChild(inputEl);
|
|
33
|
+
return new Promise(resolve => {
|
|
34
|
+
const TaroMouseEvents = document.createEvent('MouseEvents');
|
|
35
|
+
TaroMouseEvents.initEvent('click', true, true);
|
|
36
|
+
inputEl.dispatchEvent(TaroMouseEvents);
|
|
37
|
+
inputEl.onchange = function (e) {
|
|
38
|
+
var _a;
|
|
39
|
+
const target = e.target;
|
|
40
|
+
const file = (_a = target.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
41
|
+
const reader = new FileReader();
|
|
42
|
+
reader.onload = function (event) {
|
|
43
|
+
var _a;
|
|
44
|
+
const videoEl = document.createElement('video');
|
|
45
|
+
const url = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
46
|
+
videoEl.preload = 'metadata';
|
|
47
|
+
videoEl.src = url;
|
|
48
|
+
videoEl.onloadedmetadata = () => {
|
|
49
|
+
res.tempFilePath = url;
|
|
50
|
+
res.duration = videoEl.duration;
|
|
51
|
+
res.size = event.total;
|
|
52
|
+
res.height = videoEl.videoHeight;
|
|
53
|
+
res.width = videoEl.videoHeight;
|
|
54
|
+
return handle.success(res, resolve);
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
if (file) {
|
|
58
|
+
reader.readAsDataURL(file);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}).finally(() => {
|
|
62
|
+
document.body.removeChild(inputEl);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
export const chooseMedia = temporarilyNotSupport('chooseMedia');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
export const updateVoIPChatMuteConfig = temporarilyNotSupport('updateVoIPChatMuteConfig');
|
|
3
|
+
export const subscribeVoIPVideoMembers = temporarilyNotSupport('subscribeVoIPVideoMembers');
|
|
4
|
+
export const setEnable1v1Chat = temporarilyNotSupport('setEnable1v1Chat');
|
|
5
|
+
export const onVoIPVideoMembersChanged = temporarilyNotSupport('onVoIPVideoMembersChanged');
|
|
6
|
+
export const onVoIPChatStateChanged = temporarilyNotSupport('onVoIPChatStateChanged');
|
|
7
|
+
export const onVoIPChatSpeakersChanged = temporarilyNotSupport('onVoIPChatSpeakersChanged');
|
|
8
|
+
export const onVoIPChatMembersChanged = temporarilyNotSupport('onVoIPChatMembersChanged');
|
|
9
|
+
export const onVoIPChatInterrupted = temporarilyNotSupport('onVoIPChatInterrupted');
|
|
10
|
+
export const offVoIPVideoMembersChanged = temporarilyNotSupport('offVoIPVideoMembersChanged');
|
|
11
|
+
export const offVoIPChatStateChanged = temporarilyNotSupport('offVoIPChatStateChanged');
|
|
12
|
+
export const offVoIPChatMembersChanged = temporarilyNotSupport('offVoIPChatMembersChanged');
|
|
13
|
+
export const offVoIPChatInterrupted = temporarilyNotSupport('offVoIPChatInterrupted');
|
|
14
|
+
export const joinVoIPChat = temporarilyNotSupport('joinVoIPChat');
|
|
15
|
+
export const exitVoIPChat = temporarilyNotSupport('exitVoIPChat');
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
export const openEmbeddedMiniProgram = temporarilyNotSupport('openEmbeddedMiniProgram');
|
|
3
|
+
export const navigateToMiniProgram = temporarilyNotSupport('navigateToMiniProgram');
|
|
4
|
+
export const navigateBackMiniProgram = temporarilyNotSupport('navigateBackMiniProgram');
|
|
5
|
+
export const exitMiniProgram = temporarilyNotSupport('exitMiniProgram');
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { CallbackManager } from '../utils/handler';
|
|
2
|
+
import { NETWORK_TIMEOUT, setHeader, XHR_STATS } from './utils';
|
|
3
|
+
const createDownloadTask = ({ url, header, success, error }) => {
|
|
4
|
+
let timeout;
|
|
5
|
+
const apiName = 'downloadFile';
|
|
6
|
+
const xhr = new XMLHttpRequest();
|
|
7
|
+
const callbackManager = {
|
|
8
|
+
headersReceived: new CallbackManager(),
|
|
9
|
+
progressUpdate: new CallbackManager()
|
|
10
|
+
};
|
|
11
|
+
xhr.open('GET', url, true);
|
|
12
|
+
xhr.responseType = 'blob';
|
|
13
|
+
setHeader(xhr, header);
|
|
14
|
+
xhr.onprogress = e => {
|
|
15
|
+
const { loaded, total } = e;
|
|
16
|
+
callbackManager.progressUpdate.trigger({
|
|
17
|
+
progress: Math.round(loaded / total * 100),
|
|
18
|
+
totalBytesWritten: loaded,
|
|
19
|
+
totalBytesExpectedToWrite: total
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
xhr.onreadystatechange = () => {
|
|
23
|
+
if (xhr.readyState !== XHR_STATS.HEADERS_RECEIVED)
|
|
24
|
+
return;
|
|
25
|
+
callbackManager.headersReceived.trigger({
|
|
26
|
+
header: xhr.getAllResponseHeaders()
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
xhr.onload = () => {
|
|
30
|
+
const response = xhr.response;
|
|
31
|
+
const status = xhr.status;
|
|
32
|
+
success({
|
|
33
|
+
errMsg: `${apiName}:ok`,
|
|
34
|
+
statusCode: status,
|
|
35
|
+
tempFilePath: window.URL.createObjectURL(response)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
xhr.onabort = () => {
|
|
39
|
+
clearTimeout(timeout);
|
|
40
|
+
error({
|
|
41
|
+
errMsg: `${apiName}:fail abort`
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
xhr.onerror = (e) => {
|
|
45
|
+
error({
|
|
46
|
+
errMsg: `${apiName}:fail ${e.message}`
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const abort = () => {
|
|
50
|
+
xhr.abort();
|
|
51
|
+
};
|
|
52
|
+
const send = () => {
|
|
53
|
+
xhr.send();
|
|
54
|
+
timeout = setTimeout(() => {
|
|
55
|
+
xhr.onabort = null;
|
|
56
|
+
xhr.onload = null;
|
|
57
|
+
xhr.onprogress = null;
|
|
58
|
+
xhr.onreadystatechange = null;
|
|
59
|
+
xhr.onerror = null;
|
|
60
|
+
abort();
|
|
61
|
+
error({
|
|
62
|
+
errMsg: `${apiName}:fail timeout`
|
|
63
|
+
});
|
|
64
|
+
}, NETWORK_TIMEOUT);
|
|
65
|
+
};
|
|
66
|
+
send();
|
|
67
|
+
const onHeadersReceived = callbackManager.headersReceived.add;
|
|
68
|
+
const offHeadersReceived = callbackManager.headersReceived.remove;
|
|
69
|
+
const onProgressUpdate = callbackManager.progressUpdate.add;
|
|
70
|
+
const offProgressUpdate = callbackManager.progressUpdate.remove;
|
|
71
|
+
return {
|
|
72
|
+
abort,
|
|
73
|
+
onHeadersReceived,
|
|
74
|
+
offHeadersReceived,
|
|
75
|
+
onProgressUpdate,
|
|
76
|
+
offProgressUpdate
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export const downloadFile = ({ url, header, success, fail, complete }) => {
|
|
80
|
+
let task;
|
|
81
|
+
const result = new Promise((resolve, reject) => {
|
|
82
|
+
task = createDownloadTask({
|
|
83
|
+
url,
|
|
84
|
+
header,
|
|
85
|
+
success: res => {
|
|
86
|
+
success && success(res);
|
|
87
|
+
complete && complete(res);
|
|
88
|
+
resolve(res);
|
|
89
|
+
},
|
|
90
|
+
error: res => {
|
|
91
|
+
fail && fail(res);
|
|
92
|
+
complete && complete(res);
|
|
93
|
+
reject(res);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
result.headersReceive = task.onHeadersReceived;
|
|
98
|
+
result.progress = task.onProgressUpdate;
|
|
99
|
+
result.abort = task.abort;
|
|
100
|
+
return result;
|
|
101
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
export const stopLocalServiceDiscovery = temporarilyNotSupport('stopLocalServiceDiscovery');
|
|
3
|
+
export const startLocalServiceDiscovery = temporarilyNotSupport('startLocalServiceDiscovery');
|
|
4
|
+
export const onLocalServiceResolveFail = temporarilyNotSupport('onLocalServiceResolveFail');
|
|
5
|
+
export const onLocalServiceLost = temporarilyNotSupport('onLocalServiceLost');
|
|
6
|
+
export const onLocalServiceFound = temporarilyNotSupport('onLocalServiceFound');
|
|
7
|
+
export const onLocalServiceDiscoveryStop = temporarilyNotSupport('onLocalServiceDiscoveryStop');
|
|
8
|
+
export const offLocalServiceResolveFail = temporarilyNotSupport('offLocalServiceResolveFail');
|
|
9
|
+
export const offLocalServiceLost = temporarilyNotSupport('offLocalServiceLost');
|
|
10
|
+
export const offLocalServiceFound = temporarilyNotSupport('offLocalServiceFound');
|
|
11
|
+
export const offLocalServiceDiscoveryStop = temporarilyNotSupport('offLocalServiceDiscoveryStop');
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import Taro from '@tarojs/api';
|
|
2
|
+
import 'whatwg-fetch';
|
|
3
|
+
import jsonpRetry from 'jsonp-retry';
|
|
4
|
+
import { serializeParams } from '../../utils';
|
|
5
|
+
const { Link } = Taro;
|
|
6
|
+
function generateRequestUrlWithParams(url, params) {
|
|
7
|
+
params = typeof params === 'string' ? params : serializeParams(params);
|
|
8
|
+
if (params) {
|
|
9
|
+
url += (~url.indexOf('?') ? '&' : '?') + params;
|
|
10
|
+
}
|
|
11
|
+
url = url.replace('?&', '?');
|
|
12
|
+
return url;
|
|
13
|
+
}
|
|
14
|
+
function _request(options) {
|
|
15
|
+
options = options || {};
|
|
16
|
+
if (typeof options === 'string') {
|
|
17
|
+
options = {
|
|
18
|
+
url: options
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const { success, complete, fail } = options;
|
|
22
|
+
let url = options.url;
|
|
23
|
+
const params = {};
|
|
24
|
+
const res = {};
|
|
25
|
+
if (options.jsonp) {
|
|
26
|
+
Object.assign(params, options);
|
|
27
|
+
params.params = options.data;
|
|
28
|
+
params.cache = options.jsonpCache;
|
|
29
|
+
if (typeof options.jsonp === 'string') {
|
|
30
|
+
params.name = options.jsonp;
|
|
31
|
+
}
|
|
32
|
+
delete params.jsonp;
|
|
33
|
+
return jsonpRetry(url, params)
|
|
34
|
+
.then(data => {
|
|
35
|
+
res.statusCode = 200;
|
|
36
|
+
res.data = data;
|
|
37
|
+
typeof success === 'function' && success(res);
|
|
38
|
+
typeof complete === 'function' && complete(res);
|
|
39
|
+
return res;
|
|
40
|
+
})
|
|
41
|
+
.catch(err => {
|
|
42
|
+
typeof fail === 'function' && fail(err);
|
|
43
|
+
typeof complete === 'function' && complete(res);
|
|
44
|
+
return Promise.reject(err);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
params.method = options.method || 'GET';
|
|
48
|
+
const methodUpper = params.method.toUpperCase();
|
|
49
|
+
params.cache = options.cache || 'default';
|
|
50
|
+
if (methodUpper === 'GET' || methodUpper === 'HEAD') {
|
|
51
|
+
url = generateRequestUrlWithParams(url, options.data);
|
|
52
|
+
}
|
|
53
|
+
else if (typeof options.data === 'object') {
|
|
54
|
+
options.header = options.header || {};
|
|
55
|
+
const keyOfContentType = Object.keys(options.header).find(item => item.toLowerCase() === 'content-type');
|
|
56
|
+
if (!keyOfContentType) {
|
|
57
|
+
options.header['Content-Type'] = 'application/json';
|
|
58
|
+
}
|
|
59
|
+
const contentType = options.header[keyOfContentType || 'Content-Type'];
|
|
60
|
+
if (contentType.indexOf('application/json') >= 0) {
|
|
61
|
+
params.body = JSON.stringify(options.data);
|
|
62
|
+
}
|
|
63
|
+
else if (contentType.indexOf('application/x-www-form-urlencoded') >= 0) {
|
|
64
|
+
params.body = serializeParams(options.data);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
params.body = options.data;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
params.body = options.data;
|
|
72
|
+
}
|
|
73
|
+
if (options.header) {
|
|
74
|
+
params.headers = options.header;
|
|
75
|
+
}
|
|
76
|
+
if (options.mode) {
|
|
77
|
+
params.mode = options.mode;
|
|
78
|
+
}
|
|
79
|
+
if (options.signal) {
|
|
80
|
+
params.signal = options.signal;
|
|
81
|
+
}
|
|
82
|
+
params.credentials = options.credentials;
|
|
83
|
+
return fetch(url, params)
|
|
84
|
+
.then(response => {
|
|
85
|
+
res.statusCode = response.status;
|
|
86
|
+
res.header = {};
|
|
87
|
+
for (const key of response.headers.keys()) {
|
|
88
|
+
res.header[key] = response.headers.get(key);
|
|
89
|
+
}
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
throw response;
|
|
92
|
+
}
|
|
93
|
+
if (options.responseType === 'arraybuffer') {
|
|
94
|
+
return response.arrayBuffer();
|
|
95
|
+
}
|
|
96
|
+
if (res.statusCode !== 204) {
|
|
97
|
+
if (options.dataType === 'json' || typeof options.dataType === 'undefined') {
|
|
98
|
+
return response.json();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (options.responseType === 'text' || options.dataType === 'text') {
|
|
102
|
+
return response.text();
|
|
103
|
+
}
|
|
104
|
+
return Promise.resolve(null);
|
|
105
|
+
})
|
|
106
|
+
.then(data => {
|
|
107
|
+
res.data = data;
|
|
108
|
+
typeof success === 'function' && success(res);
|
|
109
|
+
typeof complete === 'function' && complete(res);
|
|
110
|
+
return res;
|
|
111
|
+
})
|
|
112
|
+
.catch(err => {
|
|
113
|
+
typeof fail === 'function' && fail(err);
|
|
114
|
+
typeof complete === 'function' && complete(res);
|
|
115
|
+
return Promise.reject(err);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function taroInterceptor(chain) {
|
|
119
|
+
return _request(chain.requestParams);
|
|
120
|
+
}
|
|
121
|
+
const link = new Link(taroInterceptor);
|
|
122
|
+
export const request = link.request.bind(link);
|
|
123
|
+
export const addInterceptor = link.addInterceptor.bind(link);
|