@wovoon/polaris 0.6.2 → 0.6.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 +14 -2
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -49,7 +49,7 @@ export class PolarisClient {
|
|
|
49
49
|
return fetch(this.baseUrl + path, {
|
|
50
50
|
method,
|
|
51
51
|
credentials: "include",
|
|
52
|
-
headers: body === undefined ?
|
|
52
|
+
headers: { ...(body === undefined ? {} : { "Content-Type": "application/json" }), ...(localPlayer() ? { "X-Wovoon-Dev-Player": localPlayer() } : {}) },
|
|
53
53
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
54
54
|
}).then(async (response) => {
|
|
55
55
|
const payload = await response.json().catch(() => null);
|
|
@@ -177,6 +177,8 @@ export class PolarisClient {
|
|
|
177
177
|
const roomPath = `/api/cloud/rooms/${data.appId}/${encodeURIComponent(roomId)}`;
|
|
178
178
|
const sid = /[?&#]wovoon_play_sid=([0-9a-fA-F-]{36})(?:&|$)/.exec(String(typeof location === "undefined" ? "" : location.hash ?? ""))?.[1];
|
|
179
179
|
const query = [];
|
|
180
|
+
if (localPlayer())
|
|
181
|
+
query.push(`wovoon_player=${encodeURIComponent(localPlayer())}`);
|
|
180
182
|
if (sid)
|
|
181
183
|
query.push(`wovoon_play_sid=${sid}`);
|
|
182
184
|
if (options?.mode)
|
|
@@ -314,7 +316,12 @@ function attachCollectionsWatch(client) {
|
|
|
314
316
|
const origin = client.webSocketOrigin();
|
|
315
317
|
const scheme = origin.startsWith("https") ? "wss" : "ws";
|
|
316
318
|
const sid = /[?&#]wovoon_play_sid=([0-9a-fA-F-]{36})(?:&|$)/.exec(String(typeof location === "undefined" ? "" : location.hash ?? ""))?.[1];
|
|
317
|
-
const
|
|
319
|
+
const params = new URLSearchParams();
|
|
320
|
+
if (sid)
|
|
321
|
+
params.set("wovoon_play_sid", sid);
|
|
322
|
+
if (localPlayer())
|
|
323
|
+
params.set("wovoon_player", localPlayer());
|
|
324
|
+
const query = params.size ? `?${params}` : "";
|
|
318
325
|
const socket = new WebSocket(`${scheme}://${origin.replace(/^https?:\/\//, "")}/api/cloud/rooms/${data.appId}/__collections${query}`);
|
|
319
326
|
collectionsWatch.socket = socket;
|
|
320
327
|
socket.onmessage = (event) => {
|
|
@@ -364,3 +371,8 @@ function watchCollections(client, collection, cb) {
|
|
|
364
371
|
};
|
|
365
372
|
}
|
|
366
373
|
export { parseData };
|
|
374
|
+
function localPlayer() {
|
|
375
|
+
if (typeof location === "undefined" || !/^(localhost|127\.0\.0\.1)$/.test(location.hostname))
|
|
376
|
+
return "";
|
|
377
|
+
return new URLSearchParams(location.search).get("wovoon_player") || "";
|
|
378
|
+
}
|