@galacean/effects-plugin-alipay-downgrade 2.0.0-alpha.0 → 2.0.0-alpha.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 +0 -1
- package/dist/index.d.ts +0 -27
- package/dist/index.js +266 -234
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.mjs +267 -232
- package/dist/index.mjs.map +1 -1
- package/dist/utils.d.ts +39 -14
- package/package.json +2 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Player, SceneLoadOptions, spec } from '@galacean/effects';
|
|
2
2
|
import { AbstractPlugin } from '@galacean/effects';
|
|
3
3
|
export declare class AlipayDowngradePlugin extends AbstractPlugin {
|
|
4
|
-
static currentBizId: string;
|
|
5
4
|
static glLostOccurred: boolean;
|
|
6
5
|
static onPlayerCreated(player: Player): Promise<void>;
|
|
7
6
|
static processRawJSON(json: spec.JSONScene, options?: SceneLoadOptions): Promise<undefined>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,3 @@
|
|
|
1
1
|
export * from './utils';
|
|
2
2
|
export * from './native-log';
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
export interface AlipayDowngradeOptions {
|
|
7
|
-
/**
|
|
8
|
-
* 发生 gl lost 时,是否忽略
|
|
9
|
-
* @default false - 不忽略,将不再允许任何播放器创建,会全部走降级逻辑
|
|
10
|
-
*/
|
|
11
|
-
ignoreGLLost?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* 禁用压后台的时候自动暂停播放器
|
|
14
|
-
* @default false
|
|
15
|
-
*/
|
|
16
|
-
autoPause?: boolean;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 支付宝端内统一降级方案,传入降级 ID,每次加载场景前都会自动调用降级
|
|
20
|
-
* - 如果要为某个 json 单独配置降级 ID,可以使用 `player.loadScene(url, { pluginData: { alipayBizId: '#bizId#' }})`
|
|
21
|
-
* @param bizId - 降级 ID,如果为 `mock-pass` 将 mock 不降级场景,如果为 `mock-fail` 将 mock 降级场景,业务请不要使用这两个字符串
|
|
22
|
-
* @param options - 优化策略
|
|
23
|
-
*/
|
|
24
|
-
export declare function setAlipayDowngradeBizId(bizId: string, options?: AlipayDowngradeOptions): void;
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
* @returns
|
|
28
|
-
*/
|
|
29
|
-
export declare function getAlipayDowngradeBizId(): string;
|
|
30
3
|
export declare const version: string;
|
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: v2.0.0-alpha.
|
|
6
|
+
* Version: v2.0.0-alpha.1
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -113,86 +113,37 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
113
113
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
var devicePerformance;
|
|
121
|
-
var deviceName = 'DESKTOP_DEBUG';
|
|
122
|
-
var isIOS = false;
|
|
123
|
-
function getDeviceName() {
|
|
124
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
-
return __generator(this, function (_a) {
|
|
126
|
-
if (!devicePending) {
|
|
127
|
-
devicePending = getSystemInfo().then(function (info) {
|
|
128
|
-
var performance = info.performance, platform = info.platform, _a = info.model, model = _a === void 0 ? 'UNKNOWN_DEVICE' : _a;
|
|
129
|
-
if (!devicePerformance) {
|
|
130
|
-
devicePerformance = performance;
|
|
131
|
-
}
|
|
132
|
-
isIOS = platform === 'iOS';
|
|
133
|
-
deviceName = model;
|
|
134
|
-
if (/iPhone(\d+),/.test(deviceName) && !devicePerformance) {
|
|
135
|
-
var gen = +RegExp.$1;
|
|
136
|
-
// https://gist.github.com/adamawolf/3048717 device code
|
|
137
|
-
if (gen <= 9) { // iphone 7,iphone 7p
|
|
138
|
-
devicePerformance = DEVICE_PERFORMANCE_LOW;
|
|
139
|
-
}
|
|
140
|
-
else if (gen < 10) {
|
|
141
|
-
devicePerformance = DEVICE_PERFORMANCE_MIDDLE;
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
devicePerformance = DEVICE_PERFORMANCE_HIGH;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (deviceName.indexOf(info.brand) === 0) {
|
|
148
|
-
deviceName = deviceName.replace(info.brand, '').trim();
|
|
149
|
-
}
|
|
150
|
-
return deviceName;
|
|
151
|
-
}, function (e) {
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
return [2 /*return*/, devicePending.then(function () { return deviceName; }, function () { return deviceName; })];
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
function getRenderLevelByDevice(renderLevel) {
|
|
159
|
-
if (renderLevel === 'auto' || !renderLevel) {
|
|
160
|
-
if (devicePerformance === DEVICE_PERFORMANCE_HIGH) {
|
|
161
|
-
return effects.spec.RenderLevel.S;
|
|
162
|
-
}
|
|
163
|
-
else if (devicePerformance === DEVICE_PERFORMANCE_MIDDLE) {
|
|
164
|
-
return effects.spec.RenderLevel.A;
|
|
165
|
-
}
|
|
166
|
-
else if (devicePerformance === DEVICE_PERFORMANCE_LOW) {
|
|
167
|
-
return effects.spec.RenderLevel.B;
|
|
168
|
-
}
|
|
169
|
-
return isIOS ? effects.spec.RenderLevel.S : effects.spec.RenderLevel.B;
|
|
116
|
+
var DowngradeVFXItem = /** @class */ (function (_super) {
|
|
117
|
+
__extends(DowngradeVFXItem, _super);
|
|
118
|
+
function DowngradeVFXItem() {
|
|
119
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
170
120
|
}
|
|
171
|
-
return
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
devicePending = undefined;
|
|
175
|
-
}
|
|
121
|
+
return DowngradeVFXItem;
|
|
122
|
+
}(effects.VFXItem));
|
|
123
|
+
|
|
176
124
|
var mockIdPass = 'mock-pass';
|
|
177
125
|
var mockIdFail = 'mock-fail';
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
function checkDowngrade(bizId, options) {
|
|
126
|
+
var DEVICE_LEVEL_HIGH = 'high';
|
|
127
|
+
var DEVICE_LEVEL_MEDIUM = 'medium';
|
|
128
|
+
var DEVICE_LEVEL_LOW = 'low';
|
|
129
|
+
var DEVICE_LEVEL_NONE = 'none';
|
|
130
|
+
var hasRegisterEvent = false;
|
|
131
|
+
function getDowngradeResult(bizId, options) {
|
|
185
132
|
if (options === void 0) { options = {}; }
|
|
186
133
|
return __awaiter(this, void 0, void 0, function () {
|
|
187
134
|
var ap, now_1;
|
|
188
135
|
return __generator(this, function (_a) {
|
|
136
|
+
if (!hasRegisterEvent) {
|
|
137
|
+
registerEvent(options);
|
|
138
|
+
hasRegisterEvent = true;
|
|
139
|
+
}
|
|
189
140
|
if (bizId === mockIdFail || bizId === mockIdPass) {
|
|
190
|
-
return [2 /*return*/, Promise.resolve({ downgrade: bizId === mockIdFail
|
|
141
|
+
return [2 /*return*/, Promise.resolve({ mock: { downgrade: bizId === mockIdFail } })];
|
|
191
142
|
}
|
|
192
143
|
ap = window.AlipayJSBridge;
|
|
193
144
|
if (ap) {
|
|
194
145
|
now_1 = performance.now();
|
|
195
|
-
return [2 /*return*/,
|
|
146
|
+
return [2 /*return*/, getSystemInfo().then(function (systemInfo) {
|
|
196
147
|
return new Promise(function (resolve) {
|
|
197
148
|
var _a;
|
|
198
149
|
var techPoint = ['mars'];
|
|
@@ -200,60 +151,51 @@ function checkDowngrade(bizId, options) {
|
|
|
200
151
|
if (tc) {
|
|
201
152
|
techPoint.push.apply(techPoint, __spreadArray([], __read(tc), false));
|
|
202
153
|
}
|
|
203
|
-
var
|
|
204
|
-
callBridge('getDowngradeResult', {
|
|
154
|
+
var downgradeOptions = {
|
|
205
155
|
bizId: bizId,
|
|
206
156
|
scene: 0,
|
|
207
157
|
ext: {
|
|
208
158
|
techPoint: techPoint,
|
|
209
159
|
},
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
else if ('resultType' in ret) {
|
|
220
|
-
reason = ret.resultType;
|
|
221
|
-
}
|
|
222
|
-
if (result.context) {
|
|
223
|
-
var deviceInfo = result.context.deviceInfo;
|
|
224
|
-
if (deviceInfo) {
|
|
225
|
-
var level = deviceInfo.deviceLevel;
|
|
226
|
-
if (level === DEVICE_PERFORMANCE_HIGH || level === DEVICE_PERFORMANCE_LOW) {
|
|
227
|
-
devicePerformance = level;
|
|
228
|
-
}
|
|
229
|
-
else if (level === 'medium') {
|
|
230
|
-
devicePerformance = DEVICE_PERFORMANCE_MIDDLE;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
catch (ex) {
|
|
236
|
-
console.error(ex);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
// 无权调用的情况下不降级
|
|
241
|
-
resolve({ downgrade: result.error !== 4, reason: 'api error:' + result.error });
|
|
242
|
-
}
|
|
243
|
-
if (reason === undefined) {
|
|
244
|
-
resolve({ downgrade: true, reason: 'call downgrade fail' });
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
resolve({ reason: reason, downgrade: reason === 1 });
|
|
248
|
-
}
|
|
249
|
-
});
|
|
160
|
+
};
|
|
161
|
+
var downgradeCallback = function (result) {
|
|
162
|
+
var totalTime = performance.now() - now_1;
|
|
163
|
+
console.info("downgrade time: ".concat(totalTime, "ms"));
|
|
164
|
+
resolve({ bizId: bizId, systemInfo: systemInfo, downgradeResult: result, totalTime: totalTime });
|
|
165
|
+
};
|
|
166
|
+
var callBridge = (_a = options.callBridge) !== null && _a !== void 0 ? _a : ap.call;
|
|
167
|
+
callBridge('getDowngradeResult', downgradeOptions, downgradeCallback);
|
|
250
168
|
});
|
|
251
169
|
})];
|
|
252
170
|
}
|
|
253
|
-
|
|
171
|
+
else {
|
|
172
|
+
return [2 /*return*/, Promise.resolve({ noAlipayEnv: true })];
|
|
173
|
+
}
|
|
254
174
|
});
|
|
255
175
|
});
|
|
256
176
|
}
|
|
177
|
+
function registerEvent(options) {
|
|
178
|
+
var ignoreGLLost = options.ignoreGLLost, autoPause = options.autoPause;
|
|
179
|
+
var downgradeWhenGLLost = ignoreGLLost !== true;
|
|
180
|
+
window.addEventListener('unload', function () {
|
|
181
|
+
effects.getActivePlayers().forEach(function (player) { return player.dispose(); });
|
|
182
|
+
});
|
|
183
|
+
window.addEventListener('webglcontextlost', function (e) {
|
|
184
|
+
if (effects.isCanvasUsedByPlayer(e.target)) {
|
|
185
|
+
AlipayDowngradePlugin.glLostOccurred = true;
|
|
186
|
+
console.error('webgl lost occur');
|
|
187
|
+
if (downgradeWhenGLLost) {
|
|
188
|
+
console.warn('webgl lost occur, all players will be downgraded from now on');
|
|
189
|
+
effects.disableAllPlayer(true);
|
|
190
|
+
effects.getActivePlayers().forEach(function (player) { return player.dispose(); });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}, true);
|
|
194
|
+
if (autoPause) {
|
|
195
|
+
document.addEventListener('pause', pauseAllActivePlayers);
|
|
196
|
+
document.addEventListener('resume', resumePausedPlayers);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
257
199
|
function getSystemInfo() {
|
|
258
200
|
return __awaiter(this, void 0, void 0, function () {
|
|
259
201
|
return __generator(this, function (_a) {
|
|
@@ -276,6 +218,191 @@ function getSystemInfo() {
|
|
|
276
218
|
});
|
|
277
219
|
});
|
|
278
220
|
}
|
|
221
|
+
var DeviceProxy = /** @class */ (function () {
|
|
222
|
+
function DeviceProxy() {
|
|
223
|
+
this.isIOS = false;
|
|
224
|
+
this.model = 'DESKTOP_DEBUG';
|
|
225
|
+
this.deviceLevel = DEVICE_LEVEL_NONE;
|
|
226
|
+
this.isDowngrade = false;
|
|
227
|
+
}
|
|
228
|
+
DeviceProxy.prototype.getRenderLevel = function () {
|
|
229
|
+
if (this.deviceLevel === DEVICE_LEVEL_HIGH) {
|
|
230
|
+
return effects.spec.RenderLevel.S;
|
|
231
|
+
}
|
|
232
|
+
else if (this.deviceLevel === DEVICE_LEVEL_MEDIUM) {
|
|
233
|
+
return effects.spec.RenderLevel.A;
|
|
234
|
+
}
|
|
235
|
+
else if (this.deviceLevel === DEVICE_LEVEL_LOW) {
|
|
236
|
+
return effects.spec.RenderLevel.B;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
return this.isIOS ? effects.spec.RenderLevel.S : effects.spec.RenderLevel.B;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
DeviceProxy.prototype.hasDeviceLevel = function () {
|
|
243
|
+
return isDeviceLevel(this.deviceLevel);
|
|
244
|
+
};
|
|
245
|
+
DeviceProxy.prototype.setBySystemInfo = function (systemInfo) {
|
|
246
|
+
var performance = systemInfo.performance, platform = systemInfo.platform, _a = systemInfo.model, model = _a === void 0 ? 'UNKNOWN_DEVICE' : _a;
|
|
247
|
+
this.isIOS = platform === 'iOS';
|
|
248
|
+
this.model = model;
|
|
249
|
+
if (performance && !this.hasDeviceLevel()) {
|
|
250
|
+
this.deviceLevel = performance;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
DeviceProxy.prototype.updateDeviceLevel = function () {
|
|
254
|
+
if (this.hasDeviceLevel()) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (/iPhone(\d+),/.test(this.model)) {
|
|
258
|
+
var gen = +RegExp.$1;
|
|
259
|
+
if (gen <= 9) {
|
|
260
|
+
this.deviceLevel = DEVICE_LEVEL_LOW;
|
|
261
|
+
}
|
|
262
|
+
else if (gen < 10) {
|
|
263
|
+
this.deviceLevel = DEVICE_LEVEL_MEDIUM;
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
this.deviceLevel = DEVICE_LEVEL_HIGH;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
DeviceProxy.prototype.getDeviceInfo = function () {
|
|
271
|
+
return {
|
|
272
|
+
isIOS: this.isIOS,
|
|
273
|
+
model: this.model,
|
|
274
|
+
deviceLevel: this.deviceLevel,
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
return DeviceProxy;
|
|
278
|
+
}());
|
|
279
|
+
var device = new DeviceProxy();
|
|
280
|
+
function checkDowngradeResult(result) {
|
|
281
|
+
if (result.mock) {
|
|
282
|
+
var _a = result.mock, downgrade = _a.downgrade, _b = _a.deviceLevel, deviceLevel = _b === void 0 ? DEVICE_LEVEL_HIGH : _b;
|
|
283
|
+
device.deviceLevel = deviceLevel;
|
|
284
|
+
return { downgrade: downgrade, reason: 'mock' };
|
|
285
|
+
}
|
|
286
|
+
if (result.noAlipayEnv) {
|
|
287
|
+
return { downgrade: false, reason: 'no AP env' };
|
|
288
|
+
}
|
|
289
|
+
if (!result.systemInfo) {
|
|
290
|
+
return { downgrade: false, reason: 'systemInfo is required' };
|
|
291
|
+
}
|
|
292
|
+
if (!result.downgradeResult) {
|
|
293
|
+
return { downgrade: false, reason: 'downgradeResult is required' };
|
|
294
|
+
}
|
|
295
|
+
device.setBySystemInfo(result.systemInfo);
|
|
296
|
+
return parseDowngradeResult(result.downgradeResult);
|
|
297
|
+
}
|
|
298
|
+
function parseDowngradeResult(result) {
|
|
299
|
+
var resultType = undefined;
|
|
300
|
+
var resultReason = undefined;
|
|
301
|
+
if (!result.error) {
|
|
302
|
+
try {
|
|
303
|
+
var ret = effects.isString(result) ? JSON.parse(result) : result;
|
|
304
|
+
if ('downgradeResultType' in ret) {
|
|
305
|
+
resultType = ret.downgradeResultType;
|
|
306
|
+
}
|
|
307
|
+
else if ('resultType' in ret) {
|
|
308
|
+
resultType = ret.resultType;
|
|
309
|
+
resultReason = ret.resultReason;
|
|
310
|
+
}
|
|
311
|
+
if (result.context) {
|
|
312
|
+
var deviceInfo = result.context.deviceInfo;
|
|
313
|
+
if (deviceInfo) {
|
|
314
|
+
var deviceLevel = deviceInfo.deviceLevel;
|
|
315
|
+
if (isDeviceLevel(deviceLevel)) {
|
|
316
|
+
device.deviceLevel = deviceLevel;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
device.updateDeviceLevel();
|
|
321
|
+
}
|
|
322
|
+
catch (ex) {
|
|
323
|
+
console.error(ex);
|
|
324
|
+
}
|
|
325
|
+
if (resultType === undefined) {
|
|
326
|
+
return { downgrade: true, reason: 'call downgrade fail' };
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
if (resultType === 1) {
|
|
330
|
+
return { downgrade: true, reason: getDowngradeReason(resultReason) };
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
return { downgrade: false, reason: resultType };
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
// 无权调用的情况下不降级
|
|
339
|
+
return { downgrade: result.error !== 4, reason: 'api error: ' + result.error };
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function getDowngradeReason(reason) {
|
|
343
|
+
if (reason === -1) {
|
|
344
|
+
return "".concat(reason, "-no config");
|
|
345
|
+
}
|
|
346
|
+
else if (reason === 0) {
|
|
347
|
+
return "".concat(reason, "-none");
|
|
348
|
+
}
|
|
349
|
+
else if (reason === 1) {
|
|
350
|
+
return "".concat(reason, "-downgrade by memory");
|
|
351
|
+
}
|
|
352
|
+
else if (reason === 2) {
|
|
353
|
+
return "".concat(reason, "-downgrade by crash");
|
|
354
|
+
}
|
|
355
|
+
else if (reason === 3) {
|
|
356
|
+
return "".concat(reason, "-downgrade by device");
|
|
357
|
+
}
|
|
358
|
+
else if (reason === 4) {
|
|
359
|
+
return "".concat(reason, "-downgrade by force");
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
return "".concat(reason);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function getRenderLevelByDevice(renderLevel) {
|
|
366
|
+
if (!renderLevel) {
|
|
367
|
+
return device.getRenderLevel();
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
return /[ABS]/.test(renderLevel) ? renderLevel : effects.spec.RenderLevel.S;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function isDeviceLevel(deviceLevel) {
|
|
374
|
+
return deviceLevel === DEVICE_LEVEL_HIGH
|
|
375
|
+
|| deviceLevel === DEVICE_LEVEL_MEDIUM
|
|
376
|
+
|| deviceLevel === DEVICE_LEVEL_LOW;
|
|
377
|
+
}
|
|
378
|
+
var internalPaused = Symbol('@@_inter_pause');
|
|
379
|
+
function pauseAllActivePlayers(e) {
|
|
380
|
+
if (e.target === document) {
|
|
381
|
+
effects.logger.info('Auto pause all players with data offloaded');
|
|
382
|
+
var players = effects.getActivePlayers();
|
|
383
|
+
players.forEach(function (player) {
|
|
384
|
+
if (!player.paused) {
|
|
385
|
+
player.pause({ offloadTexture: true });
|
|
386
|
+
// @ts-expect-error
|
|
387
|
+
player[internalPaused] = true;
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
function resumePausedPlayers(e) {
|
|
393
|
+
if (e.target === document) {
|
|
394
|
+
effects.logger.info('auto resume all players');
|
|
395
|
+
var players = effects.getActivePlayers();
|
|
396
|
+
players.forEach(function (player) {
|
|
397
|
+
// @ts-expect-error
|
|
398
|
+
if (player[internalPaused]) {
|
|
399
|
+
void player.resume();
|
|
400
|
+
// @ts-expect-error
|
|
401
|
+
player[internalPaused] = false;
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
279
406
|
|
|
280
407
|
var AlipayDowngradePlugin = /** @class */ (function (_super) {
|
|
281
408
|
__extends(AlipayDowngradePlugin, _super);
|
|
@@ -284,66 +411,45 @@ var AlipayDowngradePlugin = /** @class */ (function (_super) {
|
|
|
284
411
|
}
|
|
285
412
|
AlipayDowngradePlugin.onPlayerCreated = function (player) {
|
|
286
413
|
return __awaiter(this, void 0, void 0, function () {
|
|
287
|
-
var result;
|
|
288
414
|
return __generator(this, function (_a) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
console.warn('gl lost happened, new player will be destroyed.');
|
|
293
|
-
return [2 /*return*/, player.dispose()];
|
|
294
|
-
}
|
|
295
|
-
if (!AlipayDowngradePlugin.currentBizId) return [3 /*break*/, 2];
|
|
296
|
-
return [4 /*yield*/, checkDowngrade(AlipayDowngradePlugin.currentBizId)];
|
|
297
|
-
case 1:
|
|
298
|
-
result = _a.sent();
|
|
299
|
-
if (result.downgrade) {
|
|
300
|
-
console.warn('automatically destroy downgraded player.');
|
|
301
|
-
player.dispose();
|
|
302
|
-
}
|
|
303
|
-
_a.label = 2;
|
|
304
|
-
case 2: return [2 /*return*/];
|
|
415
|
+
if (AlipayDowngradePlugin.glLostOccurred) {
|
|
416
|
+
console.warn('gl lost happened, new player will be destroyed.');
|
|
417
|
+
return [2 /*return*/, player.dispose()];
|
|
305
418
|
}
|
|
419
|
+
return [2 /*return*/];
|
|
306
420
|
});
|
|
307
421
|
});
|
|
308
422
|
};
|
|
309
423
|
AlipayDowngradePlugin.processRawJSON = function (json, options) {
|
|
310
|
-
var _a
|
|
424
|
+
var _a;
|
|
311
425
|
if (options === void 0) { options = {}; }
|
|
312
426
|
return __awaiter(this, void 0, void 0, function () {
|
|
313
|
-
var
|
|
314
|
-
return __generator(this, function (
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
throw new Error("downgraded, reason: ".concat(result.reason));
|
|
325
|
-
}
|
|
326
|
-
if (!options.renderLevel) {
|
|
327
|
-
options.renderLevel = getRenderLevelByDevice(options.renderLevel);
|
|
328
|
-
}
|
|
329
|
-
return [2 /*return*/];
|
|
427
|
+
var downgradeResult, downgradeDecision;
|
|
428
|
+
return __generator(this, function (_b) {
|
|
429
|
+
if (AlipayDowngradePlugin.glLostOccurred) {
|
|
430
|
+
return [2 /*return*/, Promise.reject('gl lost happened')];
|
|
431
|
+
}
|
|
432
|
+
downgradeResult = (_a = options.pluginData) === null || _a === void 0 ? void 0 : _a['downgrade'];
|
|
433
|
+
if (downgradeResult) {
|
|
434
|
+
downgradeDecision = checkDowngradeResult(downgradeResult);
|
|
435
|
+
if (downgradeDecision.downgrade) {
|
|
436
|
+
throw new Error("downgraded, reason: ".concat(downgradeDecision.reason));
|
|
437
|
+
}
|
|
330
438
|
}
|
|
439
|
+
else {
|
|
440
|
+
console.warn('No downgrade result in pluginData of SceneLoadOptions');
|
|
441
|
+
}
|
|
442
|
+
if (!options.renderLevel) {
|
|
443
|
+
options.renderLevel = getRenderLevelByDevice(options.renderLevel);
|
|
444
|
+
}
|
|
445
|
+
return [2 /*return*/];
|
|
331
446
|
});
|
|
332
447
|
});
|
|
333
448
|
};
|
|
334
|
-
AlipayDowngradePlugin.currentBizId = '';
|
|
335
449
|
AlipayDowngradePlugin.glLostOccurred = false;
|
|
336
450
|
return AlipayDowngradePlugin;
|
|
337
451
|
}(effects.AbstractPlugin));
|
|
338
452
|
|
|
339
|
-
var DowngradeVFXItem = /** @class */ (function (_super) {
|
|
340
|
-
__extends(DowngradeVFXItem, _super);
|
|
341
|
-
function DowngradeVFXItem() {
|
|
342
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
343
|
-
}
|
|
344
|
-
return DowngradeVFXItem;
|
|
345
|
-
}(effects.VFXItem));
|
|
346
|
-
|
|
347
453
|
var prefix = '[Galacean Effects]';
|
|
348
454
|
effects.logger.register(nativeLogger);
|
|
349
455
|
function nativeLogger(type, msg) {
|
|
@@ -408,86 +514,12 @@ function formatMessage(level, msg) {
|
|
|
408
514
|
return result.join(' ');
|
|
409
515
|
}
|
|
410
516
|
|
|
411
|
-
var
|
|
412
|
-
|
|
413
|
-
* 支付宝端内统一降级方案,传入降级 ID,每次加载场景前都会自动调用降级
|
|
414
|
-
* - 如果要为某个 json 单独配置降级 ID,可以使用 `player.loadScene(url, { pluginData: { alipayBizId: '#bizId#' }})`
|
|
415
|
-
* @param bizId - 降级 ID,如果为 `mock-pass` 将 mock 不降级场景,如果为 `mock-fail` 将 mock 降级场景,业务请不要使用这两个字符串
|
|
416
|
-
* @param options - 优化策略
|
|
417
|
-
*/
|
|
418
|
-
function setAlipayDowngradeBizId(bizId, options) {
|
|
419
|
-
if (options === void 0) { options = {}; }
|
|
420
|
-
var ignoreGLLost = options.ignoreGLLost, autoPause = options.autoPause;
|
|
421
|
-
var downgradeWhenGLLost = ignoreGLLost !== true;
|
|
422
|
-
AlipayDowngradePlugin.currentBizId = bizId;
|
|
423
|
-
if (registered) {
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
effects.registerPlugin('alipay-downgrade', AlipayDowngradePlugin, DowngradeVFXItem, true);
|
|
427
|
-
window.addEventListener('unload', function () {
|
|
428
|
-
effects.getActivePlayers().forEach(function (player) { return player.dispose(); });
|
|
429
|
-
});
|
|
430
|
-
window.addEventListener('webglcontextlost', function (e) {
|
|
431
|
-
if (effects.isCanvasUsedByPlayer(e.target)) {
|
|
432
|
-
AlipayDowngradePlugin.glLostOccurred = true;
|
|
433
|
-
console.error('webgl lost occur');
|
|
434
|
-
if (downgradeWhenGLLost) {
|
|
435
|
-
console.warn('webgl lost occur, all players will be downgraded from now on');
|
|
436
|
-
effects.disableAllPlayer(true);
|
|
437
|
-
effects.getActivePlayers().forEach(function (player) { return player.dispose(); });
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}, true);
|
|
441
|
-
if (autoPause) {
|
|
442
|
-
document.addEventListener('pause', pauseAllActivePlayers);
|
|
443
|
-
document.addEventListener('resume', resumePausedPlayers);
|
|
444
|
-
}
|
|
445
|
-
registered = true;
|
|
446
|
-
void getDeviceName();
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
*
|
|
450
|
-
* @returns
|
|
451
|
-
*/
|
|
452
|
-
function getAlipayDowngradeBizId() {
|
|
453
|
-
return AlipayDowngradePlugin.currentBizId;
|
|
454
|
-
}
|
|
455
|
-
var internalPaused = Symbol('@@_inter_pause');
|
|
456
|
-
function pauseAllActivePlayers(e) {
|
|
457
|
-
if (e.target === document) {
|
|
458
|
-
effects.logger.info('Auto pause all players with data offloaded');
|
|
459
|
-
var players = effects.getActivePlayers();
|
|
460
|
-
players.forEach(function (player) {
|
|
461
|
-
if (!player.paused) {
|
|
462
|
-
player.pause({ offloadTexture: true });
|
|
463
|
-
// @ts-expect-error
|
|
464
|
-
player[internalPaused] = true;
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
function resumePausedPlayers(e) {
|
|
470
|
-
if (e.target === document) {
|
|
471
|
-
effects.logger.info('auto resume all players');
|
|
472
|
-
var players = effects.getActivePlayers();
|
|
473
|
-
players.forEach(function (player) {
|
|
474
|
-
// @ts-expect-error
|
|
475
|
-
if (player[internalPaused]) {
|
|
476
|
-
void player.resume();
|
|
477
|
-
// @ts-expect-error
|
|
478
|
-
player[internalPaused] = false;
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
var version = "2.0.0-alpha.0";
|
|
517
|
+
var version = "2.0.0-alpha.1";
|
|
518
|
+
effects.registerPlugin('alipay-downgrade', AlipayDowngradePlugin, DowngradeVFXItem, true);
|
|
484
519
|
effects.logger.info('plugin alipay downgrade version: ' + version);
|
|
485
520
|
|
|
486
|
-
exports.
|
|
487
|
-
exports.
|
|
488
|
-
exports.getDeviceName = getDeviceName;
|
|
521
|
+
exports.checkDowngradeResult = checkDowngradeResult;
|
|
522
|
+
exports.getDowngradeResult = getDowngradeResult;
|
|
489
523
|
exports.getRenderLevelByDevice = getRenderLevelByDevice;
|
|
490
|
-
exports.resetDevicePending = resetDevicePending;
|
|
491
|
-
exports.setAlipayDowngradeBizId = setAlipayDowngradeBizId;
|
|
492
524
|
exports.version = version;
|
|
493
525
|
//# sourceMappingURL=index.js.map
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|