Skip to content

Commit

Permalink
コード整理
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Jan 10, 2025
1 parent 1cbb8a9 commit 81401f7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions check_stereo/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ document.addEventListener("DOMContentLoaded", async () => {
channelIdSuffix,
secretKey,
);

const recvonly = new RecvonlyClient(
signalingUrl,
channelIdPrefix,
Expand Down
2 changes: 1 addition & 1 deletion recvonly/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ document.addEventListener("DOMContentLoaded", () => {
const signalingUrl = import.meta.env.VITE_SORA_SIGNALING_URL;
const channelIdPrefix = import.meta.env.VITE_SORA_CHANNEL_ID_PREFIX;
const channelIdSuffix = import.meta.env.VITE_SORA_CHANNEL_ID_SUFFIX;
const secretKey = import.meta.env.VITE_SORA_SECRET_KEY;
const secretKey = import.meta.env.VITE_SECRET_KEY;

// Sora クライアントの初期化
const client = new SoraClient(
Expand Down
2 changes: 1 addition & 1 deletion replace_track/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ document.addEventListener("DOMContentLoaded", async () => {
const signalingUrl = import.meta.env.VITE_SORA_SIGNALING_URL;
const channelIdPrefix = import.meta.env.VITE_SORA_CHANNEL_ID_PREFIX || "";
const channelIdSuffix = import.meta.env.VITE_SORA_CHANNEL_ID_SUFFIX || "";
const secretKey = import.meta.env.VITE_SORA_SECRET_KEY || "";
const secretKey = import.meta.env.VITE_SECRET_KEY || "";

const client = new SoraClient(
signalingUrl,
Expand Down
2 changes: 1 addition & 1 deletion sendonly/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ document.addEventListener("DOMContentLoaded", async () => {
const signalingUrl = import.meta.env.VITE_SORA_SIGNALING_URL;
const channelIdPrefix = import.meta.env.VITE_SORA_CHANNEL_ID_PREFIX || "";
const channelIdSuffix = import.meta.env.VITE_SORA_CHANNEL_ID_SUFFIX || "";
const secretKey = import.meta.env.VITE_SORA_SECRET_KEY || "";
const secretKey = import.meta.env.VITE_SECRET_KEY || "";

const client = new SoraClient(
signalingUrl,
Expand Down
2 changes: 1 addition & 1 deletion sendrecv/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ document.addEventListener("DOMContentLoaded", async () => {
const signalingUrl = import.meta.env.VITE_SORA_SIGNALING_URL;
const channelIdPrefix = import.meta.env.VITE_SORA_CHANNEL_ID_PREFIX || "";
const channelIdSuffix = import.meta.env.VITE_SORA_CHANNEL_ID_SUFFIX || "";
const secretKey = import.meta.env.VITE_SORA_SECRET_KEY || "";
const secretKey = import.meta.env.VITE_SECRET_KEY || "";

const client = new SoraClient(
signalingUrl,
Expand Down
23 changes: 13 additions & 10 deletions src/misc.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import jose from "jose";
import * as jose from "jose";

export const generateJwt = async (
channelId: string,
secretKey: string,
): Promise<string> => {
if (secretKey === "") {
return "";
}
const header = { alg: "HS256", typ: "JWT" };
const payload = {
// 30 秒後に有効期限切れ
exp: Math.floor(Date.now() / 1000) + 30,
channel_id: channelId,
};
return await new jose.SignJWT(payload)
.setProtectedHeader(header)
.setIssuedAt()
.sign(new TextEncoder().encode(secretKey));
return (
new jose.SignJWT({
channel_id: channelId,
})
.setProtectedHeader(header)
// 30 秒後に有効期限切れ
.setExpirationTime("30s")
.sign(new TextEncoder().encode(secretKey))
);
};

0 comments on commit 81401f7

Please sign in to comment.