@wovoon/polaris 0.4.1 → 0.4.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/client.js +22 -2
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -49,6 +49,20 @@ export class PolarisClient {
|
|
|
49
49
|
detectTarget() {
|
|
50
50
|
if (this.target)
|
|
51
51
|
return this.target;
|
|
52
|
+
const UUID = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
|
|
53
|
+
if (typeof location !== "undefined") {
|
|
54
|
+
// 隔离运行域:主机名首标签 static[-vN]-{deploymentId}(生产拓扑 pathname 是 /,路径正则提取不到)。
|
|
55
|
+
const firstLabel = String(location.hostname || "").split(".")[0] ?? "";
|
|
56
|
+
if (/^static-/.test(firstLabel)) {
|
|
57
|
+
const hostMatch = new RegExp(`-(${UUID})$`, "i").exec(firstLabel);
|
|
58
|
+
if (hostMatch)
|
|
59
|
+
return hostMatch[1];
|
|
60
|
+
}
|
|
61
|
+
// 平台启动片段:run-session 对所有拓扑统一注入 wovoon_app_id。
|
|
62
|
+
const hashMatch = new RegExp(`[?&#]wovoon_app_id=(${UUID})(?:&|$)`, "i").exec(String(location.hash || ""));
|
|
63
|
+
if (hashMatch)
|
|
64
|
+
return hashMatch[1];
|
|
65
|
+
}
|
|
52
66
|
const match = /\/api\/public\/static\/([0-9a-fA-F-]{36})/.exec(typeof location === "undefined" ? "" : location.pathname);
|
|
53
67
|
return match ? match[1] : "";
|
|
54
68
|
}
|
|
@@ -129,9 +143,15 @@ export class PolarisClient {
|
|
|
129
143
|
emit("close", { error: "当前环境不支持 WebSocket" });
|
|
130
144
|
return;
|
|
131
145
|
}
|
|
132
|
-
|
|
146
|
+
// CDN 加速域不支持 WebSocket:优先用入口页注入的 __wovoonRuntimeWsBase(平台主站,直连源站),
|
|
147
|
+
// 并以启动片段的 wovoon_play_sid 作为跨主机凭证(与 play cookie 同一游玩会话)。
|
|
148
|
+
const wsBase = String(globalThis.__wovoonRuntimeWsBase ?? "").replace(/\/+$/, "");
|
|
149
|
+
const origin = this.baseUrl || wsBase || `${location.protocol}//${location.host}`;
|
|
133
150
|
const scheme = origin.startsWith("https") ? "wss" : "ws";
|
|
134
|
-
|
|
151
|
+
const roomPath = `/api/cloud/rooms/${data.appId}/${encodeURIComponent(roomId)}`;
|
|
152
|
+
const sid = /[?&#]wovoon_play_sid=([0-9a-fA-F-]{36})(?:&|$)/.exec(String(location.hash ?? ""))?.[1];
|
|
153
|
+
const query = sid ? `${roomPath.includes("?") ? "&" : "?"}wovoon_play_sid=${sid}` : "";
|
|
154
|
+
socket = new WebSocket(`${scheme}://${origin.replace(/^https?:\/\//, "")}${roomPath}${query}`);
|
|
135
155
|
socket.onopen = () => { this.activeRooms.set(roomId, handle); };
|
|
136
156
|
socket.onmessage = (event) => {
|
|
137
157
|
let frame = null;
|