@galacean/effects-plugin-alipay-downgrade 2.0.0-alpha.9 → 2.0.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/index.js CHANGED
@@ -3,44 +3,34 @@
3
3
  * Description: Galacean Effects player downgrade plugin for Alipay
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,意绮,飂兮
6
- * Version: v2.0.0-alpha.9
6
+ * Version: v2.0.0-beta.1
7
7
  */
8
8
 
9
9
  'use strict';
10
10
 
11
11
  Object.defineProperty(exports, '__esModule', { value: true });
12
12
 
13
- var effects = require('@galacean/effects');
13
+ var EFFECTS = require('@galacean/effects');
14
14
 
15
- function _set_prototype_of(o, p) {
16
- _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
17
- o.__proto__ = p;
18
- return o;
19
- };
20
- return _set_prototype_of(o, p);
21
- }
22
-
23
- function _inherits(subClass, superClass) {
24
- if (typeof superClass !== "function" && superClass !== null) {
25
- throw new TypeError("Super expression must either be null or a function");
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ Object.keys(e).forEach(function (k) {
20
+ if (k !== 'default') {
21
+ var d = Object.getOwnPropertyDescriptor(e, k);
22
+ Object.defineProperty(n, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: function () { return e[k]; }
25
+ });
26
+ }
27
+ });
26
28
  }
27
- subClass.prototype = Object.create(superClass && superClass.prototype, {
28
- constructor: {
29
- value: subClass,
30
- writable: true,
31
- configurable: true
32
- }
33
- });
34
- if (superClass) _set_prototype_of(subClass, superClass);
29
+ n["default"] = e;
30
+ return Object.freeze(n);
35
31
  }
36
32
 
37
- var DowngradeVFXItem = /*#__PURE__*/ function(VFXItem) {
38
- _inherits(DowngradeVFXItem, VFXItem);
39
- function DowngradeVFXItem() {
40
- return VFXItem.apply(this, arguments);
41
- }
42
- return DowngradeVFXItem;
43
- }(effects.VFXItem);
33
+ var EFFECTS__namespace = /*#__PURE__*/_interopNamespace(EFFECTS);
44
34
 
45
35
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
46
36
  try {
@@ -69,6 +59,28 @@ function _async_to_generator(fn) {
69
59
  };
70
60
  }
71
61
 
62
+ function _set_prototype_of(o, p) {
63
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
64
+ o.__proto__ = p;
65
+ return o;
66
+ };
67
+ return _set_prototype_of(o, p);
68
+ }
69
+
70
+ function _inherits(subClass, superClass) {
71
+ if (typeof superClass !== "function" && superClass !== null) {
72
+ throw new TypeError("Super expression must either be null or a function");
73
+ }
74
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
75
+ constructor: {
76
+ value: subClass,
77
+ writable: true,
78
+ configurable: true
79
+ }
80
+ });
81
+ if (superClass) _set_prototype_of(subClass, superClass);
82
+ }
83
+
72
84
  function __generator(thisArg, body) {
73
85
  var _ = {
74
86
  label: 0,
@@ -169,122 +181,312 @@ typeof SuppressedError === "function" ? SuppressedError : function _SuppressedEr
169
181
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
170
182
  };
171
183
 
184
+ function _extends() {
185
+ _extends = Object.assign || function assign(target) {
186
+ for(var i = 1; i < arguments.length; i++){
187
+ var source = arguments[i];
188
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
189
+ }
190
+ return target;
191
+ };
192
+ return _extends.apply(this, arguments);
193
+ }
194
+
195
+ exports.DeviceLevel = void 0;
196
+ (function(DeviceLevel) {
197
+ DeviceLevel["High"] = "high";
198
+ DeviceLevel["Medium"] = "medium";
199
+ DeviceLevel["Low"] = "low";
200
+ DeviceLevel["Unknown"] = "unknown";
201
+ })(exports.DeviceLevel || (exports.DeviceLevel = {}));
202
+
203
+ var deviceModelList = [
204
+ "12,8",
205
+ "13,1",
206
+ "13,2",
207
+ "13,3",
208
+ "13,4"
209
+ ];
210
+ /**
211
+ * 设备代理类
212
+ *
213
+ * 负责将 JSAPI 返回的 SystemInfo 和 DowngradeResult 数据
214
+ * 转成设备相关的数据,在后面的降级判断中使用
215
+ */ var DeviceProxy = /*#__PURE__*/ function() {
216
+ function DeviceProxy() {
217
+ /**
218
+ * 是否 iOS 系统
219
+ */ this.isIOS = false;
220
+ /**
221
+ * 硬件机型
222
+ */ this.model = "DESKTOP_DEBUG";
223
+ /**
224
+ * 系统版本
225
+ */ this.system = "Unknown";
226
+ /**
227
+ * 设备等级
228
+ */ this.level = exports.DeviceLevel.Unknown;
229
+ /**
230
+ * 是否降级
231
+ */ this.isDowngrade = false;
232
+ }
233
+ var _proto = DeviceProxy.prototype;
234
+ /**
235
+ * 设置 JSAPI 返回的系统信息
236
+ * @param systemInfo - JSAPI 返回的系统信息
237
+ */ _proto.setSystemInfo = function setSystemInfo(systemInfo) {
238
+ var performance = systemInfo.performance, platform = systemInfo.platform, _systemInfo_model = systemInfo.model, model = _systemInfo_model === void 0 ? "UNKNOWN_DEVICE" : _systemInfo_model, _systemInfo_system = systemInfo.system, system = _systemInfo_system === void 0 ? "Unknown" : _systemInfo_system;
239
+ this.isIOS = platform === "iOS";
240
+ this.model = model;
241
+ this.system = system;
242
+ this.setLevel(performance);
243
+ };
244
+ /**
245
+ * 根据传入的 JSAPI 降级结果,返回设备的降级决定
246
+ *
247
+ * @param result - JSAPI 返回的降级结果
248
+ * @returns 设备降级决定
249
+ */ _proto.getDowngradeDecision = function getDowngradeDecision(result) {
250
+ var resultType = undefined;
251
+ var resultReason = undefined;
252
+ if (result.error) {
253
+ // 无权调用的情况下不降级
254
+ return {
255
+ downgrade: result.error !== 4,
256
+ level: this.getRenderLevel(),
257
+ reason: "api error: " + result.error
258
+ };
259
+ }
260
+ try {
261
+ var ret = EFFECTS.isString(result) ? JSON.parse(result) : result;
262
+ if ("downgradeResultType" in ret) {
263
+ resultType = ret.downgradeResultType;
264
+ } else if ("resultType" in ret) {
265
+ resultType = ret.resultType;
266
+ resultReason = ret.resultReason;
267
+ }
268
+ if (result.context) {
269
+ var deviceInfo = result.context.deviceInfo;
270
+ if (deviceInfo) {
271
+ var deviceLevel = deviceInfo.deviceLevel;
272
+ var newLevel = getDeviceLevel(deviceLevel);
273
+ if (newLevel !== exports.DeviceLevel.Unknown) {
274
+ this.level = newLevel;
275
+ }
276
+ }
277
+ }
278
+ } catch (ex) {
279
+ EFFECTS.logger.error(ex);
280
+ }
281
+ if (resultType === undefined) {
282
+ return {
283
+ downgrade: true,
284
+ level: this.getRenderLevel(),
285
+ reason: "call downgrade fail"
286
+ };
287
+ }
288
+ if (resultType === 1) {
289
+ return {
290
+ downgrade: true,
291
+ level: this.getRenderLevel(),
292
+ reason: getDowngradeReason(resultReason)
293
+ };
294
+ }
295
+ if (EFFECTS.isAlipayMiniApp() && this.downgradeForMiniprogram()) {
296
+ return {
297
+ downgrade: true,
298
+ level: this.getRenderLevel(),
299
+ reason: "Force downgrade by downgrade plugin"
300
+ };
301
+ }
302
+ return {
303
+ downgrade: false,
304
+ level: this.getRenderLevel(),
305
+ reason: "" + resultType
306
+ };
307
+ };
308
+ /**
309
+ * 获取设备渲染等级
310
+ * @returns 设备渲染等级
311
+ */ _proto.getRenderLevel = function getRenderLevel() {
312
+ if (this.level === exports.DeviceLevel.High) {
313
+ return EFFECTS.spec.RenderLevel.S;
314
+ } else if (this.level === exports.DeviceLevel.Medium) {
315
+ return EFFECTS.spec.RenderLevel.A;
316
+ } else if (this.level === exports.DeviceLevel.Low) {
317
+ return EFFECTS.spec.RenderLevel.B;
318
+ } else {
319
+ return this.isIOS ? EFFECTS.spec.RenderLevel.S : EFFECTS.spec.RenderLevel.B;
320
+ }
321
+ };
322
+ _proto.setLevel = function setLevel(level) {
323
+ this.level = getDeviceLevel(level);
324
+ if (this.level === exports.DeviceLevel.Unknown) {
325
+ if (/iPhone(\d+),/.test(this.model)) {
326
+ var gen = +RegExp.$1;
327
+ if (gen <= 9) {
328
+ this.level = exports.DeviceLevel.Low;
329
+ } else if (gen < 10) {
330
+ this.level = exports.DeviceLevel.Medium;
331
+ } else {
332
+ this.level = exports.DeviceLevel.High;
333
+ }
334
+ }
335
+ }
336
+ };
337
+ _proto.downgradeForMiniprogram = function downgradeForMiniprogram() {
338
+ var _this = this;
339
+ if (this.isIOS) {
340
+ if (deviceModelList.find(function(v) {
341
+ return v === _this.model;
342
+ })) {
343
+ var versionList = this.system.split(".");
344
+ if (versionList.length > 0 && versionList[0] === "16") {
345
+ return true;
346
+ }
347
+ }
348
+ }
349
+ return false;
350
+ };
351
+ return DeviceProxy;
352
+ }();
353
+ function getDowngradeReason(reason) {
354
+ if (reason === -1) {
355
+ return "" + reason + ", unable to pull configuration";
356
+ } else if (reason === 0) {
357
+ return "" + reason + ", no downgrade";
358
+ } else if (reason === 1) {
359
+ return "" + reason + ", memory downgrade";
360
+ } else if (reason === 2) {
361
+ return "" + reason + ", crash downgrade";
362
+ } else if (reason === 3) {
363
+ return "" + reason + ", basic dimension downgrade";
364
+ } else if (reason === 4) {
365
+ return "" + reason + ", technical point downgrade";
366
+ } else if (reason === 5) {
367
+ return "" + reason + ", GPU downgrade";
368
+ } else if (reason === 6) {
369
+ return "" + reason + ", self-healing downgrade";
370
+ } else if (reason === 7) {
371
+ return "" + reason + ", 32-bit CPU downgrade";
372
+ } else {
373
+ return "" + reason;
374
+ }
375
+ }
376
+ function getDeviceLevel(level) {
377
+ if (level === "high") {
378
+ return exports.DeviceLevel.High;
379
+ } else if (level === "medium" || level === "middle") {
380
+ return exports.DeviceLevel.Medium;
381
+ } else if (level === "low") {
382
+ return exports.DeviceLevel.Low;
383
+ } else {
384
+ return exports.DeviceLevel.Unknown;
385
+ }
386
+ }
387
+
388
+ var internalPaused = Symbol("@@_inter_pause");
172
389
  var mockIdPass = "mock-pass";
173
390
  var mockIdFail = "mock-fail";
174
- var DEVICE_LEVEL_HIGH = "high";
175
- var DEVICE_LEVEL_MEDIUM = "medium";
176
- var DEVICE_LEVEL_LOW = "low";
177
- var DEVICE_LEVEL_NONE = "none";
178
391
  var hasRegisterEvent = false;
179
- function getDowngradeResult(bizId) {
392
+ /**
393
+ * 获取 GE 降级结果,在有 JSAPI 环境下调用,不需要创建 Canvas 和 WebGL 环境。
394
+ *
395
+ * @param bizId - 业务 bizId
396
+ * @param options - 降级选项
397
+ * @returns 降级结果
398
+ */ function getDowngradeResult(bizId) {
180
399
  return _getDowngradeResult.apply(this, arguments);
181
400
  }
182
401
  function _getDowngradeResult() {
183
402
  _getDowngradeResult = _async_to_generator(function(bizId, options) {
184
- var ap, now;
403
+ var _options_level, ap, _options_level1, systemStartTime;
185
404
  return __generator(this, function(_state) {
186
405
  if (options === void 0) options = {};
187
406
  if (!hasRegisterEvent) {
188
- registerEvent(options);
189
407
  hasRegisterEvent = true;
408
+ registerEvent(options);
190
409
  }
191
410
  if (bizId === mockIdFail || bizId === mockIdPass) {
192
411
  return [
193
412
  2,
194
413
  Promise.resolve({
195
- mock: {
196
- downgrade: bizId === mockIdFail
197
- }
414
+ bizId: bizId,
415
+ downgrade: bizId === mockIdFail,
416
+ level: (_options_level = options.level) != null ? _options_level : EFFECTS.spec.RenderLevel.S,
417
+ reason: "mock"
198
418
  })
199
419
  ];
200
420
  }
201
- ap = window.AlipayJSBridge;
202
- if (ap) {
203
- now = performance.now();
421
+ ap = EFFECTS.isAlipayMiniApp() ? my : window.AlipayJSBridge;
422
+ // 当需要通过 ap 获取降级信息时,才进行降级环境的检查
423
+ if (!ap && (!options.systemInfo || !options.downgradeResult)) {
204
424
  return [
205
425
  2,
206
- getSystemInfo().then(function(systemInfo) {
207
- return new Promise(function(resolve) {
208
- var techPoint = [
209
- "mars"
210
- ];
211
- var tc = options.techPoint;
212
- if (tc) {
213
- var _techPoint;
214
- (_techPoint = techPoint).push.apply(_techPoint, [].concat(tc));
215
- }
216
- var downgradeOptions = {
217
- bizId: bizId,
218
- scene: 0,
219
- ext: {
220
- techPoint: techPoint
221
- }
222
- };
223
- var downgradeCallback = function(result) {
224
- var totalTime = performance.now() - now;
225
- console.info("downgrade time: " + totalTime + "ms");
226
- resolve({
227
- bizId: bizId,
228
- systemInfo: systemInfo,
229
- downgradeResult: result,
230
- totalTime: totalTime
231
- });
232
- };
233
- var _options_callBridge;
234
- var callBridge = (_options_callBridge = options.callBridge) != null ? _options_callBridge : ap.call;
235
- callBridge("getDowngradeResult", downgradeOptions, downgradeCallback);
236
- });
237
- })
238
- ];
239
- } else {
240
- return [
241
- 2,
242
- Promise.resolve({
243
- noAlipayEnv: true
244
- })
426
+ {
427
+ bizId: bizId,
428
+ downgrade: false,
429
+ level: (_options_level1 = options.level) != null ? _options_level1 : EFFECTS.spec.RenderLevel.S,
430
+ reason: "Non-Alipay environment"
431
+ }
245
432
  ];
246
433
  }
434
+ systemStartTime = performance.now();
435
+ return [
436
+ 2,
437
+ getSystemInfoJSAPI(options, ap).then(function(systemInfo) {
438
+ var systemEndTime = performance.now();
439
+ return getDowngradeResultJSAPI(bizId, options, ap).then(function(downgradeResult) {
440
+ var downgradeEndTime = performance.now();
441
+ EFFECTS.logger.info("Downgrade time: " + (downgradeEndTime - systemStartTime) + "ms.");
442
+ var device = new DeviceProxy();
443
+ device.setSystemInfo(systemInfo);
444
+ var decision = device.getDowngradeDecision(downgradeResult);
445
+ if (options.level) {
446
+ decision.level = options.level;
447
+ }
448
+ var result = _extends({}, decision, {
449
+ bizId: bizId,
450
+ systemInfo: systemInfo,
451
+ systemTime: systemEndTime - systemStartTime,
452
+ downgradeResult: downgradeResult,
453
+ downgradeTime: downgradeEndTime - systemEndTime
454
+ });
455
+ return result;
456
+ });
457
+ })
458
+ ];
247
459
  });
248
460
  });
249
461
  return _getDowngradeResult.apply(this, arguments);
250
462
  }
251
463
  function registerEvent(options) {
252
- var ignoreGLLost = options.ignoreGLLost, autoPause = options.autoPause;
253
- var downgradeWhenGLLost = ignoreGLLost !== true;
464
+ var autoPause = options.autoPause;
254
465
  window.addEventListener("unload", function() {
255
- effects.getActivePlayers().forEach(function(player) {
466
+ EFFECTS.getActivePlayers().forEach(function(player) {
256
467
  return player.dispose();
257
468
  });
258
469
  });
259
- window.addEventListener("webglcontextlost", function(e) {
260
- if (effects.isCanvasUsedByPlayer(e.target)) {
261
- AlipayDowngradePlugin.glLostOccurred = true;
262
- console.error("webgl lost occur");
263
- if (downgradeWhenGLLost) {
264
- console.warn("webgl lost occur, all players will be downgraded from now on");
265
- effects.disableAllPlayer(true);
266
- effects.getActivePlayers().forEach(function(player) {
267
- return player.dispose();
268
- });
269
- }
270
- }
271
- }, true);
272
470
  if (autoPause) {
273
471
  document.addEventListener("pause", pauseAllActivePlayers);
274
472
  document.addEventListener("resume", resumePausedPlayers);
275
473
  }
276
474
  }
277
- function getSystemInfo() {
278
- return _getSystemInfo.apply(this, arguments);
475
+ function getSystemInfoJSAPI(options, ap) {
476
+ return _getSystemInfoJSAPI.apply(this, arguments);
279
477
  }
280
- function _getSystemInfo() {
281
- _getSystemInfo = _async_to_generator(function() {
478
+ function _getSystemInfoJSAPI() {
479
+ _getSystemInfoJSAPI = _async_to_generator(function(options, ap) {
282
480
  return __generator(this, function(_state) {
283
- return [
284
- 2,
285
- new Promise(function(resolve, reject) {
286
- var ap = window.AlipayJSBridge;
287
- if (ap) {
481
+ if (options.systemInfo) {
482
+ return [
483
+ 2,
484
+ Promise.resolve(options.systemInfo)
485
+ ];
486
+ } else {
487
+ return [
488
+ 2,
489
+ new Promise(function(resolve, reject) {
288
490
  ap.call("getSystemInfo", function(e) {
289
491
  if (e.error) {
290
492
  reject(e);
@@ -292,183 +494,66 @@ function _getSystemInfo() {
292
494
  resolve(e);
293
495
  }
294
496
  });
295
- } else {
296
- reject("no ap");
297
- }
298
- })
299
- ];
497
+ })
498
+ ];
499
+ }
300
500
  });
301
501
  });
302
- return _getSystemInfo.apply(this, arguments);
502
+ return _getSystemInfoJSAPI.apply(this, arguments);
303
503
  }
304
- var DeviceProxy = /*#__PURE__*/ function() {
305
- function DeviceProxy() {
306
- this.isIOS = false;
307
- this.model = "DESKTOP_DEBUG";
308
- this.deviceLevel = DEVICE_LEVEL_NONE;
309
- this.isDowngrade = false;
310
- }
311
- var _proto = DeviceProxy.prototype;
312
- _proto.getRenderLevel = function getRenderLevel() {
313
- if (this.deviceLevel === DEVICE_LEVEL_HIGH) {
314
- return effects.spec.RenderLevel.S;
315
- } else if (this.deviceLevel === DEVICE_LEVEL_MEDIUM) {
316
- return effects.spec.RenderLevel.A;
317
- } else if (this.deviceLevel === DEVICE_LEVEL_LOW) {
318
- return effects.spec.RenderLevel.B;
319
- } else {
320
- return this.isIOS ? effects.spec.RenderLevel.S : effects.spec.RenderLevel.B;
321
- }
322
- };
323
- _proto.hasDeviceLevel = function hasDeviceLevel() {
324
- return isDeviceLevel(this.deviceLevel);
325
- };
326
- _proto.setBySystemInfo = function setBySystemInfo(systemInfo) {
327
- var performance1 = systemInfo.performance, platform = systemInfo.platform, _systemInfo_model = systemInfo.model, model = _systemInfo_model === void 0 ? "UNKNOWN_DEVICE" : _systemInfo_model;
328
- this.isIOS = platform === "iOS";
329
- this.model = model;
330
- if (performance1 && !this.hasDeviceLevel()) {
331
- this.deviceLevel = performance1;
332
- }
333
- };
334
- _proto.updateDeviceLevel = function updateDeviceLevel() {
335
- if (this.hasDeviceLevel()) {
336
- return;
337
- }
338
- if (/iPhone(\d+),/.test(this.model)) {
339
- var gen = +RegExp.$1;
340
- if (gen <= 9) {
341
- this.deviceLevel = DEVICE_LEVEL_LOW;
342
- } else if (gen < 10) {
343
- this.deviceLevel = DEVICE_LEVEL_MEDIUM;
344
- } else {
345
- this.deviceLevel = DEVICE_LEVEL_HIGH;
346
- }
347
- }
348
- };
349
- _proto.getDeviceInfo = function getDeviceInfo() {
350
- return {
351
- isIOS: this.isIOS,
352
- model: this.model,
353
- deviceLevel: this.deviceLevel
354
- };
355
- };
356
- return DeviceProxy;
357
- }();
358
- var device = new DeviceProxy();
359
- function checkDowngradeResult(result) {
360
- if (result.mock) {
361
- var _result_mock = result.mock, downgrade = _result_mock.downgrade, _result_mock_deviceLevel = _result_mock.deviceLevel, deviceLevel = _result_mock_deviceLevel === void 0 ? DEVICE_LEVEL_HIGH : _result_mock_deviceLevel;
362
- device.deviceLevel = deviceLevel;
363
- return {
364
- downgrade: downgrade,
365
- reason: "mock"
366
- };
367
- }
368
- if (result.noAlipayEnv) {
369
- return {
370
- downgrade: false,
371
- reason: "no AP env"
372
- };
373
- }
374
- if (!result.systemInfo) {
375
- return {
376
- downgrade: false,
377
- reason: "systemInfo is required"
378
- };
379
- }
380
- if (!result.downgradeResult) {
381
- return {
382
- downgrade: false,
383
- reason: "downgradeResult is required"
384
- };
385
- }
386
- device.setBySystemInfo(result.systemInfo);
387
- return parseDowngradeResult(result.downgradeResult);
504
+ function getDowngradeResultJSAPI(bizId, options, ap) {
505
+ return _getDowngradeResultJSAPI.apply(this, arguments);
388
506
  }
389
- function parseDowngradeResult(result) {
390
- var resultType = undefined;
391
- var resultReason = undefined;
392
- if (!result.error) {
393
- try {
394
- var ret = effects.isString(result) ? JSON.parse(result) : result;
395
- if ("downgradeResultType" in ret) {
396
- resultType = ret.downgradeResultType;
397
- } else if ("resultType" in ret) {
398
- resultType = ret.resultType;
399
- resultReason = ret.resultReason;
400
- }
401
- if (result.context) {
402
- var deviceInfo = result.context.deviceInfo;
403
- if (deviceInfo) {
404
- var deviceLevel = deviceInfo.deviceLevel;
405
- if (isDeviceLevel(deviceLevel)) {
406
- device.deviceLevel = deviceLevel;
407
- }
408
- }
409
- }
410
- device.updateDeviceLevel();
411
- } catch (ex) {
412
- console.error(ex);
413
- }
414
- if (resultType === undefined) {
415
- return {
416
- downgrade: true,
417
- reason: "call downgrade fail"
418
- };
419
- } else {
420
- if (resultType === 1) {
421
- return {
422
- downgrade: true,
423
- reason: getDowngradeReason(resultReason)
424
- };
507
+ function _getDowngradeResultJSAPI() {
508
+ _getDowngradeResultJSAPI = _async_to_generator(function(bizId, options, ap) {
509
+ return __generator(this, function(_state) {
510
+ if (options.downgradeResult) {
511
+ return [
512
+ 2,
513
+ Promise.resolve(options.downgradeResult)
514
+ ];
425
515
  } else {
426
- return {
427
- downgrade: false,
428
- reason: resultType
429
- };
516
+ return [
517
+ 2,
518
+ new Promise(function(resolve, reject) {
519
+ var techPoint = [
520
+ "mars"
521
+ ];
522
+ var tc = options.techPoint;
523
+ if (tc) {
524
+ var _techPoint;
525
+ (_techPoint = techPoint).push.apply(_techPoint, [].concat(tc));
526
+ }
527
+ var downgradeOptions = {
528
+ bizId: bizId,
529
+ scene: 0,
530
+ ext: {
531
+ techPoint: techPoint
532
+ }
533
+ };
534
+ var _options_callBridge;
535
+ var callBridge = (_options_callBridge = options.callBridge) != null ? _options_callBridge : ap.call;
536
+ callBridge("getDowngradeResult", downgradeOptions, function(result) {
537
+ resolve(result);
538
+ });
539
+ })
540
+ ];
430
541
  }
431
- }
432
- } else {
433
- // 无权调用的情况下不降级
434
- return {
435
- downgrade: result.error !== 4,
436
- reason: "api error: " + result.error
437
- };
438
- }
439
- }
440
- function getDowngradeReason(reason) {
441
- if (reason === -1) {
442
- return "" + reason + "-no config";
443
- } else if (reason === 0) {
444
- return "" + reason + "-none";
445
- } else if (reason === 1) {
446
- return "" + reason + "-downgrade by memory";
447
- } else if (reason === 2) {
448
- return "" + reason + "-downgrade by crash";
449
- } else if (reason === 3) {
450
- return "" + reason + "-downgrade by device";
451
- } else if (reason === 4) {
452
- return "" + reason + "-downgrade by force";
453
- } else {
454
- return "" + reason;
455
- }
456
- }
457
- function getRenderLevelByDevice(renderLevel) {
458
- if (!renderLevel) {
459
- return device.getRenderLevel();
460
- } else {
461
- return /[ABS]/.test(renderLevel) ? renderLevel : effects.spec.RenderLevel.S;
462
- }
542
+ });
543
+ });
544
+ return _getDowngradeResultJSAPI.apply(this, arguments);
463
545
  }
464
- function isDeviceLevel(deviceLevel) {
465
- return deviceLevel === DEVICE_LEVEL_HIGH || deviceLevel === DEVICE_LEVEL_MEDIUM || deviceLevel === DEVICE_LEVEL_LOW;
546
+ /**
547
+ * 获取默认渲染等级
548
+ *
549
+ * @returns 渲染等级
550
+ */ function getDefaultRenderLevel() {
551
+ return EFFECTS.isIOS() ? EFFECTS.spec.RenderLevel.S : EFFECTS.spec.RenderLevel.B;
466
552
  }
467
- var internalPaused = Symbol("@@_inter_pause");
468
553
  function pauseAllActivePlayers(e) {
469
554
  if (e.target === document) {
470
- effects.logger.info("Auto pause all players with data offloaded");
471
- var players = effects.getActivePlayers();
555
+ EFFECTS.logger.info("Auto pause all players with data offloaded.");
556
+ var players = EFFECTS.getActivePlayers();
472
557
  players.forEach(function(player) {
473
558
  if (!player.paused) {
474
559
  player.pause({
@@ -482,8 +567,8 @@ function pauseAllActivePlayers(e) {
482
567
  }
483
568
  function resumePausedPlayers(e) {
484
569
  if (e.target === document) {
485
- effects.logger.info("auto resume all players");
486
- var players = effects.getActivePlayers();
570
+ EFFECTS.logger.info("Auto resume all players.");
571
+ var players = EFFECTS.getActivePlayers();
487
572
  players.forEach(function(player) {
488
573
  // @ts-expect-error
489
574
  if (player[internalPaused]) {
@@ -495,49 +580,34 @@ function resumePausedPlayers(e) {
495
580
  }
496
581
  }
497
582
 
498
- var AlipayDowngradePlugin = /*#__PURE__*/ function(AbstractPlugin) {
583
+ /**
584
+ * Alipay 降级插件类
585
+ *
586
+ * 根据 SceneLoadOptions 中传入的 downgrade 数据,判断是否降级。
587
+ * 如果设备被降级,会在 processRawJSON 时抛出降级相关的异常和原因。
588
+ *
589
+ * 如果 SceneLoadOptions 中 renderLevel 没有设置,那么会根据 downgrade 数据
590
+ * 和默认的渲染等级规则设置其中的 renderLevel。
591
+ */ var AlipayDowngradePlugin = /*#__PURE__*/ function(AbstractPlugin) {
499
592
  _inherits(AlipayDowngradePlugin, AbstractPlugin);
500
593
  function AlipayDowngradePlugin() {
501
594
  return AbstractPlugin.apply(this, arguments);
502
595
  }
503
- AlipayDowngradePlugin.onPlayerCreated = function onPlayerCreated(player) {
504
- return _async_to_generator(function() {
505
- return __generator(this, function(_state) {
506
- if (AlipayDowngradePlugin.glLostOccurred) {
507
- console.warn("gl lost happened, new player will be destroyed.");
508
- return [
509
- 2,
510
- player.dispose()
511
- ];
512
- }
513
- return [
514
- 2
515
- ];
516
- });
517
- })();
518
- };
519
596
  AlipayDowngradePlugin.processRawJSON = function processRawJSON(json, options) {
520
597
  if (options === void 0) options = {};
521
598
  return _async_to_generator(function() {
522
- var _options_pluginData, downgradeResult, downgradeDecision;
599
+ var _options_pluginData, downgradeResult, _downgradeResult_level;
523
600
  return __generator(this, function(_state) {
524
- if (AlipayDowngradePlugin.glLostOccurred) {
525
- return [
526
- 2,
527
- Promise.reject("gl lost happened")
528
- ];
529
- }
530
601
  downgradeResult = (_options_pluginData = options.pluginData) == null ? void 0 : _options_pluginData["downgrade"];
531
602
  if (downgradeResult) {
532
- downgradeDecision = checkDowngradeResult(downgradeResult);
533
- if (downgradeDecision.downgrade) {
534
- throw new Error("downgraded, reason: " + downgradeDecision.reason);
603
+ if (downgradeResult.downgrade) {
604
+ throw new Error("Downgraded, reason: " + downgradeResult.reason);
535
605
  }
536
606
  } else {
537
- console.warn("No downgrade result in pluginData of SceneLoadOptions");
607
+ EFFECTS.logger.warn("No downgrade result in pluginData of SceneLoadOptions.");
538
608
  }
539
609
  if (!options.renderLevel) {
540
- options.renderLevel = getRenderLevelByDevice(options.renderLevel);
610
+ options.renderLevel = (_downgradeResult_level = downgradeResult == null ? void 0 : downgradeResult.level) != null ? _downgradeResult_level : getDefaultRenderLevel();
541
611
  }
542
612
  return [
543
613
  2
@@ -546,81 +616,37 @@ var AlipayDowngradePlugin = /*#__PURE__*/ function(AbstractPlugin) {
546
616
  })();
547
617
  };
548
618
  return AlipayDowngradePlugin;
549
- }(effects.AbstractPlugin);
550
- AlipayDowngradePlugin.glLostOccurred = false;
619
+ }(EFFECTS.AbstractPlugin);
551
620
 
552
621
  var prefix = "[Galacean Effects]";
553
- effects.logger.register(nativeLogger);
622
+ var ap = EFFECTS.isAlipayMiniApp() ? my : window.AlipayJSBridge;
623
+ EFFECTS.logger.register(nativeLogger);
554
624
  function nativeLogger(type, msg) {
555
625
  for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
556
626
  args[_key - 2] = arguments[_key];
557
627
  }
558
- if (effects.isAndroid()) {
559
- androidLogger.apply(void 0, [].concat([
560
- type,
561
- prefix + " " + msg
562
- ], args));
563
- } else if (effects.isIOS()) {
564
- iOSLogger.apply(void 0, [].concat([
565
- type,
566
- msg
567
- ], args));
568
- }
569
- }
570
- function iOSLogger(type, msg) {
571
- for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
572
- args[_key - 2] = arguments[_key];
573
- }
574
- try {
575
- var ap = window.AlipayJSBridge;
576
- var content = formatMessage.apply(void 0, [].concat([
577
- type,
578
- msg
579
- ], args));
580
- ap == null ? void 0 : ap.call("H5APLog", {
581
- content: content
582
- });
583
- } catch (e) {
584
- console.error(e);
585
- }
586
- }
587
- // Android H5 容器支持 console 日志直接写入 aplog
588
- function androidLogger(type, msg) {
589
- for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
590
- args[_key - 2] = arguments[_key];
628
+ var content = {
629
+ "message": prefix + " " + msg + " " + args.join(""),
630
+ "level": type
631
+ };
632
+ if (EFFECTS.isAndroid()) {
633
+ content["anr_info"] = "mars";
591
634
  }
592
635
  try {
593
- var ap = window.AlipayJSBridge;
594
- ap == null ? void 0 : ap.call("localLog", {
595
- "anr_info": "mars",
596
- "message": msg + args.join(""),
597
- "level": type
598
- });
636
+ ap == null ? void 0 : ap.call("localLog", content);
599
637
  } catch (e) {
600
638
  console.error(e);
601
639
  }
602
640
  }
603
- function formatMessage(level, msg) {
604
- for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
605
- args[_key - 2] = arguments[_key];
606
- }
607
- var result = [
608
- "<MARS_PLAYER>",
609
- "(" + level + "):",
610
- msg
611
- ];
612
- args.forEach(function(i) {
613
- result.push(i + "");
614
- });
615
- return result.join(" ");
616
- }
617
641
 
618
- var version = "2.0.0-alpha.9";
619
- effects.registerPlugin("alipay-downgrade", AlipayDowngradePlugin, DowngradeVFXItem, true);
620
- effects.logger.info("plugin alipay downgrade version: " + version);
642
+ var version = "2.0.0-beta.1";
643
+ EFFECTS.registerPlugin("alipay-downgrade", AlipayDowngradePlugin, EFFECTS.VFXItem, true);
644
+ EFFECTS.logger.info("Plugin downgrade version: " + version + ".");
645
+ if (version !== EFFECTS__namespace.version) {
646
+ console.error("注意:请统一 Downgrade 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Downgrade plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
647
+ }
621
648
 
622
- exports.checkDowngradeResult = checkDowngradeResult;
649
+ exports.getDefaultRenderLevel = getDefaultRenderLevel;
623
650
  exports.getDowngradeResult = getDowngradeResult;
624
- exports.getRenderLevelByDevice = getRenderLevelByDevice;
625
651
  exports.version = version;
626
652
  //# sourceMappingURL=index.js.map