feat: pattern editor
This commit is contained in:
@@ -141,6 +141,10 @@ class LEDLabServer {
|
||||
this.startPreset(data.presetName, data.width, data.height, data.nodeIp, data.parameters);
|
||||
break;
|
||||
|
||||
case 'startCustomPreset':
|
||||
this.startCustomPreset(data.configuration, data.nodeIp);
|
||||
break;
|
||||
|
||||
case 'stopStreaming':
|
||||
this.stopStreaming(data.nodeIp);
|
||||
break;
|
||||
@@ -267,6 +271,72 @@ class LEDLabServer {
|
||||
}
|
||||
}
|
||||
|
||||
startCustomPreset(configuration, nodeIp = null) {
|
||||
try {
|
||||
const CustomPreset = require('../presets/custom-preset');
|
||||
const targetIp = nodeIp || this.currentTarget;
|
||||
|
||||
if (!targetIp) {
|
||||
console.warn('No target specified for streaming');
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract dimensions from configuration or use defaults
|
||||
const width = configuration.width || this.matrixWidth;
|
||||
const height = configuration.height || this.matrixHeight;
|
||||
|
||||
// Stop current streaming for this node if active
|
||||
this.stopStreaming(targetIp);
|
||||
|
||||
// Create custom preset instance with configuration
|
||||
const preset = new CustomPreset(width, height, configuration);
|
||||
preset.start();
|
||||
|
||||
console.log(`Started custom preset: ${configuration.name} (${width}x${height}) for ${targetIp}`);
|
||||
|
||||
// Start streaming interval for this node
|
||||
const intervalMs = Math.floor(1000 / this.fps);
|
||||
const interval = setInterval(() => {
|
||||
this.streamFrameForNode(targetIp);
|
||||
}, intervalMs);
|
||||
|
||||
// Store stream information
|
||||
this.nodeStreams.set(targetIp, {
|
||||
preset,
|
||||
presetName: 'custom-' + configuration.name,
|
||||
interval,
|
||||
matrixSize: { width, height },
|
||||
parameters: preset.getParameters(),
|
||||
configuration: configuration
|
||||
});
|
||||
|
||||
// Update legacy support
|
||||
if (targetIp === this.currentTarget) {
|
||||
this.currentPreset = preset;
|
||||
this.currentPresetName = 'custom-' + configuration.name;
|
||||
this.streamingInterval = interval;
|
||||
}
|
||||
|
||||
// Notify clients
|
||||
this.broadcastToClients({
|
||||
type: 'streamingStarted',
|
||||
preset: preset.getMetadata(),
|
||||
nodeIp: targetIp,
|
||||
isCustom: true
|
||||
});
|
||||
|
||||
// Also send updated state to keep all clients in sync
|
||||
this.broadcastCurrentState();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error starting custom preset:', error);
|
||||
this.broadcastToClients({
|
||||
type: 'error',
|
||||
message: `Failed to start custom preset: ${error.message}`
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
stopStreaming(nodeIp = null) {
|
||||
const targetIp = nodeIp || this.currentTarget;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user