@tarojs/taro-h5 3.7.0-alpha.7 → 3.7.0-beta.1
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/media/audio/InnerAudioContext.d.ts +20 -20
- package/dist/api/media/audio/InnerAudioContext.js +1 -1
- package/dist/api/media/audio/InnerAudioContext.js.map +1 -1
- package/dist/api/media/background-audio/BackgroundAudioManager.js +1 -0
- package/dist/api/media/background-audio/BackgroundAudioManager.js.map +1 -1
- package/dist/api/media/image/previewImage.js +8 -3
- package/dist/api/media/image/previewImage.js.map +1 -1
- package/dist/api/network/download.js +10 -8
- package/dist/api/network/download.js.map +1 -1
- package/dist/api/network/request/index.js +30 -29
- package/dist/api/network/request/index.js.map +1 -1
- package/dist/api/network/upload.js +10 -8
- package/dist/api/network/upload.js.map +1 -1
- package/dist/api/network/websocket/index.js +2 -2
- package/dist/api/network/websocket/index.js.map +1 -1
- package/dist/index.cjs.js +61 -51
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +62 -52
- package/dist/index.esm.js.map +1 -1
- package/package.json +6 -6
package/dist/index.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ import { history, navigateBack, navigateTo, reLaunch, redirectTo, getCurrentPage
|
|
|
3
3
|
export { getCurrentPages, history, navigateBack, navigateTo, reLaunch, redirectTo, switchTab } from '@tarojs/router';
|
|
4
4
|
import { isFunction, toKebabCase, PLATFORM_TYPE } from '@tarojs/shared';
|
|
5
5
|
import { getCurrentPage, getHomePage } from '@tarojs/router/dist/utils';
|
|
6
|
-
import { hooks, Current as Current$1 } from '@tarojs/runtime';
|
|
6
|
+
import { hooks, Current as Current$1, eventCenter as eventCenter$1 } from '@tarojs/runtime';
|
|
7
7
|
import { fromByteArray, toByteArray } from 'base64-js';
|
|
8
8
|
import { getMobileDetect, setTitle } from '@tarojs/router/dist/utils/navigate';
|
|
9
9
|
import isNil from 'lodash-es/isNil';
|
|
@@ -2396,7 +2396,6 @@ class InnerAudioContext {
|
|
|
2396
2396
|
this.destroy = () => {
|
|
2397
2397
|
this.stop();
|
|
2398
2398
|
if (this.Instance) {
|
|
2399
|
-
document.body.removeChild(this.Instance);
|
|
2400
2399
|
this.Instance = undefined;
|
|
2401
2400
|
}
|
|
2402
2401
|
};
|
|
@@ -2423,6 +2422,7 @@ class InnerAudioContext {
|
|
|
2423
2422
|
this.Instance = new Audio();
|
|
2424
2423
|
this.errorStack = new CallbackManager();
|
|
2425
2424
|
this.stopStack = new CallbackManager();
|
|
2425
|
+
this.Instance.onerror = this.errorStack.trigger;
|
|
2426
2426
|
Taro.eventCenter.on('__taroRouterChange', () => { this.stop(); });
|
|
2427
2427
|
this.onPlay(() => {
|
|
2428
2428
|
if (this.__isFirstPlay) {
|
|
@@ -2515,6 +2515,7 @@ class BackgroundAudioManager {
|
|
|
2515
2515
|
this.Instance = new Audio();
|
|
2516
2516
|
this.errorStack = new CallbackManager();
|
|
2517
2517
|
this.stopStack = new CallbackManager();
|
|
2518
|
+
this.Instance.onerror = this.errorStack.trigger;
|
|
2518
2519
|
this.Instance.autoplay = true;
|
|
2519
2520
|
this.onPlay(() => {
|
|
2520
2521
|
if (this.currentTime !== this.startTime) {
|
|
@@ -2685,12 +2686,16 @@ const previewImage = (options) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
2685
2686
|
const { urls = [], current = '', success, fail, complete } = options;
|
|
2686
2687
|
const handle = new MethodHandler({ name: 'previewImage', success, fail, complete });
|
|
2687
2688
|
const container = document.createElement('div');
|
|
2689
|
+
const removeHandler = () => {
|
|
2690
|
+
eventCenter$1.off('__taroRouterChange', removeHandler);
|
|
2691
|
+
container.remove();
|
|
2692
|
+
};
|
|
2693
|
+
// 路由改变后应该关闭预览框
|
|
2694
|
+
eventCenter$1.on('__taroRouterChange', removeHandler);
|
|
2688
2695
|
container.classList.add('preview-image');
|
|
2689
2696
|
container.style.cssText =
|
|
2690
2697
|
'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;';
|
|
2691
|
-
container.addEventListener('click',
|
|
2692
|
-
container.remove();
|
|
2693
|
-
});
|
|
2698
|
+
container.addEventListener('click', removeHandler);
|
|
2694
2699
|
const swiper = document.createElement('taro-swiper-core');
|
|
2695
2700
|
// @ts-ignore
|
|
2696
2701
|
swiper.full = true;
|
|
@@ -4967,15 +4972,17 @@ const downloadFile = ({ url, header, withCredentials, timeout, success, fail, co
|
|
|
4967
4972
|
}
|
|
4968
4973
|
});
|
|
4969
4974
|
});
|
|
4970
|
-
result.headersReceive = task.onHeadersReceived;
|
|
4971
|
-
result.progress = task.onProgressUpdate;
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4975
|
+
result.headersReceive = task.onHeadersReceived.bind(task);
|
|
4976
|
+
result.progress = task.onProgressUpdate.bind(task);
|
|
4977
|
+
const properties = {};
|
|
4978
|
+
Object.keys(task).forEach(key => {
|
|
4979
|
+
properties[key] = {
|
|
4980
|
+
get() {
|
|
4981
|
+
return typeof task[key] === 'function' ? task[key].bind(task) : task[key];
|
|
4982
|
+
}
|
|
4983
|
+
};
|
|
4978
4984
|
});
|
|
4985
|
+
return Object.defineProperties(result, properties);
|
|
4979
4986
|
};
|
|
4980
4987
|
|
|
4981
4988
|
// mDNS
|
|
@@ -5002,19 +5009,21 @@ function generateRequestUrlWithParams(url = '', params) {
|
|
|
5002
5009
|
}
|
|
5003
5010
|
function _request(options = {}) {
|
|
5004
5011
|
const { success, complete, fail } = options;
|
|
5005
|
-
let url = options.url || '';
|
|
5006
5012
|
const params = {};
|
|
5007
5013
|
const res = {};
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5014
|
+
let { cache = 'default', credentials, data, dataType, header = {}, jsonp, method = 'GET', mode, responseType, signal, timeout = 2000, url = '' } = options, opts = __rest(options, ["cache", "credentials", "data", "dataType", "header", "jsonp", "method", "mode", "responseType", "signal", "timeout", "url"]);
|
|
5015
|
+
Object.assign(params, opts);
|
|
5016
|
+
if (jsonp) {
|
|
5011
5017
|
// @ts-ignore
|
|
5012
|
-
params.params =
|
|
5018
|
+
params.params = data;
|
|
5013
5019
|
params.cache = opts.jsonpCache;
|
|
5020
|
+
// @ts-ignore
|
|
5021
|
+
params.timeout = timeout;
|
|
5014
5022
|
if (typeof jsonp === 'string') {
|
|
5015
5023
|
// @ts-ignore
|
|
5016
5024
|
params.name = jsonp;
|
|
5017
5025
|
}
|
|
5026
|
+
// Note: https://github.com/luckyadam/jsonp-retry
|
|
5018
5027
|
return jsonpRetry(url, params)
|
|
5019
5028
|
.then(data => {
|
|
5020
5029
|
res.statusCode = 200;
|
|
@@ -5029,50 +5038,49 @@ function _request(options = {}) {
|
|
|
5029
5038
|
return Promise.reject(err);
|
|
5030
5039
|
});
|
|
5031
5040
|
}
|
|
5032
|
-
params.method =
|
|
5041
|
+
params.method = method;
|
|
5033
5042
|
const methodUpper = params.method.toUpperCase();
|
|
5034
|
-
params.cache =
|
|
5043
|
+
params.cache = cache;
|
|
5035
5044
|
if (methodUpper === 'GET' || methodUpper === 'HEAD') {
|
|
5036
|
-
url = generateRequestUrlWithParams(url,
|
|
5045
|
+
url = generateRequestUrlWithParams(url, data);
|
|
5037
5046
|
}
|
|
5038
|
-
else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(
|
|
5039
|
-
|
|
5040
|
-
const keyOfContentType = Object.keys(options.header).find(item => item.toLowerCase() === 'content-type');
|
|
5047
|
+
else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(data)) >= 0) {
|
|
5048
|
+
const keyOfContentType = Object.keys(header).find(item => item.toLowerCase() === 'content-type');
|
|
5041
5049
|
if (!keyOfContentType) {
|
|
5042
|
-
|
|
5050
|
+
header['Content-Type'] = 'application/json';
|
|
5043
5051
|
}
|
|
5044
|
-
const contentType =
|
|
5052
|
+
const contentType = header[keyOfContentType || 'Content-Type'];
|
|
5045
5053
|
if (contentType.indexOf('application/json') >= 0) {
|
|
5046
|
-
params.body = JSON.stringify(
|
|
5054
|
+
params.body = JSON.stringify(data);
|
|
5047
5055
|
}
|
|
5048
5056
|
else if (contentType.indexOf('application/x-www-form-urlencoded') >= 0) {
|
|
5049
|
-
params.body = serializeParams(
|
|
5057
|
+
params.body = serializeParams(data);
|
|
5050
5058
|
}
|
|
5051
5059
|
else {
|
|
5052
|
-
params.body =
|
|
5060
|
+
params.body = data;
|
|
5053
5061
|
}
|
|
5054
5062
|
}
|
|
5055
5063
|
else {
|
|
5056
|
-
params.body =
|
|
5064
|
+
params.body = data;
|
|
5057
5065
|
}
|
|
5058
|
-
if (
|
|
5059
|
-
params.headers =
|
|
5066
|
+
if (header) {
|
|
5067
|
+
params.headers = header;
|
|
5060
5068
|
}
|
|
5061
|
-
if (
|
|
5062
|
-
params.mode =
|
|
5069
|
+
if (mode) {
|
|
5070
|
+
params.mode = mode;
|
|
5063
5071
|
}
|
|
5064
5072
|
let timeoutTimer = null;
|
|
5065
|
-
if (
|
|
5066
|
-
params.signal =
|
|
5073
|
+
if (signal) {
|
|
5074
|
+
params.signal = signal;
|
|
5067
5075
|
}
|
|
5068
|
-
else if (typeof
|
|
5076
|
+
else if (typeof timeout === 'number') {
|
|
5069
5077
|
const controller = new window.AbortController();
|
|
5070
5078
|
params.signal = controller.signal;
|
|
5071
5079
|
timeoutTimer = setTimeout(function () {
|
|
5072
5080
|
controller.abort();
|
|
5073
|
-
},
|
|
5081
|
+
}, timeout);
|
|
5074
5082
|
}
|
|
5075
|
-
params.credentials =
|
|
5083
|
+
params.credentials = credentials;
|
|
5076
5084
|
return fetch(url, params)
|
|
5077
5085
|
.then(response => {
|
|
5078
5086
|
if (timeoutTimer) {
|
|
@@ -5088,17 +5096,17 @@ function _request(options = {}) {
|
|
|
5088
5096
|
for (const key of response.headers.keys()) {
|
|
5089
5097
|
res.header[key] = response.headers.get(key);
|
|
5090
5098
|
}
|
|
5091
|
-
if (
|
|
5099
|
+
if (responseType === 'arraybuffer') {
|
|
5092
5100
|
return response.arrayBuffer();
|
|
5093
5101
|
}
|
|
5094
5102
|
if (res.statusCode !== 204) {
|
|
5095
|
-
if (
|
|
5103
|
+
if (dataType === 'json' || typeof dataType === 'undefined') {
|
|
5096
5104
|
return response.json().catch(() => {
|
|
5097
5105
|
return null;
|
|
5098
5106
|
});
|
|
5099
5107
|
}
|
|
5100
5108
|
}
|
|
5101
|
-
if (
|
|
5109
|
+
if (responseType === 'text' || dataType === 'text') {
|
|
5102
5110
|
return response.text();
|
|
5103
5111
|
}
|
|
5104
5112
|
return Promise.resolve(null);
|
|
@@ -5285,15 +5293,17 @@ const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName,
|
|
|
5285
5293
|
}
|
|
5286
5294
|
});
|
|
5287
5295
|
});
|
|
5288
|
-
result.headersReceive = task.onHeadersReceived;
|
|
5289
|
-
result.progress = task.onProgressUpdate;
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
+
result.headersReceive = task.onHeadersReceived.bind(task);
|
|
5297
|
+
result.progress = task.onProgressUpdate.bind(task);
|
|
5298
|
+
const properties = {};
|
|
5299
|
+
Object.keys(task).forEach(key => {
|
|
5300
|
+
properties[key] = {
|
|
5301
|
+
get() {
|
|
5302
|
+
return typeof task[key] === 'function' ? task[key].bind(task) : task[key];
|
|
5303
|
+
}
|
|
5304
|
+
};
|
|
5296
5305
|
});
|
|
5306
|
+
return Object.defineProperties(result, properties);
|
|
5297
5307
|
};
|
|
5298
5308
|
|
|
5299
5309
|
class SocketTask {
|
|
@@ -5408,9 +5418,9 @@ function connectSocket(options) {
|
|
|
5408
5418
|
// protocols must be array
|
|
5409
5419
|
const _protocols = Array.isArray(protocols) ? protocols : null;
|
|
5410
5420
|
// 2 connection at most
|
|
5411
|
-
if (socketTasks.length
|
|
5421
|
+
if (socketTasks.length >= 5) {
|
|
5412
5422
|
return handle.fail({
|
|
5413
|
-
errMsg: '同时最多发起
|
|
5423
|
+
errMsg: '同时最多发起 5 个 socket 请求,更多请参考文档。'
|
|
5414
5424
|
}, { resolve, reject });
|
|
5415
5425
|
}
|
|
5416
5426
|
const task = new SocketTask(url, _protocols);
|