@wovoon/polaris 0.4.2 → 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.
Files changed (2) hide show
  1. package/dist/client.js +8 -2
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -143,9 +143,15 @@ export class PolarisClient {
143
143
  emit("close", { error: "当前环境不支持 WebSocket" });
144
144
  return;
145
145
  }
146
- const origin = this.baseUrl || `${location.protocol}//${location.host}`;
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}`;
147
150
  const scheme = origin.startsWith("https") ? "wss" : "ws";
148
- socket = new WebSocket(`${scheme}://${origin.replace(/^https?:\/\//, "")}/api/cloud/rooms/${data.appId}/${encodeURIComponent(roomId)}`);
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}`);
149
155
  socket.onopen = () => { this.activeRooms.set(roomId, handle); };
150
156
  socket.onmessage = (event) => {
151
157
  let frame = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wovoon/polaris",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "wovoon Polaris SDK——wovoon 大后台云能力客户端(身份/数据集合/云函数/房间实时),协议 1",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",