refactor: remplacement système de canaux statiques par canaux virtuels depuis routing

This commit is contained in:
2026-05-25 21:03:40 +02:00
parent 7037517ca2
commit 42badb1fdf
8 changed files with 252 additions and 79 deletions
+10 -35
View File
@@ -52,16 +52,12 @@ function loadConfig() {
const configFile = readFileSync(configPath, 'utf8');
const config = YAML.parse(configFile);
// Générer les IDs pour les groupes et canaux
// Générer les IDs pour les groupes
config.groups = config.groups.map(group => {
const groupId = slugify(group.name);
return {
...group,
id: groupId,
channels: group.channels ? group.channels.map(channel => ({
...channel,
id: channel.id || `${groupId}-${slugify(channel.name)}`
})) : []
id: groupId
};
});
@@ -78,13 +74,7 @@ function saveConfig(config) {
...config,
groups: config.groups.map(group => {
const { id, ...groupWithoutId } = group;
return {
...groupWithoutId,
channels: group.channels ? group.channels.map(channel => {
const { id: channelId, ...channelWithoutId } = channel;
return channelWithoutId;
}) : []
};
return groupWithoutId;
})
};
@@ -194,11 +184,11 @@ router.get('/groups', (req, res) => {
*/
router.post('/groups', (req, res) => {
try {
const { name, audioBitrate, channels } = req.body;
const { name, audioBitrate } = req.body;
if (!name || !channels || !Array.isArray(channels)) {
if (!name) {
return res.status(400).json({
error: 'Missing required fields: name, channels'
error: 'Missing required field: name'
});
}
@@ -214,17 +204,10 @@ router.post('/groups', (req, res) => {
});
}
// Générer les IDs pour les canaux
const channelsWithIds = channels.map(channel => ({
...channel,
id: channel.id || `${id}-${slugify(channel.name)}`
}));
// Créer le nouveau groupe
// Créer le nouveau groupe (sans channels)
const newGroup = {
name,
audioBitrate: audioBitrate || config.audio.defaultBitrate,
channels: channelsWithIds
...(audioBitrate && { audioBitrate })
};
config.groups.push(newGroup);
@@ -246,13 +229,13 @@ router.post('/groups', (req, res) => {
/**
* PUT /admin/groups/:id
* Modifie un groupe existant
* Body: { name?, audioBitrate?, channels? }
* Body: { name?, audioBitrate? }
* Note: l'ID est un slug généré, on cherche le groupe par nom dans le YAML
*/
router.put('/groups/:id', (req, res) => {
try {
const { id } = req.params;
const { name, audioBitrate, channels } = req.body;
const { name, audioBitrate } = req.body;
const config = loadConfig();
@@ -268,14 +251,6 @@ router.put('/groups/:id', (req, res) => {
// Mettre à jour les champs fournis
if (name !== undefined) config.groups[groupIndex].name = name;
if (audioBitrate !== undefined) config.groups[groupIndex].audioBitrate = audioBitrate;
if (channels !== undefined) {
// Pas besoin de générer les IDs ici, ils seront générés au chargement
config.groups[groupIndex].channels = channels.map(channel => ({
name: channel.name,
audioInput: channel.audioInput,
audioOutput: channel.audioOutput
}));
}
saveConfig(config);
+24 -18
View File
@@ -7,30 +7,36 @@ audio:
inputDeviceId: 0
outputDeviceId: 2
sampleRate: 48000
routing:
inputToGroup:
"1":
- technique
"2":
- technique
"4":
- technique
"5":
- technique
groupToOutput: {}
gains: {}
channelNames:
inputs:
"0": "Micro Régisseur"
"1": "Talkback FOH"
"2": "Retour Console"
"3": "Liaison Scène"
"4": "Monitor Mix"
"5": "Spare 1"
outputs:
"0": "Sortie Principale"
"1": "Retour Scène"
"2": "Talkback Console"
groups:
- name: Production
audioBitrate: 96
channels:
- name: Principal
audioInput: 0
audioOutput: 0
- name: Backup
audioInput: 1
audioOutput: 1
- name: Technique
channels:
- name: Général
audioInput: 2
audioOutput: 2
- name: Sonorisation
audioBitrate: 128
channels:
- name: Principal
audioInput: 3
audioOutput: 3
- name: Retours
audioInput: 4
audioOutput: 4
server:
host: 0.0.0.0
port: 3000
+21 -6
View File
@@ -196,11 +196,7 @@ app.get('/config', (req, res) => {
const clientConfig = {
groups: config.groups.map(g => ({
id: g.id,
name: g.name,
channels: g.channels.map(c => ({
id: c.id,
name: c.name
}))
name: g.name
})),
audio: {
sampleRate: config.audio.sampleRate,
@@ -281,11 +277,30 @@ app.post('/token', async (req, res) => {
// Enregistrer l'utilisateur dans le système admin
registerUser(participantIdentity, username, groupId, roomName);
// Générer les canaux virtuels depuis le routing (inputs uniquement)
const virtualChannels = [];
const inputToGroup = config.audio?.routing?.inputToGroup || {};
const channelNames = config.audio?.channelNames?.inputs || {};
// Trouver tous les canaux physiques routés vers ce groupe
for (const [inputChannel, groups] of Object.entries(inputToGroup)) {
if (groups.includes(groupId)) {
const channelName = channelNames[inputChannel] || `Canal ${inputChannel}`;
virtualChannels.push({
id: `input-${inputChannel}`,
name: channelName,
isVirtual: true,
audioInput: parseInt(inputChannel, 10)
});
}
}
res.json({
token,
url: LIVEKIT_URL,
roomName,
participantIdentity
participantIdentity,
virtualChannels
});
} catch (error) {