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