Skip to content

Commit 0f86c66

Browse files
fix: 修复 crypto.randomUUID 的 https 需要
1 parent 442f639 commit 0f86c66

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • packages/remote-control-server/web

packages/remote-control-server/web/api.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@
44

55
const BASE = ""; // same origin
66

7+
function generateUuid() {
8+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
9+
return crypto.randomUUID();
10+
}
11+
// Fallback for non-secure contexts (HTTP without localhost)
12+
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) =>
13+
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16),
14+
);
15+
}
16+
717
export function getUuid() {
818
let uuid = localStorage.getItem("rcs_uuid");
919
if (!uuid) {
10-
uuid = crypto.randomUUID();
20+
uuid = generateUuid();
1121
localStorage.setItem("rcs_uuid", uuid);
1222
}
1323
return uuid;

0 commit comments

Comments
 (0)