Add OBS scene switching controls with dynamic button states
Some checks failed
Lint and Build / build (pull_request) Failing after 1m25s
Some checks failed
Lint and Build / build (pull_request) Failing after 1m25s
- Add setScene API endpoint for OBS scene switching (1-Screen, 2-Screen, 4-Screen) - Add getCurrentScene API endpoint to fetch active OBS scene - Implement scene switching buttons in main UI with dynamic state tracking - Buttons change color and text based on current active scene - Glass morphism styling with Solarized Dark gradients - Real-time scene state synchronization with optimistic UI updates - Toast notifications for user feedback 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6fadccef51
commit
260eb3f7b2
3 changed files with 196 additions and 26 deletions
66
app/api/setScene/route.ts
Normal file
66
app/api/setScene/route.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getOBSClient } from '../../../lib/obsClient';
|
||||
|
||||
// Valid scene names for this application
|
||||
const VALID_SCENES = ['1-Screen', '2-Screen', '4-Screen'] as const;
|
||||
type ValidScene = typeof VALID_SCENES[number];
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { sceneName } = body;
|
||||
|
||||
// Validate scene name
|
||||
if (!sceneName || typeof sceneName !== 'string') {
|
||||
return NextResponse.json(
|
||||
{ success: false, error: 'Scene name is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
if (!VALID_SCENES.includes(sceneName as ValidScene)) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Invalid scene name',
|
||||
validScenes: VALID_SCENES
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const obsClient = await getOBSClient();
|
||||
|
||||
// Switch to the requested scene
|
||||
await obsClient.call('SetCurrentProgramScene', { sceneName });
|
||||
|
||||
console.log(`Successfully switched to scene: ${sceneName}`);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: { sceneName },
|
||||
message: `Switched to ${sceneName} layout`
|
||||
});
|
||||
} catch (obsError) {
|
||||
console.error('OBS WebSocket error:', obsError);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Failed to switch scene in OBS',
|
||||
details: obsError instanceof Error ? obsError.message : 'Unknown error'
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error switching scene:', error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Invalid request format'
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue