@galacean/effects-plugin-alipay-downgrade 1.5.0-alpha.0 → 1.5.0

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.
@@ -0,0 +1,460 @@
1
+ import { window } from '@galacean/appx-adapter/alipay';
2
+ import { spec, isAlipayMiniApp, isString, AbstractPlugin, VFXItem, logger, isAndroid, registerPlugin, getActivePlayers, isCanvasUsedByPlayer, disableAllPlayer } from '@galacean/effects/alipay';
3
+
4
+ /******************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+ /* global Reflect, Promise, SuppressedError, Symbol */
19
+
20
+ var extendStatics = function(d, b) {
21
+ extendStatics = Object.setPrototypeOf ||
22
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
23
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
24
+ return extendStatics(d, b);
25
+ };
26
+
27
+ function __extends(d, b) {
28
+ if (typeof b !== "function" && b !== null)
29
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
30
+ extendStatics(d, b);
31
+ function __() { this.constructor = d; }
32
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
33
+ }
34
+
35
+ function __awaiter(thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ }
44
+
45
+ function __generator(thisArg, body) {
46
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
+ function verb(n) { return function (v) { return step([n, v]); }; }
49
+ function step(op) {
50
+ if (f) throw new TypeError("Generator is already executing.");
51
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
+ if (y = 0, t) op = [op[0] & 2, t.value];
54
+ switch (op[0]) {
55
+ case 0: case 1: t = op; break;
56
+ case 4: _.label++; return { value: op[1], done: false };
57
+ case 5: _.label++; y = op[1]; op = [0]; continue;
58
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
+ default:
60
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
+ if (t[2]) _.ops.pop();
65
+ _.trys.pop(); continue;
66
+ }
67
+ op = body.call(thisArg, _);
68
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
+ }
71
+ }
72
+
73
+ function __read(o, n) {
74
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
75
+ if (!m) return o;
76
+ var i = m.call(o), r, ar = [], e;
77
+ try {
78
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
79
+ }
80
+ catch (error) { e = { error: error }; }
81
+ finally {
82
+ try {
83
+ if (r && !r.done && (m = i["return"])) m.call(i);
84
+ }
85
+ finally { if (e) throw e.error; }
86
+ }
87
+ return ar;
88
+ }
89
+
90
+ function __spreadArray(to, from, pack) {
91
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
92
+ if (ar || !(i in from)) {
93
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
94
+ ar[i] = from[i];
95
+ }
96
+ }
97
+ return to.concat(ar || Array.prototype.slice.call(from));
98
+ }
99
+
100
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
101
+ var e = new Error(message);
102
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
103
+ };
104
+
105
+ var DEVICE_PERFORMANCE_LOW = 'low';
106
+ var DEVICE_PERFORMANCE_MIDDLE = 'middle';
107
+ var DEVICE_PERFORMANCE_HIGH = 'high';
108
+ var devicePending;
109
+ var devicePerformance;
110
+ var deviceName = 'DESKTOP_DEBUG';
111
+ var deviceSystem = 'Unknown';
112
+ var isIOS = false;
113
+ function getDeviceName() {
114
+ return __awaiter(this, void 0, void 0, function () {
115
+ return __generator(this, function (_a) {
116
+ if (!devicePending) {
117
+ devicePending = getSystemInfo().then(function (info) {
118
+ var performance = info.performance, platform = info.platform, _a = info.model, model = _a === void 0 ? 'UNKNOWN_DEVICE' : _a, _b = info.system, system = _b === void 0 ? 'Unknown' : _b;
119
+ if (!devicePerformance) {
120
+ devicePerformance = performance;
121
+ }
122
+ isIOS = platform === 'iOS';
123
+ deviceName = model;
124
+ deviceSystem = system;
125
+ if (/iPhone(\d+),/.test(deviceName) && !devicePerformance) {
126
+ var gen = +RegExp.$1;
127
+ // https://gist.github.com/adamawolf/3048717 device code
128
+ if (gen <= 9) { // iphone 7,iphone 7p
129
+ devicePerformance = DEVICE_PERFORMANCE_LOW;
130
+ }
131
+ else if (gen < 10) {
132
+ devicePerformance = DEVICE_PERFORMANCE_MIDDLE;
133
+ }
134
+ else {
135
+ devicePerformance = DEVICE_PERFORMANCE_HIGH;
136
+ }
137
+ }
138
+ if (deviceName.indexOf(info.brand) === 0) {
139
+ deviceName = deviceName.replace(info.brand, '').trim();
140
+ }
141
+ return deviceName;
142
+ }, function (e) {
143
+ });
144
+ }
145
+ return [2 /*return*/, devicePending.then(function () { return deviceName; }, function () { return deviceName; })];
146
+ });
147
+ });
148
+ }
149
+ function getRenderLevelByDevice(renderLevel) {
150
+ if (renderLevel === 'auto' || !renderLevel) {
151
+ if (devicePerformance === DEVICE_PERFORMANCE_HIGH) {
152
+ return spec.RenderLevel.S;
153
+ }
154
+ else if (devicePerformance === DEVICE_PERFORMANCE_MIDDLE) {
155
+ return spec.RenderLevel.A;
156
+ }
157
+ else if (devicePerformance === DEVICE_PERFORMANCE_LOW) {
158
+ return spec.RenderLevel.B;
159
+ }
160
+ return isIOS ? spec.RenderLevel.S : spec.RenderLevel.B;
161
+ }
162
+ return /[ABS]/.test(renderLevel) ? renderLevel : spec.RenderLevel.S;
163
+ }
164
+ function resetDevicePending() {
165
+ devicePending = undefined;
166
+ }
167
+ var mockIdPass = 'mock-pass';
168
+ var mockIdFail = 'mock-fail';
169
+ /**
170
+ *
171
+ * @param bizId
172
+ * @param options
173
+ * @returns
174
+ */
175
+ function checkDowngrade(bizId, options) {
176
+ if (options === void 0) { options = {}; }
177
+ return __awaiter(this, void 0, void 0, function () {
178
+ var ap, now_1;
179
+ return __generator(this, function (_a) {
180
+ if (bizId === mockIdFail || bizId === mockIdPass) {
181
+ return [2 /*return*/, Promise.resolve({ downgrade: bizId === mockIdFail, reason: 'mock' })];
182
+ }
183
+ ap = isAlipayMiniApp() ? my : window.AlipayJSBridge;
184
+ if (ap) {
185
+ now_1 = performance.now();
186
+ return [2 /*return*/, getDeviceName().then(function () {
187
+ return new Promise(function (resolve) {
188
+ var _a;
189
+ var techPoint = ['mars'];
190
+ var tc = options.techPoint;
191
+ if (tc) {
192
+ techPoint.push.apply(techPoint, __spreadArray([], __read(tc), false));
193
+ }
194
+ var callBridge = (_a = options.callBridge) !== null && _a !== void 0 ? _a : ap.call;
195
+ callBridge('getDowngradeResult', {
196
+ bizId: bizId,
197
+ scene: 0,
198
+ ext: {
199
+ techPoint: techPoint,
200
+ },
201
+ }, function (result) {
202
+ var reason = undefined;
203
+ console.info("downgrade time: ".concat(performance.now() - now_1, "ms"));
204
+ if (!result.error) {
205
+ try {
206
+ var ret = isString(result) ? JSON.parse(result) : result;
207
+ if ('downgradeResultType' in ret) {
208
+ reason = ret.downgradeResultType;
209
+ }
210
+ else if ('resultType' in ret) {
211
+ reason = ret.resultType;
212
+ }
213
+ if (result.context) {
214
+ var deviceInfo = result.context.deviceInfo;
215
+ if (deviceInfo) {
216
+ var level = deviceInfo.deviceLevel;
217
+ if (level === DEVICE_PERFORMANCE_HIGH || level === DEVICE_PERFORMANCE_LOW) {
218
+ devicePerformance = level;
219
+ }
220
+ else if (level === 'medium') {
221
+ devicePerformance = DEVICE_PERFORMANCE_MIDDLE;
222
+ }
223
+ }
224
+ }
225
+ }
226
+ catch (ex) {
227
+ console.error(ex);
228
+ }
229
+ }
230
+ else {
231
+ // 无权调用的情况下不降级
232
+ resolve({ downgrade: result.error !== 4, reason: 'api error:' + result.error });
233
+ }
234
+ if (reason === undefined) {
235
+ resolve({ downgrade: true, reason: 'call downgrade fail' });
236
+ }
237
+ else {
238
+ if (isAlipayMiniApp() && downgradeForMiniprogram()) {
239
+ resolve({ downgrade: true, reason: 'Force downgrade by downgrade plugin' });
240
+ }
241
+ else {
242
+ resolve({ downgrade: reason === 1, reason: reason });
243
+ }
244
+ }
245
+ });
246
+ });
247
+ })];
248
+ }
249
+ return [2 /*return*/, Promise.resolve({ downgrade: false, reason: 'no AP env' })];
250
+ });
251
+ });
252
+ }
253
+ function getSystemInfo() {
254
+ return __awaiter(this, void 0, void 0, function () {
255
+ return __generator(this, function (_a) {
256
+ return [2 /*return*/, new Promise(function (resolve, reject) {
257
+ //@ts-expect-error
258
+ var ap = isAlipayMiniApp() ? my : window.AlipayJSBridge;
259
+ if (ap) {
260
+ ap.call('getSystemInfo', function (e) {
261
+ if (e.error) {
262
+ reject(e);
263
+ }
264
+ else {
265
+ resolve(e);
266
+ }
267
+ });
268
+ }
269
+ else {
270
+ reject('no ap');
271
+ }
272
+ })];
273
+ });
274
+ });
275
+ }
276
+ var deviceNameList = ['12,8', '13,1', '13,2', '13,3', '13,4'];
277
+ /**
278
+ * iPhone SE2 和 12 全系列机型,如果是 iOS16 系统,在小程序中强制降级
279
+ * @returns
280
+ */
281
+ function downgradeForMiniprogram() {
282
+ if (isIOS) {
283
+ if (deviceNameList.find(function (v) { return v === deviceName; })) {
284
+ var versionList = deviceSystem.split('.');
285
+ if (versionList.length > 0 && versionList[0] === '16') {
286
+ return true;
287
+ }
288
+ }
289
+ }
290
+ return false;
291
+ }
292
+
293
+ var AlipayDowngradePlugin = /** @class */ (function (_super) {
294
+ __extends(AlipayDowngradePlugin, _super);
295
+ function AlipayDowngradePlugin() {
296
+ return _super !== null && _super.apply(this, arguments) || this;
297
+ }
298
+ AlipayDowngradePlugin.onPlayerCreated = function (player) {
299
+ return __awaiter(this, void 0, void 0, function () {
300
+ var result;
301
+ return __generator(this, function (_a) {
302
+ switch (_a.label) {
303
+ case 0:
304
+ if (AlipayDowngradePlugin.glLostOccurred) {
305
+ console.warn('gl lost happened, new player will be destroyed.');
306
+ return [2 /*return*/, player.dispose()];
307
+ }
308
+ if (!AlipayDowngradePlugin.currentBizId) return [3 /*break*/, 2];
309
+ return [4 /*yield*/, checkDowngrade(AlipayDowngradePlugin.currentBizId)];
310
+ case 1:
311
+ result = _a.sent();
312
+ if (result.downgrade) {
313
+ console.warn('automatically destroy downgraded player.');
314
+ player.dispose();
315
+ }
316
+ _a.label = 2;
317
+ case 2: return [2 /*return*/];
318
+ }
319
+ });
320
+ });
321
+ };
322
+ AlipayDowngradePlugin.processRawJSON = function (json, options) {
323
+ var _a, _b;
324
+ if (options === void 0) { options = {}; }
325
+ return __awaiter(this, void 0, void 0, function () {
326
+ var result;
327
+ return __generator(this, function (_c) {
328
+ switch (_c.label) {
329
+ case 0:
330
+ if (AlipayDowngradePlugin.glLostOccurred) {
331
+ return [2 /*return*/, Promise.reject('gl lost happened')];
332
+ }
333
+ return [4 /*yield*/, checkDowngrade((_b = (_a = options.pluginData) === null || _a === void 0 ? void 0 : _a['alipayBizId']) !== null && _b !== void 0 ? _b : AlipayDowngradePlugin.currentBizId)];
334
+ case 1:
335
+ result = _c.sent();
336
+ if (result.downgrade) {
337
+ throw new Error("downgraded, reason: ".concat(result.reason));
338
+ }
339
+ if (!options.renderLevel) {
340
+ options.renderLevel = getRenderLevelByDevice(options.renderLevel);
341
+ }
342
+ return [2 /*return*/];
343
+ }
344
+ });
345
+ });
346
+ };
347
+ AlipayDowngradePlugin.currentBizId = '';
348
+ AlipayDowngradePlugin.glLostOccurred = false;
349
+ return AlipayDowngradePlugin;
350
+ }(AbstractPlugin));
351
+
352
+ var DowngradeVFXItem = /** @class */ (function (_super) {
353
+ __extends(DowngradeVFXItem, _super);
354
+ function DowngradeVFXItem() {
355
+ return _super !== null && _super.apply(this, arguments) || this;
356
+ }
357
+ return DowngradeVFXItem;
358
+ }(VFXItem));
359
+
360
+ var prefix = '[Galacean Effects]';
361
+ //@ts-expect-error
362
+ var ap = isAlipayMiniApp() ? my : window.AlipayJSBridge;
363
+ logger.register(nativeLogger);
364
+ function nativeLogger(type, msg) {
365
+ var args = [];
366
+ for (var _i = 2; _i < arguments.length; _i++) {
367
+ args[_i - 2] = arguments[_i];
368
+ }
369
+ var content = {
370
+ 'message': "".concat(prefix, " ").concat(msg, " ").concat(args.join('')),
371
+ 'level': type,
372
+ };
373
+ if (isAndroid()) {
374
+ content['anr_info'] = 'mars';
375
+ }
376
+ try {
377
+ ap === null || ap === void 0 ? void 0 : ap.call('localLog', content);
378
+ }
379
+ catch (e) {
380
+ console.error(e);
381
+ }
382
+ }
383
+
384
+ var registered = false;
385
+ /**
386
+ * 支付宝端内统一降级方案,传入降级 ID,每次加载场景前都会自动调用降级
387
+ * - 如果要为某个 json 单独配置降级 ID,可以使用 `player.loadScene(url, { pluginData: { alipayBizId: '#bizId#' }})`
388
+ * @param bizId - 降级 ID,如果为 `mock-pass` 将 mock 不降级场景,如果为 `mock-fail` 将 mock 降级场景,业务请不要使用这两个字符串
389
+ * @param options - 优化策略
390
+ */
391
+ function setAlipayDowngradeBizId(bizId, options) {
392
+ if (options === void 0) { options = {}; }
393
+ var ignoreGLLost = options.ignoreGLLost, autoPause = options.autoPause;
394
+ var downgradeWhenGLLost = ignoreGLLost !== true;
395
+ AlipayDowngradePlugin.currentBizId = bizId;
396
+ if (registered) {
397
+ return;
398
+ }
399
+ registerPlugin('alipay-downgrade', AlipayDowngradePlugin, DowngradeVFXItem, true);
400
+ window.addEventListener('unload', function () {
401
+ getActivePlayers().forEach(function (player) { return player.dispose(); });
402
+ });
403
+ window.addEventListener('webglcontextlost', function (e) {
404
+ if (isCanvasUsedByPlayer(e.target)) {
405
+ AlipayDowngradePlugin.glLostOccurred = true;
406
+ console.error('webgl lost occur');
407
+ if (downgradeWhenGLLost) {
408
+ console.warn('webgl lost occur, all players will be downgraded from now on');
409
+ disableAllPlayer(true);
410
+ getActivePlayers().forEach(function (player) { return player.dispose(); });
411
+ }
412
+ }
413
+ }, true);
414
+ if (autoPause) {
415
+ document.addEventListener('pause', pauseAllActivePlayers);
416
+ document.addEventListener('resume', resumePausedPlayers);
417
+ }
418
+ registered = true;
419
+ void getDeviceName();
420
+ }
421
+ /**
422
+ *
423
+ * @returns
424
+ */
425
+ function getAlipayDowngradeBizId() {
426
+ return AlipayDowngradePlugin.currentBizId;
427
+ }
428
+ var internalPaused = Symbol('@@_inter_pause');
429
+ function pauseAllActivePlayers(e) {
430
+ if (e.target === document) {
431
+ logger.info('Auto pause all players with data offloaded');
432
+ var players = getActivePlayers();
433
+ players.forEach(function (player) {
434
+ if (!player.paused) {
435
+ player.pause({ offloadTexture: true });
436
+ // @ts-expect-error
437
+ player[internalPaused] = true;
438
+ }
439
+ });
440
+ }
441
+ }
442
+ function resumePausedPlayers(e) {
443
+ if (e.target === document) {
444
+ logger.info('auto resume all players');
445
+ var players = getActivePlayers();
446
+ players.forEach(function (player) {
447
+ // @ts-expect-error
448
+ if (player[internalPaused]) {
449
+ void player.resume();
450
+ // @ts-expect-error
451
+ player[internalPaused] = false;
452
+ }
453
+ });
454
+ }
455
+ }
456
+ var version = "1.5.0";
457
+ logger.info('plugin alipay downgrade version: ' + version);
458
+
459
+ export { checkDowngrade, downgradeForMiniprogram, getAlipayDowngradeBizId, getDeviceName, getRenderLevelByDevice, getSystemInfo, resetDevicePending, setAlipayDowngradeBizId, version };
460
+ //# sourceMappingURL=alipay.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alipay.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects player downgrade plugin for Alipay
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,意绮
6
- * Version: v1.5.0-alpha.0
6
+ * Version: v1.5.0
7
7
  */
8
8
 
9
9
  'use strict';
@@ -119,18 +119,20 @@ var DEVICE_PERFORMANCE_HIGH = 'high';
119
119
  var devicePending;
120
120
  var devicePerformance;
121
121
  var deviceName = 'DESKTOP_DEBUG';
122
+ var deviceSystem = 'Unknown';
122
123
  var isIOS = false;
123
124
  function getDeviceName() {
124
125
  return __awaiter(this, void 0, void 0, function () {
125
126
  return __generator(this, function (_a) {
126
127
  if (!devicePending) {
127
128
  devicePending = getSystemInfo().then(function (info) {
128
- var performance = info.performance, platform = info.platform, _a = info.model, model = _a === void 0 ? 'UNKNOWN_DEVICE' : _a;
129
+ var performance = info.performance, platform = info.platform, _a = info.model, model = _a === void 0 ? 'UNKNOWN_DEVICE' : _a, _b = info.system, system = _b === void 0 ? 'Unknown' : _b;
129
130
  if (!devicePerformance) {
130
131
  devicePerformance = performance;
131
132
  }
132
133
  isIOS = platform === 'iOS';
133
134
  deviceName = model;
135
+ deviceSystem = system;
134
136
  if (/iPhone(\d+),/.test(deviceName) && !devicePerformance) {
135
137
  var gen = +RegExp.$1;
136
138
  // https://gist.github.com/adamawolf/3048717 device code
@@ -189,7 +191,7 @@ function checkDowngrade(bizId, options) {
189
191
  if (bizId === mockIdFail || bizId === mockIdPass) {
190
192
  return [2 /*return*/, Promise.resolve({ downgrade: bizId === mockIdFail, reason: 'mock' })];
191
193
  }
192
- ap = window.AlipayJSBridge;
194
+ ap = effects.isAlipayMiniApp() ? my : window.AlipayJSBridge;
193
195
  if (ap) {
194
196
  now_1 = performance.now();
195
197
  return [2 /*return*/, getDeviceName().then(function () {
@@ -244,7 +246,12 @@ function checkDowngrade(bizId, options) {
244
246
  resolve({ downgrade: true, reason: 'call downgrade fail' });
245
247
  }
246
248
  else {
247
- resolve({ reason: reason, downgrade: reason === 1 });
249
+ if (effects.isAlipayMiniApp() && downgradeForMiniprogram()) {
250
+ resolve({ downgrade: true, reason: 'Force downgrade by downgrade plugin' });
251
+ }
252
+ else {
253
+ resolve({ downgrade: reason === 1, reason: reason });
254
+ }
248
255
  }
249
256
  });
250
257
  });
@@ -258,7 +265,8 @@ function getSystemInfo() {
258
265
  return __awaiter(this, void 0, void 0, function () {
259
266
  return __generator(this, function (_a) {
260
267
  return [2 /*return*/, new Promise(function (resolve, reject) {
261
- var ap = window.AlipayJSBridge;
268
+ //@ts-expect-error
269
+ var ap = effects.isAlipayMiniApp() ? my : window.AlipayJSBridge;
262
270
  if (ap) {
263
271
  ap.call('getSystemInfo', function (e) {
264
272
  if (e.error) {
@@ -276,6 +284,22 @@ function getSystemInfo() {
276
284
  });
277
285
  });
278
286
  }
287
+ var deviceNameList = ['12,8', '13,1', '13,2', '13,3', '13,4'];
288
+ /**
289
+ * iPhone SE2 和 12 全系列机型,如果是 iOS16 系统,在小程序中强制降级
290
+ * @returns
291
+ */
292
+ function downgradeForMiniprogram() {
293
+ if (isIOS) {
294
+ if (deviceNameList.find(function (v) { return v === deviceName; })) {
295
+ var versionList = deviceSystem.split('.');
296
+ if (versionList.length > 0 && versionList[0] === '16') {
297
+ return true;
298
+ }
299
+ }
300
+ }
301
+ return false;
302
+ }
279
303
 
280
304
  var AlipayDowngradePlugin = /** @class */ (function (_super) {
281
305
  __extends(AlipayDowngradePlugin, _super);
@@ -344,69 +368,41 @@ var DowngradeVFXItem = /** @class */ (function (_super) {
344
368
  return DowngradeVFXItem;
345
369
  }(effects.VFXItem));
346
370
 
371
+ /**
372
+ * 将日志写到 native 容器的日志中,便于线上问题排查。
373
+ * 打印的日志可以通过海纳上捞取用户本地日志获得。
374
+ *
375
+ * @example
376
+ * ``` ts
377
+ * // 普通日志,使用方法和console日志一样。
378
+ * nativeLog.log('this is native log from h5.');
379
+ * // 错误日志
380
+ * nativeLog.error('this is native log from h5, error:', error);
381
+ * ```
382
+ */
347
383
  var prefix = '[Galacean Effects]';
384
+ //@ts-expect-error
385
+ var ap = effects.isAlipayMiniApp() ? my : window.AlipayJSBridge;
348
386
  effects.logger.register(nativeLogger);
349
387
  function nativeLogger(type, msg) {
350
388
  var args = [];
351
389
  for (var _i = 2; _i < arguments.length; _i++) {
352
390
  args[_i - 2] = arguments[_i];
353
391
  }
392
+ var content = {
393
+ 'message': "".concat(prefix, " ").concat(msg, " ").concat(args.join('')),
394
+ 'level': type,
395
+ };
354
396
  if (effects.isAndroid()) {
355
- androidLogger.apply(void 0, __spreadArray([type, "".concat(prefix, " ").concat(msg)], __read(args), false));
356
- }
357
- else if (effects.isIOS()) {
358
- iOSLogger.apply(void 0, __spreadArray([type, msg], __read(args), false));
359
- }
360
- }
361
- function iOSLogger(type, msg) {
362
- var args = [];
363
- for (var _i = 2; _i < arguments.length; _i++) {
364
- args[_i - 2] = arguments[_i];
397
+ content['anr_info'] = 'mars';
365
398
  }
366
399
  try {
367
- var ap = window.AlipayJSBridge;
368
- var content = formatMessage.apply(void 0, __spreadArray([type, msg], __read(args), false));
369
- ap === null || ap === void 0 ? void 0 : ap.call('H5APLog', {
370
- content: content,
371
- });
372
- }
373
- catch (e) {
374
- console.error(e);
375
- }
376
- }
377
- // Android H5 容器支持 console 日志直接写入 aplog
378
- function androidLogger(type, msg) {
379
- var args = [];
380
- for (var _i = 2; _i < arguments.length; _i++) {
381
- args[_i - 2] = arguments[_i];
382
- }
383
- try {
384
- var ap = window.AlipayJSBridge;
385
- ap === null || ap === void 0 ? void 0 : ap.call('localLog', {
386
- 'anr_info': 'mars',
387
- 'message': msg + args.join(''),
388
- 'level': type,
389
- });
400
+ ap === null || ap === void 0 ? void 0 : ap.call('localLog', content);
390
401
  }
391
402
  catch (e) {
392
403
  console.error(e);
393
404
  }
394
405
  }
395
- function formatMessage(level, msg) {
396
- var args = [];
397
- for (var _i = 2; _i < arguments.length; _i++) {
398
- args[_i - 2] = arguments[_i];
399
- }
400
- var result = [
401
- '<MARS_PLAYER>',
402
- "(".concat(level, "):"),
403
- msg,
404
- ];
405
- args.forEach(function (i) {
406
- result.push(i + '');
407
- });
408
- return result.join(' ');
409
- }
410
406
 
411
407
  var registered = false;
412
408
  /**
@@ -480,13 +476,15 @@ function resumePausedPlayers(e) {
480
476
  });
481
477
  }
482
478
  }
483
- var version = "1.5.0-alpha.0";
479
+ var version = "1.5.0";
484
480
  effects.logger.info('plugin alipay downgrade version: ' + version);
485
481
 
486
482
  exports.checkDowngrade = checkDowngrade;
483
+ exports.downgradeForMiniprogram = downgradeForMiniprogram;
487
484
  exports.getAlipayDowngradeBizId = getAlipayDowngradeBizId;
488
485
  exports.getDeviceName = getDeviceName;
489
486
  exports.getRenderLevelByDevice = getRenderLevelByDevice;
487
+ exports.getSystemInfo = getSystemInfo;
490
488
  exports.resetDevicePending = resetDevicePending;
491
489
  exports.setAlipayDowngradeBizId = setAlipayDowngradeBizId;
492
490
  exports.version = version;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}