@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.
@@ -50,9 +50,9 @@ function connectSocket(options) {
50
50
  // protocols must be array
51
51
  const _protocols = Array.isArray(protocols) ? protocols : null;
52
52
  // 2 connection at most
53
- if (socketTasks.length > 1) {
53
+ if (socketTasks.length >= 5) {
54
54
  return handle.fail({
55
- errMsg: '同时最多发起 2 个 socket 请求,更多请参考文档。'
55
+ errMsg: '同时最多发起 5 个 socket 请求,更多请参考文档。'
56
56
  }, { resolve, reject });
57
57
  }
58
58
  const task = new SocketTask(url, _protocols);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/api/network/websocket/index.ts"],"sourcesContent":["import { getParameterError, shouldBeObject } from '../../../utils'\nimport { MethodHandler } from '../../../utils/handler'\nimport { SocketTask } from './socketTask'\n\nlet socketTasks: SocketTask[] = []\nlet socketsCounter = 1\n\nexport function sendSocketMessage () {\n console.warn('Deprecated.Please use socketTask.send instead.')\n}\n\nexport function onSocketOpen () {\n console.warn('Deprecated.Please use socketTask.onOpen instead.')\n}\n\nexport function onSocketMessage () {\n console.warn('Deprecated.Please use socketTask.onMessage instead.')\n}\n\nexport function onSocketError () {\n console.warn('Deprecated.Please use socketTask.onError instead.')\n}\n\nexport function onSocketClose () {\n console.warn('Deprecated.Please use socketTask.onClose instead.')\n}\n\nexport function connectSocket (options?: Taro.connectSocket.Option) {\n const name = 'connectSocket'\n\n return new Promise((resolve, reject) => {\n // options must be an Object\n const isObject = shouldBeObject(options)\n if (!isObject.flag) {\n const res = { errMsg: `${name}:fail ${isObject.msg}` }\n console.error(res.errMsg)\n return reject(res)\n }\n const { url, protocols, success, fail, complete } = options as Exclude<typeof options, undefined>\n const handle = new MethodHandler<{\n socketTaskId?: number\n }>({ name, success, fail, complete })\n\n // options.url must be String\n if (typeof url !== 'string') {\n return handle.fail({\n errMsg: getParameterError({\n para: 'url',\n correct: 'String',\n wrong: url\n })\n }, { resolve, reject })\n }\n\n // options.url must be invalid\n if (!url.startsWith('ws://') && !url.startsWith('wss://')) {\n return handle.fail({\n errMsg: `request:fail invalid url \"${url}\"`\n }, { resolve, reject })\n }\n\n // protocols must be array\n const _protocols = Array.isArray(protocols) ? protocols : null\n\n // 2 connection at most\n if (socketTasks.length > 1) {\n return handle.fail({\n errMsg: '同时最多发起 2 个 socket 请求,更多请参考文档。'\n }, { resolve, reject })\n }\n\n const task = new SocketTask(url, _protocols)\n task._destroyWhenClose = function () {\n socketTasks = socketTasks.filter(socketTask => socketTask !== this)\n }\n socketTasks.push(task)\n\n handle.success({\n socketTaskId: socketsCounter++\n })\n\n return resolve(task)\n })\n}\n\nexport function closeSocket () {\n console.warn('Deprecated.Please use socketTask.close instead.')\n}\n"],"names":[],"mappings":";;;;AAIA,IAAI,WAAW,GAAiB,EAAE,CAAA;AAClC,IAAI,cAAc,GAAG,CAAC,CAAA;SAEN,iBAAiB,GAAA;AAC/B,IAAA,OAAO,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAA;AAChE,CAAC;SAEe,YAAY,GAAA;AAC1B,IAAA,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAA;AAClE,CAAC;SAEe,eAAe,GAAA;AAC7B,IAAA,OAAO,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAA;AACrE,CAAC;SAEe,aAAa,GAAA;AAC3B,IAAA,OAAO,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAA;AACnE,CAAC;SAEe,aAAa,GAAA;AAC3B,IAAA,OAAO,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAA;AACnE,CAAC;AAEK,SAAU,aAAa,CAAE,OAAmC,EAAA;IAChE,MAAM,IAAI,GAAG,eAAe,CAAA;IAE5B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;;AAErC,QAAA,MAAM,QAAQ,GAAG,cAA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AAA;;AAG9D,QAAA,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,OAAO,MAAM,CAAC,IAAI,CAAC;AACjB,gBAAA,MAAM,EAAE,+BAA+B;AACxC,aAAA,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;AACxB,SAAA;QAED,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;QAC5C,IAAI,CAAC,iBAAiB,GAAG,YAAA;AACvB,YAAA,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC,UAAU,IAAI,UAAU,KAAK,IAAI,CAAC,CAAA;AACrE,SAAC,CAAA;AACD,QAAA,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEtB,MAAM,CAAC,OAAO,CAAC;YACb,YAAY,EAAE,cAAc,EAAE;AAC/B,SAAA,CAAC,CAAA;AAEF,QAAA,OAAO,OAAO,CAAC,IAAI,CAAC,CAAA;AACtB,KAAC,CAAC,CAAA;AACJ,CAAC;SAEe,WAAW,GAAA;AACzB,IAAA,OAAO,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAA;AACjE;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/api/network/websocket/index.ts"],"sourcesContent":["import { getParameterError, shouldBeObject } from '../../../utils'\nimport { MethodHandler } from '../../../utils/handler'\nimport { SocketTask } from './socketTask'\n\nlet socketTasks: SocketTask[] = []\nlet socketsCounter = 1\n\nexport function sendSocketMessage () {\n console.warn('Deprecated.Please use socketTask.send instead.')\n}\n\nexport function onSocketOpen () {\n console.warn('Deprecated.Please use socketTask.onOpen instead.')\n}\n\nexport function onSocketMessage () {\n console.warn('Deprecated.Please use socketTask.onMessage instead.')\n}\n\nexport function onSocketError () {\n console.warn('Deprecated.Please use socketTask.onError instead.')\n}\n\nexport function onSocketClose () {\n console.warn('Deprecated.Please use socketTask.onClose instead.')\n}\n\nexport function connectSocket (options?: Taro.connectSocket.Option) {\n const name = 'connectSocket'\n\n return new Promise((resolve, reject) => {\n // options must be an Object\n const isObject = shouldBeObject(options)\n if (!isObject.flag) {\n const res = { errMsg: `${name}:fail ${isObject.msg}` }\n console.error(res.errMsg)\n return reject(res)\n }\n const { url, protocols, success, fail, complete } = options as Exclude<typeof options, undefined>\n const handle = new MethodHandler<{\n socketTaskId?: number\n }>({ name, success, fail, complete })\n\n // options.url must be String\n if (typeof url !== 'string') {\n return handle.fail({\n errMsg: getParameterError({\n para: 'url',\n correct: 'String',\n wrong: url\n })\n }, { resolve, reject })\n }\n\n // options.url must be invalid\n if (!url.startsWith('ws://') && !url.startsWith('wss://')) {\n return handle.fail({\n errMsg: `request:fail invalid url \"${url}\"`\n }, { resolve, reject })\n }\n\n // protocols must be array\n const _protocols = Array.isArray(protocols) ? protocols : null\n\n // 2 connection at most\n if (socketTasks.length >= 5) {\n return handle.fail({\n errMsg: '同时最多发起 5 个 socket 请求,更多请参考文档。'\n }, { resolve, reject })\n }\n\n const task = new SocketTask(url, _protocols)\n task._destroyWhenClose = function () {\n socketTasks = socketTasks.filter(socketTask => socketTask !== this)\n }\n socketTasks.push(task)\n\n handle.success({\n socketTaskId: socketsCounter++\n })\n\n return resolve(task)\n })\n}\n\nexport function closeSocket () {\n console.warn('Deprecated.Please use socketTask.close instead.')\n}\n"],"names":[],"mappings":";;;;AAIA,IAAI,WAAW,GAAiB,EAAE,CAAA;AAClC,IAAI,cAAc,GAAG,CAAC,CAAA;SAEN,iBAAiB,GAAA;AAC/B,IAAA,OAAO,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAA;AAChE,CAAC;SAEe,YAAY,GAAA;AAC1B,IAAA,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAA;AAClE,CAAC;SAEe,eAAe,GAAA;AAC7B,IAAA,OAAO,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAA;AACrE,CAAC;SAEe,aAAa,GAAA;AAC3B,IAAA,OAAO,CAAC,IAAI,CAAC,mDA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C,QAAQ,CAAC,EAAE;YACzD,OAAO,MAAM,CAAC,IAAI,CAAC;gBACjB,MAAM,EAAE,CAA6B,0BAAA,EAAA,GAAG,CAAG,CAAA,CAAA;AAC5C,aAAA,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;AACxB,SAAA;;AAGD,QAAA,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,IAAI,CAAA;;AAG9D,QAAA,IAAI,WAAW,CAAC,MAAM,IAAI,CAAC,EAAE;YAC3B,OAAO,MAAM,CAAC,IAAI,CAAC;AACjB,gBAAA,MAAM,EAAE,+BAA+B;AACxC,aAAA,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;AACxB,SAAA;QAED,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;QAC5C,IAAI,CAAC,iBAAiB,GAAG,YAAA;AACvB,YAAA,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC,UAAU,IAAI,UAAU,KAAK,IAAI,CAAC,CAAA;AACrE,SAAC,CAAA;AACD,QAAA,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEtB,MAAM,CAAC,OAAO,CAAC;YACb,YAAY,EAAE,cAAc,EAAE;AAC/B,SAAA,CAAC,CAAA;AAEF,QAAA,OAAO,OAAO,CAAC,IAAI,CAAC,CAAA;AACtB,KAAC,CAAC,CAAA;AACJ,CAAC;SAEe,WAAW,GAAA;AACzB,IAAA,OAAO,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAA;AACjE;;;;"}
package/dist/index.cjs.js CHANGED
@@ -2418,7 +2418,6 @@ class InnerAudioContext {
2418
2418
  this.destroy = () => {
2419
2419
  this.stop();
2420
2420
  if (this.Instance) {
2421
- document.body.removeChild(this.Instance);
2422
2421
  this.Instance = undefined;
2423
2422
  }
2424
2423
  };
@@ -2445,6 +2444,7 @@ class InnerAudioContext {
2445
2444
  this.Instance = new Audio();
2446
2445
  this.errorStack = new CallbackManager();
2447
2446
  this.stopStack = new CallbackManager();
2447
+ this.Instance.onerror = this.errorStack.trigger;
2448
2448
  Taro.eventCenter.on('__taroRouterChange', () => { this.stop(); });
2449
2449
  this.onPlay(() => {
2450
2450
  if (this.__isFirstPlay) {
@@ -2537,6 +2537,7 @@ class BackgroundAudioManager {
2537
2537
  this.Instance = new Audio();
2538
2538
  this.errorStack = new CallbackManager();
2539
2539
  this.stopStack = new CallbackManager();
2540
+ this.Instance.onerror = this.errorStack.trigger;
2540
2541
  this.Instance.autoplay = true;
2541
2542
  this.onPlay(() => {
2542
2543
  if (this.currentTime !== this.startTime) {
@@ -2707,12 +2708,16 @@ const previewImage = (options) => __awaiter(void 0, void 0, void 0, function* ()
2707
2708
  const { urls = [], current = '', success, fail, complete } = options;
2708
2709
  const handle = new MethodHandler({ name: 'previewImage', success, fail, complete });
2709
2710
  const container = document.createElement('div');
2711
+ const removeHandler = () => {
2712
+ runtime.eventCenter.off('__taroRouterChange', removeHandler);
2713
+ container.remove();
2714
+ };
2715
+ // 路由改变后应该关闭预览框
2716
+ runtime.eventCenter.on('__taroRouterChange', removeHandler);
2710
2717
  container.classList.add('preview-image');
2711
2718
  container.style.cssText =
2712
2719
  'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;';
2713
- container.addEventListener('click', () => {
2714
- container.remove();
2715
- });
2720
+ container.addEventListener('click', removeHandler);
2716
2721
  const swiper = document.createElement('taro-swiper-core');
2717
2722
  // @ts-ignore
2718
2723
  swiper.full = true;
@@ -4989,15 +4994,17 @@ const downloadFile = ({ url, header, withCredentials, timeout, success, fail, co
4989
4994
  }
4990
4995
  });
4991
4996
  });
4992
- result.headersReceive = task.onHeadersReceived;
4993
- result.progress = task.onProgressUpdate;
4994
- return new Proxy(result, {
4995
- get(target, prop) {
4996
- const object = prop in task ? task : target;
4997
- const value = object[prop];
4998
- return typeof value === 'function' ? value.bind(object) : value;
4999
- },
4997
+ result.headersReceive = task.onHeadersReceived.bind(task);
4998
+ result.progress = task.onProgressUpdate.bind(task);
4999
+ const properties = {};
5000
+ Object.keys(task).forEach(key => {
5001
+ properties[key] = {
5002
+ get() {
5003
+ return typeof task[key] === 'function' ? task[key].bind(task) : task[key];
5004
+ }
5005
+ };
5000
5006
  });
5007
+ return Object.defineProperties(result, properties);
5001
5008
  };
5002
5009
 
5003
5010
  // mDNS
@@ -5024,19 +5031,21 @@ function generateRequestUrlWithParams(url = '', params) {
5024
5031
  }
5025
5032
  function _request(options = {}) {
5026
5033
  const { success, complete, fail } = options;
5027
- let url = options.url || '';
5028
5034
  const params = {};
5029
5035
  const res = {};
5030
- if (options.jsonp) {
5031
- const { jsonp } = options, opts = __rest(options, ["jsonp"]);
5032
- Object.assign(params, opts);
5036
+ 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"]);
5037
+ Object.assign(params, opts);
5038
+ if (jsonp) {
5033
5039
  // @ts-ignore
5034
- params.params = opts.data;
5040
+ params.params = data;
5035
5041
  params.cache = opts.jsonpCache;
5042
+ // @ts-ignore
5043
+ params.timeout = timeout;
5036
5044
  if (typeof jsonp === 'string') {
5037
5045
  // @ts-ignore
5038
5046
  params.name = jsonp;
5039
5047
  }
5048
+ // Note: https://github.com/luckyadam/jsonp-retry
5040
5049
  return jsonpRetry(url, params)
5041
5050
  .then(data => {
5042
5051
  res.statusCode = 200;
@@ -5051,50 +5060,49 @@ function _request(options = {}) {
5051
5060
  return Promise.reject(err);
5052
5061
  });
5053
5062
  }
5054
- params.method = options.method || 'GET';
5063
+ params.method = method;
5055
5064
  const methodUpper = params.method.toUpperCase();
5056
- params.cache = options.cache || 'default';
5065
+ params.cache = cache;
5057
5066
  if (methodUpper === 'GET' || methodUpper === 'HEAD') {
5058
- url = generateRequestUrlWithParams(url, options.data);
5067
+ url = generateRequestUrlWithParams(url, data);
5059
5068
  }
5060
- else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(options.data)) >= 0) {
5061
- options.header = options.header || {};
5062
- const keyOfContentType = Object.keys(options.header).find(item => item.toLowerCase() === 'content-type');
5069
+ else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(data)) >= 0) {
5070
+ const keyOfContentType = Object.keys(header).find(item => item.toLowerCase() === 'content-type');
5063
5071
  if (!keyOfContentType) {
5064
- options.header['Content-Type'] = 'application/json';
5072
+ header['Content-Type'] = 'application/json';
5065
5073
  }
5066
- const contentType = options.header[keyOfContentType || 'Content-Type'];
5074
+ const contentType = header[keyOfContentType || 'Content-Type'];
5067
5075
  if (contentType.indexOf('application/json') >= 0) {
5068
- params.body = JSON.stringify(options.data);
5076
+ params.body = JSON.stringify(data);
5069
5077
  }
5070
5078
  else if (contentType.indexOf('application/x-www-form-urlencoded') >= 0) {
5071
- params.body = serializeParams(options.data);
5079
+ params.body = serializeParams(data);
5072
5080
  }
5073
5081
  else {
5074
- params.body = options.data;
5082
+ params.body = data;
5075
5083
  }
5076
5084
  }
5077
5085
  else {
5078
- params.body = options.data;
5086
+ params.body = data;
5079
5087
  }
5080
- if (options.header) {
5081
- params.headers = options.header;
5088
+ if (header) {
5089
+ params.headers = header;
5082
5090
  }
5083
- if (options.mode) {
5084
- params.mode = options.mode;
5091
+ if (mode) {
5092
+ params.mode = mode;
5085
5093
  }
5086
5094
  let timeoutTimer = null;
5087
- if (options.signal) {
5088
- params.signal = options.signal;
5095
+ if (signal) {
5096
+ params.signal = signal;
5089
5097
  }
5090
- else if (typeof options.timeout === 'number') {
5098
+ else if (typeof timeout === 'number') {
5091
5099
  const controller = new window.AbortController();
5092
5100
  params.signal = controller.signal;
5093
5101
  timeoutTimer = setTimeout(function () {
5094
5102
  controller.abort();
5095
- }, options.timeout);
5103
+ }, timeout);
5096
5104
  }
5097
- params.credentials = options.credentials;
5105
+ params.credentials = credentials;
5098
5106
  return fetch(url, params)
5099
5107
  .then(response => {
5100
5108
  if (timeoutTimer) {
@@ -5110,17 +5118,17 @@ function _request(options = {}) {
5110
5118
  for (const key of response.headers.keys()) {
5111
5119
  res.header[key] = response.headers.get(key);
5112
5120
  }
5113
- if (options.responseType === 'arraybuffer') {
5121
+ if (responseType === 'arraybuffer') {
5114
5122
  return response.arrayBuffer();
5115
5123
  }
5116
5124
  if (res.statusCode !== 204) {
5117
- if (options.dataType === 'json' || typeof options.dataType === 'undefined') {
5125
+ if (dataType === 'json' || typeof dataType === 'undefined') {
5118
5126
  return response.json().catch(() => {
5119
5127
  return null;
5120
5128
  });
5121
5129
  }
5122
5130
  }
5123
- if (options.responseType === 'text' || options.dataType === 'text') {
5131
+ if (responseType === 'text' || dataType === 'text') {
5124
5132
  return response.text();
5125
5133
  }
5126
5134
  return Promise.resolve(null);
@@ -5307,15 +5315,17 @@ const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName,
5307
5315
  }
5308
5316
  });
5309
5317
  });
5310
- result.headersReceive = task.onHeadersReceived;
5311
- result.progress = task.onProgressUpdate;
5312
- return new Proxy(result, {
5313
- get(target, prop) {
5314
- const object = prop in task ? task : target;
5315
- const value = object[prop];
5316
- return typeof value === 'function' ? value.bind(object) : value;
5317
- },
5318
+ result.headersReceive = task.onHeadersReceived.bind(task);
5319
+ result.progress = task.onProgressUpdate.bind(task);
5320
+ const properties = {};
5321
+ Object.keys(task).forEach(key => {
5322
+ properties[key] = {
5323
+ get() {
5324
+ return typeof task[key] === 'function' ? task[key].bind(task) : task[key];
5325
+ }
5326
+ };
5318
5327
  });
5328
+ return Object.defineProperties(result, properties);
5319
5329
  };
5320
5330
 
5321
5331
  class SocketTask {
@@ -5430,9 +5440,9 @@ function connectSocket(options) {
5430
5440
  // protocols must be array
5431
5441
  const _protocols = Array.isArray(protocols) ? protocols : null;
5432
5442
  // 2 connection at most
5433
- if (socketTasks.length > 1) {
5443
+ if (socketTasks.length >= 5) {
5434
5444
  return handle.fail({
5435
- errMsg: '同时最多发起 2 个 socket 请求,更多请参考文档。'
5445
+ errMsg: '同时最多发起 5 个 socket 请求,更多请参考文档。'
5436
5446
  }, { resolve, reject });
5437
5447
  }
5438
5448
  const task = new SocketTask(url, _protocols);