Skip to content

Commit

Permalink
整備
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Jan 16, 2025
1 parent e1cd8a7 commit 6f4d702
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion check_stereo/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class SendonlyClient {
}

async connect(stream: MediaStream): Promise<void> {
if (this.secretKey !== "") {
if (this.secretKey) {
const jwt = await generateJwt(this.channelId, this.secretKey);
this.connection.metadata = {
access_token: jwt,
Expand Down
2 changes: 1 addition & 1 deletion check_stereo_multi/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class SendonlyClient {
}

async connect(stream: MediaStream): Promise<void> {
if (this.secretKey !== "") {
if (this.secretKey) {
const jwt = await generateJwt(this.channelId, this.secretKey);
this.connection.metadata = {
access_token: jwt,
Expand Down
2 changes: 1 addition & 1 deletion messaging/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion recvonly/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SoraClient {
}

async connect(): Promise<void> {
if (this.secretKey !== "") {
if (this.secretKey) {
const jwt = await generateJwt(this.channelId, this.secretKey);
this.connection.metadata = {
access_token: jwt,
Expand Down
2 changes: 1 addition & 1 deletion replace_track/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sendonly/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SoraClient {
}

async connect(stream: MediaStream): Promise<void> {
if (this.secretKey !== "") {
if (this.secretKey) {
const jwt = await generateJwt(this.channelId, this.secretKey);
this.connection.metadata = {
access_token: jwt,
Expand Down
3 changes: 1 addition & 2 deletions sendrecv/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion simulcast/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spotlight_sendrecv/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 7 additions & 8 deletions src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions tests/sendrecv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 6f4d702

Please sign in to comment.