diff --git a/check_stereo/main.ts b/check_stereo/main.ts index 8ec3f88..63b9122 100644 --- a/check_stereo/main.ts +++ b/check_stereo/main.ts @@ -98,7 +98,7 @@ class SendonlyClient { } async connect(stream: MediaStream): Promise { - if (this.secretKey !== "") { + if (this.secretKey) { const jwt = await generateJwt(this.channelId, this.secretKey); this.connection.metadata = { access_token: jwt, diff --git a/check_stereo_multi/main.ts b/check_stereo_multi/main.ts index e00888c..3cc1d73 100644 --- a/check_stereo_multi/main.ts +++ b/check_stereo_multi/main.ts @@ -126,7 +126,7 @@ class SendonlyClient { } async connect(stream: MediaStream): Promise { - if (this.secretKey !== "") { + if (this.secretKey) { const jwt = await generateJwt(this.channelId, this.secretKey); this.connection.metadata = { access_token: jwt, diff --git a/messaging/main.ts b/messaging/main.ts index f1253e2..3d19317 100644 --- a/messaging/main.ts +++ b/messaging/main.ts @@ -82,7 +82,7 @@ class SoraClient { } async connect(compress: boolean, header: boolean) { - if (this.secretKey !== "") { + if (this.secretKey) { const jwt = await generateJwt(this.channelId, this.secretKey); this.connection.metadata = { access_token: jwt, diff --git a/recvonly/main.ts b/recvonly/main.ts index 5f3ee47..79aa021 100644 --- a/recvonly/main.ts +++ b/recvonly/main.ts @@ -60,7 +60,7 @@ class SoraClient { } async connect(): Promise { - if (this.secretKey !== "") { + if (this.secretKey) { const jwt = await generateJwt(this.channelId, this.secretKey); this.connection.metadata = { access_token: jwt, diff --git a/replace_track/main.ts b/replace_track/main.ts index 7473ddc..9b5a437 100644 --- a/replace_track/main.ts +++ b/replace_track/main.ts @@ -78,7 +78,7 @@ class SoraClient { } async connect() { - if (this.secretKey !== "") { + if (this.secretKey) { const jwt = await generateJwt(this.channelId, this.secretKey); this.connection.metadata = { access_token: jwt, diff --git a/sendonly/main.ts b/sendonly/main.ts index ac571bc..4cea7ed 100644 --- a/sendonly/main.ts +++ b/sendonly/main.ts @@ -67,7 +67,7 @@ class SoraClient { } async connect(stream: MediaStream): Promise { - if (this.secretKey !== "") { + if (this.secretKey) { const jwt = await generateJwt(this.channelId, this.secretKey); this.connection.metadata = { access_token: jwt, diff --git a/sendrecv/main.ts b/sendrecv/main.ts index 9959aa9..2c49d49 100644 --- a/sendrecv/main.ts +++ b/sendrecv/main.ts @@ -63,9 +63,8 @@ class SoraClient { } async connect(stream: MediaStream) { - if (this.secretKey !== "") { + if (this.secretKey) { const jwt = await generateJwt(this.channelId, this.secretKey); - console.log(`jwt=${jwt}`); this.connection.metadata = { access_token: jwt, }; diff --git a/simulcast/main.ts b/simulcast/main.ts index 1864416..47805cc 100644 --- a/simulcast/main.ts +++ b/simulcast/main.ts @@ -100,7 +100,7 @@ class SimulcastSendonlySoraClient { } async connect(stream: MediaStream) { - if (this.secretKey !== "") { + if (this.secretKey) { const jwt = await generateJwt(this.channelId, this.secretKey); this.connection.metadata = { access_token: jwt, diff --git a/spotlight_sendrecv/main.ts b/spotlight_sendrecv/main.ts index 685a19b..773ac88 100644 --- a/spotlight_sendrecv/main.ts +++ b/spotlight_sendrecv/main.ts @@ -58,7 +58,7 @@ class SoraClient { } async connect(stream: MediaStream) { - if (this.secretKey !== "") { + if (this.secretKey) { const jwt = await generateJwt(this.channelId, this.secretKey); this.connection.metadata = { access_token: jwt, diff --git a/src/misc.ts b/src/misc.ts index 98ccde9..81ccd92 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -14,17 +14,16 @@ export const generateJwt = async (channelId: string, secretKey: string): Promise }; export const generateChannelId = (): string => { - // qs で channelId が指定されている場合はそれを利用する + // qs を確認する const urlParams = new URLSearchParams(window.location.search); const qsChannelId = urlParams.get("channelId") || ""; - if (qsChannelId) { - return qsChannelId; - } + const qsChannelIdPrefix = urlParams.get("channelIdPrefix") || ""; + const qsChannelIdSuffix = urlParams.get("channelIdSuffix") || ""; - // qs が指定されていない場合は環境変数を利用する - const channelId = import.meta.env.VITE_SORA_CHANNEL_ID; - const channelIdPrefix = import.meta.env.VITE_SORA_CHANNEL_ID_PREFIX; - const channelIdSuffix = import.meta.env.VITE_SORA_CHANNEL_ID_SUFFIX; + // qs が指定されていればその値を優先するようにする + const channelId = qsChannelId || import.meta.env.VITE_SORA_CHANNEL_ID || ""; + const channelIdPrefix = qsChannelIdPrefix || import.meta.env.VITE_SORA_CHANNEL_ID_PREFIX || ""; + const channelIdSuffix = qsChannelIdSuffix || import.meta.env.VITE_SORA_CHANNEL_ID_SUFFIX || ""; // 環境変数の channelId が指定されていない場合はエラー if (!channelId) { diff --git a/tests/sendrecv.test.ts b/tests/sendrecv.test.ts index a814870..7164606 100644 --- a/tests/sendrecv.test.ts +++ b/tests/sendrecv.test.ts @@ -4,10 +4,10 @@ test("sendrecv x2", async ({ browser }) => { const sendrecv1 = await browser.newPage(); const sendrecv2 = await browser.newPage(); - // テストごとに異なる channelName を生成 - const channelName = crypto.randomUUID(); - await sendrecv1.goto(`http://localhost:9000/sendrecv/?channelName=${channelName}`); - await sendrecv2.goto(`http://localhost:9000/sendrecv/?channelName=${channelName}`); + const channelIdSuffix = crypto.randomUUID(); + + await sendrecv1.goto(`http://localhost:9000/sendrecv/?channelIdSuffix=${channelIdSuffix}`); + await sendrecv2.goto(`http://localhost:9000/sendrecv/?channelIdSuffix=${channelIdSuffix}`); await sendrecv1.click("#connect"); await sendrecv2.click("#connect");