@xmov/avatar 2.4.0-beta.1 → 2.4.0-beta.3
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/agent/avatar.cjs +1 -1
- package/dist/agent/avatar.modern.js +1 -1
- package/dist/agent/avatar.module.js +1 -1
- package/dist/agent/avatar.umd.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/modules/ResourceManager.d.ts +3 -1
- package/dist/utils/request.d.ts +1 -0
- package/package.json +1 -1
- package/src/index.ts +19 -13
- package/src/modules/ResourceManager.ts +2 -2
- package/src/utils/request.ts +3 -1
|
@@ -237,7 +237,9 @@ export default class ResourceManager {
|
|
|
237
237
|
load(onDownloadProgress?: TDownloadProgress): Promise<ISessionResponse | null>;
|
|
238
238
|
startSession(): Promise<any>;
|
|
239
239
|
_startSession(): Promise<any> | null;
|
|
240
|
-
stopSession(stop_reason: string
|
|
240
|
+
stopSession(stop_reason: string, options?: {
|
|
241
|
+
keepalive?: boolean;
|
|
242
|
+
}): Promise<any>;
|
|
241
243
|
/**
|
|
242
244
|
* 加载表情数据
|
|
243
245
|
*/
|
package/dist/utils/request.d.ts
CHANGED
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -43,6 +43,7 @@ export default class XmovAvatar {
|
|
|
43
43
|
|
|
44
44
|
// 使用 ! 操作符告诉 TypeScript 这些属性会在构造函数中被初始化
|
|
45
45
|
private resourceManager!: ResourceManager;
|
|
46
|
+
private beforeUnloadStopSessionPromise: ReturnType<ResourceManager["stopSession"]> | null = null;
|
|
46
47
|
private renderScheduler!: RenderScheduler;
|
|
47
48
|
private networkMonitor: NetworkMonitor | null = null;
|
|
48
49
|
private ttsa: Ttsa | null = null;
|
|
@@ -1315,7 +1316,11 @@ export default class XmovAvatar {
|
|
|
1315
1316
|
}
|
|
1316
1317
|
|
|
1317
1318
|
private handleBeforeUnload = () => {
|
|
1318
|
-
this.
|
|
1319
|
+
if (!this._isClientMode && (this.resourceManager?.session_id || this.resourceManager?.session_request_id)) {
|
|
1320
|
+
// Page dismissal cannot wait for E2E and TTSA shutdown before starting DELETE.
|
|
1321
|
+
this.beforeUnloadStopSessionPromise ??= this.resourceManager.stopSession("beforeunload", { keepalive: true });
|
|
1322
|
+
}
|
|
1323
|
+
void this.destroy("beforeunload");
|
|
1319
1324
|
};
|
|
1320
1325
|
|
|
1321
1326
|
public isDestroyed() {
|
|
@@ -1459,7 +1464,7 @@ export default class XmovAvatar {
|
|
|
1459
1464
|
this.ttsa?.sendSdkPoint('close_session', {
|
|
1460
1465
|
reason: stop_reason,
|
|
1461
1466
|
});
|
|
1462
|
-
const res = await this.resourceManager.stopSession(stop_reason);
|
|
1467
|
+
const res = await (this.beforeUnloadStopSessionPromise ?? this.resourceManager.stopSession(stop_reason));
|
|
1463
1468
|
await this.destroyClient();
|
|
1464
1469
|
if(res) {
|
|
1465
1470
|
this.onStatusChange(AvatarStatus.close);
|
|
@@ -1472,22 +1477,23 @@ export default class XmovAvatar {
|
|
|
1472
1477
|
try {
|
|
1473
1478
|
if (this._isClientMode) {
|
|
1474
1479
|
this._apiForwarder?.destroy(stopReason);
|
|
1475
|
-
} else if (!this.ttsa?.hasConnected) {
|
|
1476
|
-
// Initialization can own a session/request before TTSA first connects.
|
|
1477
|
-
// Mark an in-flight connection as quitting before waiting for DELETE.
|
|
1478
|
-
await this.ttsa?.quit(stopReason);
|
|
1479
|
-
await this.resourceManager.stopSession(stopReason);
|
|
1480
1480
|
} else {
|
|
1481
|
-
this.ttsa
|
|
1482
|
-
reason: stopReason
|
|
1483
|
-
}
|
|
1484
|
-
await this.ttsa
|
|
1481
|
+
if (this.ttsa?.hasConnected) {
|
|
1482
|
+
this.ttsa.sendSdkPoint('close_session', { reason: stopReason });
|
|
1483
|
+
}
|
|
1484
|
+
await this.ttsa?.quit(stopReason);
|
|
1485
1485
|
}
|
|
1486
1486
|
} catch (error) {
|
|
1487
1487
|
(window as any).avatarSDKLogger.warn(this.TAG, "TTSA client_quit 未确认,继续释放本地资源", error);
|
|
1488
1488
|
} finally {
|
|
1489
|
-
|
|
1490
|
-
|
|
1489
|
+
try {
|
|
1490
|
+
if (!this._isClientMode) {
|
|
1491
|
+
await (this.beforeUnloadStopSessionPromise ?? this.resourceManager.stopSession(stopReason));
|
|
1492
|
+
}
|
|
1493
|
+
} finally {
|
|
1494
|
+
await this.destroyClient();
|
|
1495
|
+
this.onStatusChange(AvatarStatus.close);
|
|
1496
|
+
}
|
|
1491
1497
|
}
|
|
1492
1498
|
}
|
|
1493
1499
|
|
|
@@ -406,7 +406,7 @@ export default class ResourceManager {
|
|
|
406
406
|
});
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
-
async stopSession(stop_reason: string) {
|
|
409
|
+
async stopSession(stop_reason: string, options: { keepalive?: boolean } = {}) {
|
|
410
410
|
try {
|
|
411
411
|
const url = `${this.options.gatewayServer}`;
|
|
412
412
|
// session_id 尚未返回时(如 init 未完成就 destroy),只要有 request_id 仍发请求,
|
|
@@ -424,7 +424,7 @@ export default class ResourceManager {
|
|
|
424
424
|
data.request_id = this.session_request_id;
|
|
425
425
|
}
|
|
426
426
|
const { headers, data: signedData } = headersNeedSign(this.options.appId, this.options.appSecret, "DELETE", url, data);
|
|
427
|
-
const response = await request(url, { method: "DELETE", data: signedData, headers: { ...headers, ...this.options.headers } });
|
|
427
|
+
const response = await request(url, { method: "DELETE", data: signedData, headers: { ...headers, ...this.options.headers }, keepalive: options.keepalive });
|
|
428
428
|
return await response.json();
|
|
429
429
|
} catch (error) {
|
|
430
430
|
this.sdk.onMessage({
|
package/src/utils/request.ts
CHANGED
|
@@ -4,6 +4,7 @@ interface RequestOptions {
|
|
|
4
4
|
method?: HttpMethod
|
|
5
5
|
data?: Record<string, any>
|
|
6
6
|
headers?: Record<string, string>
|
|
7
|
+
keepalive?: boolean
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
interface ErrorResponse {
|
|
@@ -21,6 +22,7 @@ export default async function request(
|
|
|
21
22
|
|
|
22
23
|
const config: RequestInit = {
|
|
23
24
|
method,
|
|
25
|
+
keepalive: options.keepalive,
|
|
24
26
|
// headers,
|
|
25
27
|
headers: {
|
|
26
28
|
'Content-Type': 'application/json',
|
|
@@ -104,4 +106,4 @@ export function XMLRequest(options: {
|
|
|
104
106
|
};
|
|
105
107
|
xhr.send();
|
|
106
108
|
});
|
|
107
|
-
}
|
|
109
|
+
}
|