From 6fc079382afd977d3ddd5f256d360311365bd752 Mon Sep 17 00:00:00 2001 From: Decobus Date: Sun, 20 Jul 2025 17:55:11 -0400 Subject: [PATCH] Prefix OBS source names with team scene names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update stream creation to include team prefixes in all OBS source naming: - Browser sources: team_streamname format - Stream group scenes: team_streamname_stream format - Consistent naming across createStreamGroup and addStream functions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- app/api/addStream/route.ts | 38 +++++++++++++++++++++----------------- lib/obsClient.js | 6 ++++-- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/app/api/addStream/route.ts b/app/api/addStream/route.ts index bb9df52..4bb22d6 100644 --- a/app/api/addStream/route.ts +++ b/app/api/addStream/route.ts @@ -63,9 +63,11 @@ async function fetchTeamInfo(teamId: number) { import { validateStreamInput } from '../../../lib/security'; -// Generate OBS source name from stream name -function generateOBSSourceName(streamName: string): string { - return streamName.toLowerCase().replace(/\s+/g, '_') + '_twitch'; +// Generate OBS source name from team scene name and stream name +function generateOBSSourceName(teamSceneName: string, streamName: string): string { + const cleanTeamName = teamSceneName.toLowerCase().replace(/\s+/g, '_'); + const cleanStreamName = streamName.toLowerCase().replace(/\s+/g, '_'); + return `${cleanTeamName}_${cleanStreamName}`; } export async function POST(request: NextRequest) { @@ -84,15 +86,25 @@ export async function POST(request: NextRequest) { } ({ name, url, team_id } = validation.data!); - - // Auto-generate OBS source name from stream name - obs_source_name = generateOBSSourceName(name); } catch { return NextResponse.json({ error: 'Invalid JSON in request body' }, { status: 400 }); } try { + // Fetch team info first to generate proper OBS source name + const teamInfo = await fetchTeamInfo(team_id); + if (!teamInfo) { + throw new Error('Team not found'); + } + + console.log('Team Info:', teamInfo); + + // Use group_name if it exists, otherwise use team_name + const groupName = teamInfo.group_name || teamInfo.team_name; + + // Generate OBS source name with team scene name prefix + obs_source_name = generateOBSSourceName(groupName, name); // Connect to OBS WebSocket console.log("Pre-connect") @@ -117,16 +129,6 @@ export async function POST(request: NextRequest) { throw new Error('GetInputList failed.'); } - const teamInfo = await fetchTeamInfo(team_id); - if (!teamInfo) { - throw new Error('Team not found'); - } - - console.log('Team Info:', teamInfo); - - // Use group_name if it exists, otherwise use team_name - const groupName = teamInfo.group_name || teamInfo.team_name; - const sourceExists = inputs.some((input: OBSInput) => input.inputName === obs_source_name); if (!sourceExists) { @@ -174,7 +176,9 @@ export async function POST(request: NextRequest) { for (const screen of screens) { try { - const streamGroupName = `${name.toLowerCase().replace(/\s+/g, '_')}_stream`; + const cleanGroupName = groupName.toLowerCase().replace(/\s+/g, '_'); + const cleanStreamName = name.toLowerCase().replace(/\s+/g, '_'); + const streamGroupName = `${cleanGroupName}_${cleanStreamName}_stream`; await addSourceToSwitcher(screen, [ { hidden: false, selected: false, value: streamGroupName }, ]); diff --git a/lib/obsClient.js b/lib/obsClient.js index 0ee68b7..d2f5872 100644 --- a/lib/obsClient.js +++ b/lib/obsClient.js @@ -317,8 +317,10 @@ async function createStreamGroup(groupName, streamName, teamName, url) { // Ensure team scene exists await createGroupIfNotExists(groupName); - const streamGroupName = `${streamName.toLowerCase().replace(/\s+/g, '_')}_stream`; - const sourceName = streamName.toLowerCase().replace(/\s+/g, '_') + '_twitch'; + const cleanGroupName = groupName.toLowerCase().replace(/\s+/g, '_'); + const cleanStreamName = streamName.toLowerCase().replace(/\s+/g, '_'); + const streamGroupName = `${cleanGroupName}_${cleanStreamName}_stream`; + const sourceName = `${cleanGroupName}_${cleanStreamName}`; const textSourceName = teamName.toLowerCase().replace(/\s+/g, '_') + '_text'; // Create a nested scene for this stream (acts as a group)