Routage complexe #3
@@ -9,6 +9,7 @@ pnpm-lock.yaml
|
||||
.env.local
|
||||
.env.*.local
|
||||
server/.env
|
||||
server/config/config.yaml
|
||||
client/.env
|
||||
|
||||
# Keep .env.example files (templates)
|
||||
|
||||
@@ -283,8 +283,17 @@ export default function useLiveKit() {
|
||||
});
|
||||
});
|
||||
|
||||
// Participants distants (utilisateurs WebRTC)
|
||||
// Participants distants (utilisateurs WebRTC + server audio users)
|
||||
// Exclure les participants internes de routage (role: 'bridge')
|
||||
room.remoteParticipants.forEach((participant) => {
|
||||
let role = null;
|
||||
try {
|
||||
const meta = participant.metadata ? JSON.parse(participant.metadata) : {};
|
||||
role = meta.role || null;
|
||||
} catch (_) {}
|
||||
|
||||
if (role === 'bridge') return;
|
||||
|
||||
const audioTracks = participant.audioTracks ? Array.from(participant.audioTracks.values()) : [];
|
||||
const audioPublication = audioTracks[0];
|
||||
const isSpeaking = room.activeSpeakers.some(s => s.identity === participant.identity);
|
||||
|
||||
+46
-6
@@ -454,7 +454,7 @@ app.whenReady().then(async () => {
|
||||
if (users.find(u => u.name === name)) {
|
||||
return { success: false, error: `Un utilisateur "${name}" existe déjà` };
|
||||
}
|
||||
const user = { name, group, input_channel: parseInt(input_channel), output_channel: parseInt(output_channel) };
|
||||
const user = { name, group, input_channel: parseInt(input_channel), output_channel: output_channel !== null && output_channel !== '' ? parseInt(output_channel) : null };
|
||||
config.server_audio_users = [...users, user];
|
||||
writeConfig(config);
|
||||
return { success: true, user };
|
||||
@@ -469,7 +469,7 @@ app.whenReady().then(async () => {
|
||||
const users = config.server_audio_users || [];
|
||||
const idx = users.findIndex(u => u.name === name);
|
||||
if (idx === -1) return { success: false, error: `Utilisateur "${name}" introuvable` };
|
||||
config.server_audio_users[idx] = { name, group, input_channel: parseInt(input_channel), output_channel: parseInt(output_channel) };
|
||||
config.server_audio_users[idx] = { name, group, input_channel: parseInt(input_channel), output_channel: output_channel !== null && output_channel !== '' ? parseInt(output_channel) : null };
|
||||
writeConfig(config);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
@@ -497,20 +497,60 @@ app.whenReady().then(async () => {
|
||||
try {
|
||||
const config = readConfig();
|
||||
return {
|
||||
routing: config.audio?.routing || { inputToGroup: {}, groupToOutput: {}, gains: {} },
|
||||
channelNames: config.audio?.channelNames || { inputs: {}, outputs: {} },
|
||||
groups: config.groups || []
|
||||
groups: config.groups || [],
|
||||
serverAudioUsers: config.server_audio_users || []
|
||||
};
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('routing:save', (event, { routing, channelNames }) => {
|
||||
// ========== Devices : découverte canaux physiques ==========
|
||||
|
||||
ipcMain.handle('devices:getChannels', () => {
|
||||
try {
|
||||
const config = readConfig();
|
||||
const inputDeviceName = config.audio?.device?.inputDeviceId;
|
||||
const outputDeviceName = config.audio?.device?.outputDeviceId;
|
||||
|
||||
let inputDevice = { name: inputDeviceName || 'Non configuré', channels: 0 };
|
||||
let outputDevice = { name: outputDeviceName || 'Non configuré', channels: 0 };
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
try {
|
||||
const { execSync } = require('child_process');
|
||||
const raw = execSync('system_profiler SPAudioDataType -json', { encoding: 'utf8', timeout: 5000 });
|
||||
const data = JSON.parse(raw);
|
||||
|
||||
if (data.SPAudioDataType) {
|
||||
data.SPAudioDataType.forEach(item => {
|
||||
(item._items || []).forEach(dev => {
|
||||
const name = dev._name || '';
|
||||
const inCh = parseInt(dev.coreaudio_device_input) || 0;
|
||||
const outCh = parseInt(dev.coreaudio_device_output) || 0;
|
||||
if (inputDeviceName && name === inputDeviceName && inCh > 0) {
|
||||
inputDevice = { name, channels: inCh };
|
||||
}
|
||||
if (outputDeviceName && name === outputDeviceName && outCh > 0) {
|
||||
outputDevice = { name, channels: outCh };
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch (_) { /* detection failed, keep defaults */ }
|
||||
}
|
||||
|
||||
return { inputDevice, outputDevice };
|
||||
} catch (error) {
|
||||
return { error: error.message, inputDevice: { name: 'Inconnu', channels: 0 }, outputDevice: { name: 'Inconnu', channels: 0 } };
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('routing:save', (event, { channelNames }) => {
|
||||
try {
|
||||
const config = readConfig();
|
||||
if (!config.audio) config.audio = {};
|
||||
config.audio.routing = routing;
|
||||
config.audio.channelNames = channelNames;
|
||||
writeConfig(config);
|
||||
return { success: true };
|
||||
|
||||
@@ -65,6 +65,11 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||
save: (data) => ipcRenderer.invoke('routing:save', data)
|
||||
},
|
||||
|
||||
// Découverte canaux physiques de la carte son sélectionnée
|
||||
devices: {
|
||||
getChannels: () => ipcRenderer.invoke('devices:getChannels')
|
||||
},
|
||||
|
||||
// Helpers
|
||||
platform: process.platform,
|
||||
version: process.env.npm_package_version || '0.3.0'
|
||||
|
||||
+152
-222
@@ -10,6 +10,7 @@ let statsInterval = null;
|
||||
let logsBuffer = [];
|
||||
let audioLevelsWS = null;
|
||||
let routingData = null;
|
||||
let deviceChannels = null;
|
||||
let audioLevelsData = {
|
||||
inputs: {},
|
||||
groups: {},
|
||||
@@ -585,7 +586,6 @@ async function loadViewData(view) {
|
||||
}
|
||||
|
||||
if (view === 'config') {
|
||||
await fetchServerAudioUsers();
|
||||
if (serverRunning) {
|
||||
await fetchDevices();
|
||||
await fetchConfig();
|
||||
@@ -790,16 +790,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
}
|
||||
|
||||
// Bouton ajouter utilisateur audio serveur
|
||||
const btnAddSAU = document.getElementById('btn-add-server-audio-user');
|
||||
if (btnAddSAU) {
|
||||
btnAddSAU.addEventListener('click', addServerAudioUser);
|
||||
}
|
||||
// Boutons routing
|
||||
document.getElementById('btn-save-routing')?.addEventListener('click', saveRouting);
|
||||
document.getElementById('btn-reload-routing')?.addEventListener('click', fetchRouting);
|
||||
document.getElementById('btn-refresh-channels')?.addEventListener('click', fetchRouting);
|
||||
document.getElementById('btn-add-server-audio-user')?.addEventListener('click', addServerAudioUser);
|
||||
|
||||
// Délégation modifier/supprimer utilisateur audio serveur
|
||||
const sauList = document.getElementById('server-audio-users-list');
|
||||
if (sauList) {
|
||||
sauList.addEventListener('click', async (e) => {
|
||||
// Délégation modifier/supprimer participant serveur
|
||||
document.getElementById('server-audio-users-list')?.addEventListener('click', async (e) => {
|
||||
const btn = e.target.closest('[data-sau-action]');
|
||||
if (!btn) return;
|
||||
const action = btn.dataset.sauAction;
|
||||
@@ -810,74 +808,101 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
await deleteServerAudioUser(name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Boutons routing
|
||||
document.getElementById('btn-save-routing')?.addEventListener('click', saveRouting);
|
||||
document.getElementById('btn-reload-routing')?.addEventListener('click', fetchRouting);
|
||||
document.getElementById('btn-add-input-channel')?.addEventListener('click', () => addChannelRow('input'));
|
||||
document.getElementById('btn-add-output-channel')?.addEventListener('click', () => addChannelRow('output'));
|
||||
|
||||
// Délégation suppression lignes canal (boutons ✕)
|
||||
document.addEventListener('click', (e) => {
|
||||
const btn = e.target.closest('.channel-name-delete');
|
||||
if (!btn) return;
|
||||
deleteChannelRow(btn.dataset.dir, btn.dataset.channel);
|
||||
});
|
||||
});
|
||||
|
||||
// ========== Server Audio Users ==========
|
||||
// ========== Server Audio Users (dans la vue Routing) ==========
|
||||
|
||||
async function fetchServerAudioUsers() {
|
||||
function renderServerAudioUsers() {
|
||||
const container = document.getElementById('server-audio-users-list');
|
||||
if (!container) return;
|
||||
|
||||
const data = await window.electronAPI.serverAudioUsers.list();
|
||||
const users = routingData?.serverAudioUsers || [];
|
||||
const inputs = routingData?.channelNames?.inputs || {};
|
||||
const outputs = routingData?.channelNames?.outputs || {};
|
||||
|
||||
const serverNote = serverRunning ? '' :
|
||||
'<p class="config-note" style="margin-bottom:1rem">Serveur arrêté — les modifications seront appliquées au prochain démarrage.</p>';
|
||||
const chLabel = (ch, dir) => {
|
||||
if (ch === null || ch === undefined) return 'Aucune';
|
||||
const name = dir === 'input' ? inputs[ch] : outputs[ch];
|
||||
return name ? `Ch ${ch} · ${name}` : `Ch ${ch}`;
|
||||
};
|
||||
|
||||
if (!data.users || data.users.length === 0) {
|
||||
container.innerHTML = serverNote + '<p class="empty-state">Aucun utilisateur audio serveur configuré</p>';
|
||||
if (users.length === 0) {
|
||||
container.innerHTML = '<p class="empty-state" style="margin-top:1rem">Aucun participant serveur configuré</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = serverNote + data.users.map(user => `
|
||||
<div class="group-item">
|
||||
<div class="group-info">
|
||||
<h4>${escapeHtml(user.name)}</h4>
|
||||
<p>Groupe: <strong>${escapeHtml(user.group)}</strong> · Entrée: canal ${user.input_channel} · Sortie: canal ${user.output_channel}</p>
|
||||
</div>
|
||||
<div class="group-actions">
|
||||
container.innerHTML = `
|
||||
<table class="sau-table">
|
||||
<thead>
|
||||
<tr><th>Nom</th><th>Groupe</th><th>Entrée</th><th>Sortie</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${users.map(u => `
|
||||
<tr>
|
||||
<td class="sau-name">${escapeHtml(u.name)}</td>
|
||||
<td><span class="ch-badge ch-badge-group">${escapeHtml(u.group)}</span></td>
|
||||
<td><span class="ch-badge">${chLabel(u.input_channel, 'input')}</span></td>
|
||||
<td><span class="ch-badge">${chLabel(u.output_channel, 'output')}</span></td>
|
||||
<td class="sau-actions">
|
||||
<button class="btn btn-small btn-secondary"
|
||||
data-sau-action="edit"
|
||||
data-sau-name="${escapeHtml(user.name)}"
|
||||
data-sau-group="${escapeHtml(user.group)}"
|
||||
data-sau-input="${user.input_channel}"
|
||||
data-sau-output="${user.output_channel}">Modifier</button>
|
||||
data-sau-name="${escapeHtml(u.name)}"
|
||||
data-sau-group="${escapeHtml(u.group)}"
|
||||
data-sau-input="${u.input_channel}"
|
||||
data-sau-output="${u.output_channel}">Éditer</button>
|
||||
<button class="btn btn-small btn-danger"
|
||||
data-sau-action="delete"
|
||||
data-sau-name="${escapeHtml(user.name)}">Supprimer</button>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
data-sau-name="${escapeHtml(u.name)}">✕</button>
|
||||
</td>
|
||||
</tr>`).join('')}
|
||||
</tbody>
|
||||
</table>`;
|
||||
}
|
||||
|
||||
function buildChannelOptions(dir) {
|
||||
const channels = dir === 'input'
|
||||
? routingData?.deviceChannels?.inputDevice?.channels || 0
|
||||
: routingData?.deviceChannels?.outputDevice?.channels || 0;
|
||||
const names = dir === 'input'
|
||||
? routingData?.channelNames?.inputs || {}
|
||||
: routingData?.channelNames?.outputs || {};
|
||||
|
||||
if (channels === 0) return null; // fallback to number input
|
||||
|
||||
const opts = Array.from({ length: channels }, (_, i) => ({
|
||||
value: String(i),
|
||||
label: names[i] ? `Ch ${i}: ${names[i]}` : `Ch ${i}`
|
||||
}));
|
||||
|
||||
if (dir === 'output') {
|
||||
opts.unshift({ value: '', label: 'Aucune sortie' });
|
||||
}
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
||||
async function addServerAudioUser() {
|
||||
const groupsData = await window.electronAPI.groups.list();
|
||||
const groupOptions = (groupsData.groups || []).map(g => ({
|
||||
value: slugify(g.name),
|
||||
label: g.name
|
||||
}));
|
||||
const groupOptions = (groupsData.groups || []).map(g => ({ value: slugify(g.name), label: g.name }));
|
||||
const defaultGroup = groupOptions[0]?.value || 'default';
|
||||
|
||||
const inOpts = buildChannelOptions('input');
|
||||
const outOpts = buildChannelOptions('output');
|
||||
|
||||
const inputField = inOpts
|
||||
? { name: 'input_channel', label: 'Canal d\'entrée', type: 'select', options: inOpts, default: '0' }
|
||||
: { name: 'input_channel', label: 'Canal entrée (index)', type: 'number', default: 0, min: 0, max: 63 };
|
||||
const outputField = outOpts
|
||||
? { name: 'output_channel', label: 'Canal de sortie', type: 'select', options: outOpts, default: '' }
|
||||
: { name: 'output_channel', label: 'Canal sortie (index, vide = aucune)', type: 'number', default: '', min: 0, max: 63 };
|
||||
|
||||
const result = await showModal({
|
||||
title: 'Nouvel utilisateur audio serveur',
|
||||
title: 'Nouveau participant serveur',
|
||||
fields: [
|
||||
{ name: 'name', label: 'Nom (identifiant unique, ex: foh)' },
|
||||
{ name: 'group', label: 'Groupe', type: 'select', options: groupOptions, default: defaultGroup },
|
||||
{ name: 'input_channel', label: 'Canal entrée (index physique)', type: 'number', default: 0, min: 0, max: 63, step: 1 },
|
||||
{ name: 'output_channel', label: 'Canal sortie (index physique)', type: 'number', default: 0, min: 0, max: 63, step: 1 }
|
||||
inputField,
|
||||
outputField
|
||||
],
|
||||
confirmLabel: 'Ajouter'
|
||||
});
|
||||
@@ -888,12 +913,12 @@ async function addServerAudioUser() {
|
||||
name: result.name.trim(),
|
||||
group: result.group,
|
||||
input_channel: parseInt(result.input_channel),
|
||||
output_channel: parseInt(result.output_channel)
|
||||
output_channel: result.output_channel !== '' ? parseInt(result.output_channel) : null
|
||||
});
|
||||
|
||||
if (res.success) {
|
||||
showNotification('Utilisateur audio serveur ajouté', 'success');
|
||||
await fetchServerAudioUsers();
|
||||
showNotification('Participant serveur ajouté', 'success');
|
||||
await fetchRouting();
|
||||
} else {
|
||||
showNotification('Erreur: ' + (res.error || 'Création échouée'), 'error');
|
||||
}
|
||||
@@ -901,17 +926,25 @@ async function addServerAudioUser() {
|
||||
|
||||
async function editServerAudioUser(name, group, input_channel, output_channel) {
|
||||
const groupsData = await window.electronAPI.groups.list();
|
||||
const groupOptions = (groupsData.groups || []).map(g => ({
|
||||
value: slugify(g.name),
|
||||
label: g.name
|
||||
}));
|
||||
const groupOptions = (groupsData.groups || []).map(g => ({ value: slugify(g.name), label: g.name }));
|
||||
|
||||
const inOpts = buildChannelOptions('input');
|
||||
const outOpts = buildChannelOptions('output');
|
||||
|
||||
const inputField = inOpts
|
||||
? { name: 'input_channel', label: 'Canal d\'entrée', type: 'select', options: inOpts, default: String(input_channel) }
|
||||
: { name: 'input_channel', label: 'Canal entrée (index)', type: 'number', default: input_channel, min: 0, max: 63 };
|
||||
const outputDefault = output_channel !== null && output_channel !== undefined ? String(output_channel) : '';
|
||||
const outputField = outOpts
|
||||
? { name: 'output_channel', label: 'Canal de sortie', type: 'select', options: outOpts, default: outputDefault }
|
||||
: { name: 'output_channel', label: 'Canal sortie (index, vide = aucune)', type: 'number', default: outputDefault, min: 0, max: 63 };
|
||||
|
||||
const result = await showModal({
|
||||
title: `Modifier "${name}"`,
|
||||
fields: [
|
||||
{ name: 'group', label: 'Groupe', type: 'select', options: groupOptions, default: group },
|
||||
{ name: 'input_channel', label: 'Canal entrée (index physique)', type: 'number', default: input_channel, min: 0, max: 63, step: 1 },
|
||||
{ name: 'output_channel', label: 'Canal sortie (index physique)', type: 'number', default: output_channel, min: 0, max: 63, step: 1 }
|
||||
inputField,
|
||||
outputField
|
||||
],
|
||||
confirmLabel: 'Modifier'
|
||||
});
|
||||
@@ -922,12 +955,12 @@ async function editServerAudioUser(name, group, input_channel, output_channel) {
|
||||
name,
|
||||
group: result.group,
|
||||
input_channel: parseInt(result.input_channel),
|
||||
output_channel: parseInt(result.output_channel)
|
||||
output_channel: result.output_channel !== '' ? parseInt(result.output_channel) : null
|
||||
});
|
||||
|
||||
if (res.success) {
|
||||
showNotification('Utilisateur audio serveur modifié', 'success');
|
||||
await fetchServerAudioUsers();
|
||||
showNotification('Participant serveur modifié', 'success');
|
||||
await fetchRouting();
|
||||
} else {
|
||||
showNotification('Erreur: ' + (res.error || 'Modification échouée'), 'error');
|
||||
}
|
||||
@@ -935,7 +968,7 @@ async function editServerAudioUser(name, group, input_channel, output_channel) {
|
||||
|
||||
async function deleteServerAudioUser(name) {
|
||||
const confirmed = await showModal({
|
||||
title: 'Supprimer l\'utilisateur audio serveur',
|
||||
title: 'Supprimer le participant serveur',
|
||||
message: `Supprimer "${name}" ? Cette action est irréversible.`,
|
||||
confirmLabel: 'Supprimer',
|
||||
confirmClass: 'btn-danger'
|
||||
@@ -946,8 +979,8 @@ async function deleteServerAudioUser(name) {
|
||||
const res = await window.electronAPI.serverAudioUsers.delete({ name });
|
||||
|
||||
if (res.success) {
|
||||
showNotification('Utilisateur audio serveur supprimé', 'success');
|
||||
await fetchServerAudioUsers();
|
||||
showNotification('Participant serveur supprimé', 'success');
|
||||
await fetchRouting();
|
||||
} else {
|
||||
showNotification('Erreur: ' + (res.error || 'Suppression échouée'), 'error');
|
||||
}
|
||||
@@ -956,161 +989,83 @@ async function deleteServerAudioUser(name) {
|
||||
// ========== Routing ==========
|
||||
|
||||
async function fetchRouting() {
|
||||
const data = await window.electronAPI.routing.get();
|
||||
if (data.error) {
|
||||
showNotification('Erreur chargement routing: ' + data.error, 'error');
|
||||
const [routingResult, devResult] = await Promise.all([
|
||||
window.electronAPI.routing.get(),
|
||||
window.electronAPI.devices.getChannels()
|
||||
]);
|
||||
|
||||
if (routingResult.error) {
|
||||
showNotification('Erreur chargement routing: ' + routingResult.error, 'error');
|
||||
return;
|
||||
}
|
||||
routingData = data;
|
||||
|
||||
deviceChannels = devResult;
|
||||
routingData = { ...routingResult, deviceChannels: devResult };
|
||||
renderRoutingView();
|
||||
}
|
||||
|
||||
function renderRoutingView() {
|
||||
if (!routingData) return;
|
||||
renderChannelNamesEditor();
|
||||
renderRoutingMatrices();
|
||||
renderDeviceBanner();
|
||||
renderChannelLabels();
|
||||
renderServerAudioUsers();
|
||||
}
|
||||
|
||||
function renderChannelNamesEditor() {
|
||||
const { channelNames } = routingData;
|
||||
function renderDeviceBanner() {
|
||||
const el = document.getElementById('routing-device-info');
|
||||
if (!el) return;
|
||||
|
||||
const dc = routingData.deviceChannels;
|
||||
if (!dc || dc.error || (dc.inputDevice?.channels === 0 && dc.outputDevice?.channels === 0)) {
|
||||
el.innerHTML = `<span class="device-unset">Aucun device configuré — sélectionnez une carte son dans <strong>Configuration</strong></span>`;
|
||||
return;
|
||||
}
|
||||
|
||||
const { inputDevice, outputDevice } = dc;
|
||||
el.innerHTML = `
|
||||
<span class="device-entry"><strong>Entrée :</strong> ${escapeHtml(inputDevice.name)}
|
||||
<span class="device-ch-badge">${inputDevice.channels} ch</span></span>
|
||||
<span class="device-sep">·</span>
|
||||
<span class="device-entry"><strong>Sortie :</strong> ${escapeHtml(outputDevice.name)}
|
||||
<span class="device-ch-badge">${outputDevice.channels} ch</span></span>`;
|
||||
}
|
||||
|
||||
function renderChannelLabels() {
|
||||
const { channelNames, deviceChannels: dc } = routingData;
|
||||
const inputs = channelNames?.inputs || {};
|
||||
const outputs = channelNames?.outputs || {};
|
||||
const inputCount = dc?.inputDevice?.channels || 0;
|
||||
const outputCount = dc?.outputDevice?.channels || 0;
|
||||
|
||||
const inputChannels = Object.keys(inputs).sort((a, b) => parseInt(a) - parseInt(b));
|
||||
const outputChannels = Object.keys(outputs).sort((a, b) => parseInt(a) - parseInt(b));
|
||||
const inputsEl = document.getElementById('channel-names-inputs');
|
||||
const outputsEl = document.getElementById('channel-names-outputs');
|
||||
|
||||
const inputsContainer = document.getElementById('channel-names-inputs');
|
||||
const outputsContainer = document.getElementById('channel-names-outputs');
|
||||
|
||||
if (inputsContainer) {
|
||||
inputsContainer.innerHTML = inputChannels.length > 0
|
||||
? inputChannels.map(ch => channelNameRow('input', ch, inputs[ch] || '')).join('')
|
||||
: '<p class="config-note">Aucun canal d\'entrée défini.</p>';
|
||||
if (inputsEl) {
|
||||
inputsEl.innerHTML = inputCount > 0
|
||||
? Array.from({ length: inputCount }, (_, i) => channelLabelRow('input', i, inputs[i] || '')).join('')
|
||||
: '<p class="config-note">Aucun device d\'entrée détecté.</p>';
|
||||
}
|
||||
|
||||
if (outputsContainer) {
|
||||
outputsContainer.innerHTML = outputChannels.length > 0
|
||||
? outputChannels.map(ch => channelNameRow('output', ch, outputs[ch] || '')).join('')
|
||||
: '<p class="config-note">Aucun canal de sortie défini.</p>';
|
||||
if (outputsEl) {
|
||||
outputsEl.innerHTML = outputCount > 0
|
||||
? Array.from({ length: outputCount }, (_, i) => channelLabelRow('output', i, outputs[i] || '')).join('')
|
||||
: '<p class="config-note">Aucun device de sortie détecté.</p>';
|
||||
}
|
||||
}
|
||||
|
||||
function channelNameRow(dir, ch, name) {
|
||||
function channelLabelRow(dir, ch, name) {
|
||||
return `
|
||||
<div class="channel-name-row" data-channel="${ch}" data-dir="${dir}">
|
||||
<span class="channel-index">Canal ${ch}</span>
|
||||
<span class="channel-index">Ch ${ch}</span>
|
||||
<input type="text" class="form-control form-control-small channel-name-input"
|
||||
data-dir="${dir}" data-channel="${ch}"
|
||||
value="${escapeHtml(name)}" placeholder="Nom du canal">
|
||||
<button class="btn btn-small btn-danger channel-name-delete" data-dir="${dir}" data-channel="${ch}">✕</button>
|
||||
value="${escapeHtml(name)}" placeholder="Label canal ${ch}">
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function addChannelRow(dir) {
|
||||
const containerId = dir === 'input' ? 'channel-names-inputs' : 'channel-names-outputs';
|
||||
const container = document.getElementById(containerId);
|
||||
if (!container) return;
|
||||
|
||||
// Retirer le message "Aucun canal" si présent
|
||||
const emptyMsg = container.querySelector('.config-note');
|
||||
if (emptyMsg) emptyMsg.remove();
|
||||
|
||||
const existing = Array.from(container.querySelectorAll('.channel-name-row'))
|
||||
.map(r => parseInt(r.dataset.channel))
|
||||
.filter(n => !isNaN(n));
|
||||
const nextCh = existing.length > 0 ? Math.max(...existing) + 1 : 0;
|
||||
|
||||
const row = document.createElement('div');
|
||||
row.innerHTML = channelNameRow(dir, nextCh, '');
|
||||
const newRow = row.firstElementChild;
|
||||
container.appendChild(newRow);
|
||||
newRow.querySelector('input')?.focus();
|
||||
}
|
||||
|
||||
function deleteChannelRow(dir, channel) {
|
||||
const containerId = dir === 'input' ? 'channel-names-inputs' : 'channel-names-outputs';
|
||||
const container = document.getElementById(containerId);
|
||||
const row = container?.querySelector(`.channel-name-row[data-channel="${channel}"][data-dir="${dir}"]`);
|
||||
if (!row) return;
|
||||
row.remove();
|
||||
if (!container.querySelector('.channel-name-row')) {
|
||||
container.innerHTML = `<p class="config-note">Aucun canal de ${dir === 'input' ? 'entrée' : 'sortie'} défini.</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
function renderRoutingMatrices() {
|
||||
const { routing, channelNames, groups } = routingData;
|
||||
const inputs = channelNames?.inputs || {};
|
||||
const outputs = channelNames?.outputs || {};
|
||||
const inputToGroup = routing?.inputToGroup || {};
|
||||
const groupToOutput = routing?.groupToOutput || {};
|
||||
|
||||
const inputChannels = Object.keys(inputs).sort((a, b) => parseInt(a) - parseInt(b));
|
||||
const outputChannels = Object.keys(outputs).sort((a, b) => parseInt(a) - parseInt(b));
|
||||
|
||||
// Matrice Entrées → Groupes
|
||||
const inputMatrixEl = document.getElementById('routing-input-matrix');
|
||||
if (inputMatrixEl) {
|
||||
if (inputChannels.length === 0 || groups.length === 0) {
|
||||
inputMatrixEl.innerHTML = '<p class="empty-state">Définissez des canaux d\'entrée et des groupes pour configurer le routing.</p>';
|
||||
} else {
|
||||
let html = '<div class="routing-matrix-scroll"><table class="routing-matrix"><thead><tr>';
|
||||
html += '<th class="matrix-label-cell">Canal Entrée</th>';
|
||||
groups.forEach(g => { html += `<th class="matrix-group-header">${escapeHtml(g.name)}</th>`; });
|
||||
html += '</tr></thead><tbody>';
|
||||
|
||||
inputChannels.forEach(ch => {
|
||||
const chGroups = inputToGroup[ch] || [];
|
||||
html += '<tr>';
|
||||
html += `<td class="matrix-channel-label"><span class="ch-index">${ch}</span><span class="ch-name">${escapeHtml(inputs[ch] || `Canal ${ch}`)}</span></td>`;
|
||||
groups.forEach(g => {
|
||||
const gId = slugify(g.name);
|
||||
const checked = chGroups.includes(gId) ? 'checked' : '';
|
||||
html += `<td class="matrix-cell"><input type="checkbox" class="routing-check" data-direction="input" data-channel="${ch}" data-group="${gId}" ${checked}></td>`;
|
||||
});
|
||||
html += '</tr>';
|
||||
});
|
||||
|
||||
html += '</tbody></table></div>';
|
||||
inputMatrixEl.innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
// Matrice Groupes → Sorties
|
||||
const outputMatrixEl = document.getElementById('routing-output-matrix');
|
||||
if (outputMatrixEl) {
|
||||
if (groups.length === 0 || outputChannels.length === 0) {
|
||||
outputMatrixEl.innerHTML = '<p class="empty-state">Définissez des canaux de sortie et des groupes pour configurer le routing.</p>';
|
||||
} else {
|
||||
let html = '<div class="routing-matrix-scroll"><table class="routing-matrix"><thead><tr>';
|
||||
html += '<th class="matrix-label-cell">Groupe</th>';
|
||||
outputChannels.forEach(ch => {
|
||||
html += `<th class="matrix-group-header"><span class="ch-index">${ch}</span><br><span class="ch-name">${escapeHtml(outputs[ch] || `Canal ${ch}`)}</span></th>`;
|
||||
});
|
||||
html += '</tr></thead><tbody>';
|
||||
|
||||
groups.forEach(g => {
|
||||
const gId = slugify(g.name);
|
||||
const gOutputs = groupToOutput[gId] || [];
|
||||
html += '<tr>';
|
||||
html += `<td class="matrix-channel-label">${escapeHtml(g.name)}</td>`;
|
||||
outputChannels.forEach(ch => {
|
||||
const checked = gOutputs.includes(ch) ? 'checked' : '';
|
||||
html += `<td class="matrix-cell"><input type="checkbox" class="routing-check" data-direction="output" data-channel="${ch}" data-group="${gId}" ${checked}></td>`;
|
||||
});
|
||||
html += '</tr>';
|
||||
});
|
||||
|
||||
html += '</tbody></table></div>';
|
||||
outputMatrixEl.innerHTML = html;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function saveRouting() {
|
||||
if (!routingData) return;
|
||||
|
||||
// Collecter les noms de canaux depuis le DOM
|
||||
const newChannelNames = { inputs: {}, outputs: {} };
|
||||
document.querySelectorAll('.channel-name-input[data-dir="input"]').forEach(el => {
|
||||
newChannelNames.inputs[el.dataset.channel] = el.value;
|
||||
@@ -1119,37 +1074,12 @@ async function saveRouting() {
|
||||
newChannelNames.outputs[el.dataset.channel] = el.value;
|
||||
});
|
||||
|
||||
// Collecter le routing depuis les checkboxes
|
||||
const newInputToGroup = {};
|
||||
const newGroupToOutput = {};
|
||||
|
||||
document.querySelectorAll('.routing-check[data-direction="input"]:checked').forEach(cb => {
|
||||
const ch = cb.dataset.channel;
|
||||
if (!newInputToGroup[ch]) newInputToGroup[ch] = [];
|
||||
if (!newInputToGroup[ch].includes(cb.dataset.group)) newInputToGroup[ch].push(cb.dataset.group);
|
||||
});
|
||||
|
||||
document.querySelectorAll('.routing-check[data-direction="output"]:checked').forEach(cb => {
|
||||
const g = cb.dataset.group;
|
||||
if (!newGroupToOutput[g]) newGroupToOutput[g] = [];
|
||||
if (!newGroupToOutput[g].includes(cb.dataset.channel)) newGroupToOutput[g].push(cb.dataset.channel);
|
||||
});
|
||||
|
||||
const newRouting = {
|
||||
...(routingData.routing || {}),
|
||||
inputToGroup: newInputToGroup,
|
||||
groupToOutput: newGroupToOutput
|
||||
};
|
||||
|
||||
const result = await window.electronAPI.routing.save({ routing: newRouting, channelNames: newChannelNames });
|
||||
const result = await window.electronAPI.routing.save({ channelNames: newChannelNames });
|
||||
|
||||
if (result.success) {
|
||||
routingData.routing = newRouting;
|
||||
routingData.channelNames = newChannelNames;
|
||||
renderRoutingView();
|
||||
showNotification('Routing sauvegardé', 'success');
|
||||
const note = document.getElementById('routing-server-note');
|
||||
if (note) note.classList.remove('hidden');
|
||||
showNotification('Noms de canaux sauvegardés', 'success');
|
||||
} else {
|
||||
showNotification('Erreur: ' + (result.error || 'Sauvegarde échouée'), 'error');
|
||||
}
|
||||
|
||||
+19
-37
@@ -126,15 +126,6 @@
|
||||
<button class="btn btn-primary" id="btn-save-device">Appliquer</button>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h3>🔗 Utilisateurs Audio Serveur</h3>
|
||||
<p class="config-note" style="margin-bottom: 1rem">Participants LiveKit côté serveur avec canaux physiques d'entrée et de sortie dédiés (mix-minus natif). Voir aussi la page <strong>Routing</strong> pour le câblage entre canaux et groupes.</p>
|
||||
<button class="btn btn-primary btn-small" id="btn-add-server-audio-user">➕ Ajouter</button>
|
||||
<div id="server-audio-users-list" class="groups-list" style="margin-top: 1rem">
|
||||
<p class="empty-state">Chargement...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h3>💾 Sauvegarde de configuration</h3>
|
||||
<div class="config-actions">
|
||||
@@ -179,25 +170,27 @@
|
||||
<div id="view-routing" class="view">
|
||||
<h2>Routing Audio</h2>
|
||||
|
||||
<!-- Noms des canaux -->
|
||||
<!-- Device info -->
|
||||
<div class="section">
|
||||
<h3>🏷️ Noms des Canaux</h3>
|
||||
<p class="config-note" style="margin-bottom: 1rem">Définissez les canaux physiques disponibles. Les matrices de routing se mettent à jour après la sauvegarde.</p>
|
||||
<div class="routing-device-banner">
|
||||
<div class="routing-device-info" id="routing-device-info">Chargement...</div>
|
||||
<button class="btn btn-small btn-secondary" id="btn-refresh-channels">🔄 Actualiser</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Labels canaux physiques -->
|
||||
<div class="section">
|
||||
<h3>🏷️ Canaux Physiques</h3>
|
||||
<p class="config-note">Labels des canaux de votre carte son. La liste est déterminée par le device sélectionné en <strong>Configuration</strong>.</p>
|
||||
<div class="channel-names-grid">
|
||||
<div class="channel-names-col">
|
||||
<div class="channel-names-col-header">
|
||||
<h4>Canaux Entrée</h4>
|
||||
<button class="btn btn-small btn-secondary" id="btn-add-input-channel">➕ Ajouter</button>
|
||||
</div>
|
||||
<h4>Entrées</h4>
|
||||
<div id="channel-names-inputs" class="channel-names-list">
|
||||
<p class="empty-state">Chargement...</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="channel-names-col">
|
||||
<div class="channel-names-col-header">
|
||||
<h4>Canaux Sortie</h4>
|
||||
<button class="btn btn-small btn-secondary" id="btn-add-output-channel">➕ Ajouter</button>
|
||||
</div>
|
||||
<h4>Sorties</h4>
|
||||
<div id="channel-names-outputs" class="channel-names-list">
|
||||
<p class="empty-state">Chargement...</p>
|
||||
</div>
|
||||
@@ -205,29 +198,18 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Matrice Entrées → Groupes -->
|
||||
<!-- Participants Serveur -->
|
||||
<div class="section">
|
||||
<h3>🎙️ Entrées → Groupes</h3>
|
||||
<p class="config-note" style="margin-bottom: 1rem">Quels canaux physiques d'entrée alimentent quels groupes LiveKit.</p>
|
||||
<div class="routing-matrix-wrapper" id="routing-input-matrix">
|
||||
<p class="empty-state">Chargement...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Matrice Groupes → Sorties -->
|
||||
<div class="section">
|
||||
<h3>🔊 Groupes → Sorties</h3>
|
||||
<p class="config-note" style="margin-bottom: 1rem">Vers quels canaux physiques de sortie chaque groupe est routé.</p>
|
||||
<div class="routing-matrix-wrapper" id="routing-output-matrix">
|
||||
<p class="empty-state">Chargement...</p>
|
||||
</div>
|
||||
<h3>🎙️ Participants Serveur</h3>
|
||||
<p class="config-note">Participants LiveKit côté serveur — chaque ligne branche des canaux physiques d'E/S sur un groupe.</p>
|
||||
<button class="btn btn-primary btn-small" id="btn-add-server-audio-user">➕ Ajouter</button>
|
||||
<div id="server-audio-users-list" class="sau-list"></div>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="routing-actions">
|
||||
<button class="btn btn-primary" id="btn-save-routing">Sauvegarder</button>
|
||||
<button class="btn btn-primary" id="btn-save-routing">Sauvegarder noms de canaux</button>
|
||||
<button class="btn btn-secondary" id="btn-reload-routing">Recharger</button>
|
||||
<span class="config-note routing-restart-note hidden" id="routing-server-note">⚠️ Redémarrez le serveur pour appliquer les changements.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+122
-16
@@ -893,7 +893,54 @@ body {
|
||||
background: rgba(74, 158, 255, 0.05);
|
||||
}
|
||||
|
||||
/* Channel Names Editor */
|
||||
/* Device banner */
|
||||
|
||||
.routing-device-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
padding: 0.75rem 1rem;
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.routing-device-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.device-entry {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
.device-sep {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.device-ch-badge {
|
||||
display: inline-block;
|
||||
background: var(--accent-primary);
|
||||
color: #fff;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 600;
|
||||
padding: 0.1rem 0.4rem;
|
||||
border-radius: 10px;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.device-unset {
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
/* Channel labels */
|
||||
|
||||
.channel-names-grid {
|
||||
display: grid;
|
||||
@@ -901,21 +948,14 @@ body {
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.channel-names-col-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 0.75rem;
|
||||
padding-bottom: 0.5rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.channel-names-col-header h4 {
|
||||
font-size: 0.875rem;
|
||||
.channel-names-col h4 {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--text-secondary);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
margin: 0;
|
||||
margin: 0 0 0.75rem;
|
||||
padding-bottom: 0.5rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.channel-names-list {
|
||||
@@ -931,13 +971,79 @@ body {
|
||||
}
|
||||
|
||||
.channel-index {
|
||||
min-width: 58px;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--text-secondary);
|
||||
min-width: 40px;
|
||||
font-size: 0.8rem;
|
||||
color: var(--accent-primary);
|
||||
font-family: 'Courier New', monospace;
|
||||
font-weight: 600;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Server Audio Users table */
|
||||
|
||||
.sau-list {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.sau-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.sau-table th {
|
||||
background: var(--bg-tertiary);
|
||||
padding: 0.5rem 0.75rem;
|
||||
text-align: left;
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.sau-table td {
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.sau-table tbody tr:hover td {
|
||||
background: rgba(74, 158, 255, 0.04);
|
||||
}
|
||||
|
||||
.sau-name {
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.sau-actions {
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.ch-badge {
|
||||
display: inline-block;
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-color);
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.78rem;
|
||||
padding: 0.1rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
|
||||
.ch-badge-group {
|
||||
background: rgba(74, 158, 255, 0.12);
|
||||
border-color: rgba(74, 158, 255, 0.3);
|
||||
color: var(--accent-primary);
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
/* Routing actions bar */
|
||||
|
||||
.routing-actions {
|
||||
|
||||
@@ -17,8 +17,6 @@ import JACKBackend from './backends/JACKBackend.js';
|
||||
import PipeWireBackend from './backends/PipeWireBackend.js';
|
||||
import OpusCodec, { OpusPresets } from './OpusCodec.js';
|
||||
import JitterBuffer, { JitterBufferPresets } from './JitterBuffer.js';
|
||||
import LiveKitClient from './LiveKitClient.js';
|
||||
import GroupAudioRouter from './GroupAudioRouter.js';
|
||||
import ServerAudioUser from './ServerAudioUser.js';
|
||||
|
||||
export class AudioBridge extends EventEmitter {
|
||||
@@ -55,8 +53,6 @@ export class AudioBridge extends EventEmitter {
|
||||
this.opusEncoder = null;
|
||||
this.opusDecoder = null;
|
||||
this.jitterBuffer = null;
|
||||
this.liveKitClients = new Map(); // Map<groupName, LiveKitClient> - un client par groupe
|
||||
this.groupAudioRouter = null;
|
||||
|
||||
// État
|
||||
this.isRunning = false;
|
||||
@@ -64,10 +60,6 @@ export class AudioBridge extends EventEmitter {
|
||||
|
||||
// Buffers pour routing multi-canaux
|
||||
this.inputChannelBuffers = new Map(); // Map<channelId, Float32Array>
|
||||
this.groupBuffersFromLiveKit = new Map(); // Map<groupName, Float32Array>
|
||||
|
||||
// Frame accumulators pour LiveKit (240 samples → 960 samples)
|
||||
this.liveKitFrameAccumulators = new Map(); // Map<groupName, { buffer: Float32Array, offset: number }>
|
||||
|
||||
// Utilisateurs audio gérés côté serveur (participants LiveKit avec I/O physique dédiés)
|
||||
this.serverAudioUsers = new Map(); // Map<name, ServerAudioUser>
|
||||
@@ -118,16 +110,10 @@ export class AudioBridge extends EventEmitter {
|
||||
// 3. Initialisation du jitter buffer
|
||||
this._initJitterBuffer();
|
||||
|
||||
// 4. Initialisation du GroupAudioRouter
|
||||
this._initGroupAudioRouter();
|
||||
|
||||
// 5. Connexion à LiveKit
|
||||
await this._initLiveKit();
|
||||
|
||||
// 6. Initialisation des server audio users
|
||||
// 4. Initialisation des server audio users
|
||||
await this._initServerAudioUsers();
|
||||
|
||||
// 7. Démarrage du routing audio
|
||||
// 5. Démarrage du routing audio
|
||||
await this._startAudioRouting();
|
||||
|
||||
this.isRunning = true;
|
||||
@@ -307,92 +293,6 @@ export class AudioBridge extends EventEmitter {
|
||||
console.log(`✓ Jitter buffer : cible ${bufferConfig.targetSize} frames`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise le GroupAudioRouter pour le routing multi-canaux
|
||||
* @private
|
||||
*/
|
||||
_initGroupAudioRouter() {
|
||||
this.groupAudioRouter = new GroupAudioRouter({
|
||||
sampleRate: this.options.sampleRate,
|
||||
frameSize: this.options.frameSize,
|
||||
maxInputChannels: this.options.maxInputChannels || 32,
|
||||
maxOutputChannels: this.options.maxOutputChannels || 32,
|
||||
groups: this.options.groups || []
|
||||
});
|
||||
|
||||
// Charger la configuration de routing depuis les options
|
||||
if (this.options.routing) {
|
||||
this.groupAudioRouter.configure(this.options.routing);
|
||||
}
|
||||
|
||||
// Events du router
|
||||
this.groupAudioRouter.on('configured', (stats) => {
|
||||
console.log(`✓ GroupAudioRouter configuré : ${stats.routesActive} routes`);
|
||||
});
|
||||
|
||||
console.log('✓ GroupAudioRouter initialisé');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise les connexions LiveKit (une par groupe)
|
||||
* @private
|
||||
*/
|
||||
async _initLiveKit() {
|
||||
if (!this.options.liveKitTokens || !Array.isArray(this.options.liveKitTokens)) {
|
||||
throw new Error('liveKitTokens requis (tableau d\'objets { groupName, groupId, token })');
|
||||
}
|
||||
|
||||
console.log(`🔌 Initialisation ${this.options.liveKitTokens.length} connexions LiveKit (une par groupe)...`);
|
||||
|
||||
// Créer un LiveKitClient pour chaque groupe
|
||||
for (const { groupName, groupId, token } of this.options.liveKitTokens) {
|
||||
const roomName = groupId; // La room porte le nom du groupId (slugifié)
|
||||
|
||||
const client = new LiveKitClient({
|
||||
url: this.options.liveKitUrl,
|
||||
token,
|
||||
roomName,
|
||||
participantName: `AudioBridge-${groupId}`,
|
||||
sampleRate: this.options.sampleRate,
|
||||
channels: this.options.channels,
|
||||
audioBitrate: this.opusEncoder.options.bitrate
|
||||
});
|
||||
|
||||
// Events LiveKit pour ce groupe
|
||||
client.on('connected', () => {
|
||||
console.log(`✓ LiveKit connecté pour groupe "${groupName}" (room: ${roomName})`);
|
||||
});
|
||||
|
||||
client.on('disconnected', (data) => {
|
||||
const reason = data?.reason || 'unknown';
|
||||
console.warn(`⚠️ LiveKit déconnecté pour groupe "${groupName}":`, reason);
|
||||
this.stats.errors.network++;
|
||||
});
|
||||
|
||||
client.on('reconnecting', () => {
|
||||
console.log(`🔄 LiveKit reconnexion pour groupe "${groupName}"...`);
|
||||
});
|
||||
|
||||
client.on('audioTrackSubscribed', ({ track, participant }) => {
|
||||
console.log(`🎵 Nouveau track audio dans groupe "${groupName}": ${participant.identity}`);
|
||||
});
|
||||
|
||||
// Réception audio depuis les clients LiveKit de ce groupe
|
||||
client.on('audioData', ({ participantName, pcmData, sampleRate, channels }) => {
|
||||
// Router vers le bon groupe
|
||||
this.emit('groupAudioIn', { groupName: groupId, pcmBuffer: pcmData });
|
||||
});
|
||||
|
||||
// Connexion
|
||||
await client.connect();
|
||||
|
||||
// Stocker le client par groupId
|
||||
this.liveKitClients.set(groupId, client);
|
||||
}
|
||||
|
||||
console.log(`✓ ${this.liveKitClients.size} connexions LiveKit établies`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise les utilisateurs audio serveur (participants LiveKit avec I/O physique)
|
||||
* @private
|
||||
@@ -445,44 +345,31 @@ export class AudioBridge extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Démarre le routing audio bidirectionnel complet
|
||||
* Démarre le routing audio : capture physique → server audio users
|
||||
* @private
|
||||
*/
|
||||
async _startAudioRouting() {
|
||||
console.log('🔄 Démarrage routing audio bidirectionnel...');
|
||||
console.log('🔄 Démarrage routing audio...');
|
||||
|
||||
// ===== FLUX 1 : CAPTURE (Carte Son → Groupes → LiveKit → Clients) =====
|
||||
this.audioBackend.on('audioData', (pcmData) => {
|
||||
try {
|
||||
// Convertir PCM Buffer → Float32Array (pour GroupAudioRouter)
|
||||
const float32Data = this._bufferToFloat32(pcmData);
|
||||
|
||||
// Séparer les canaux si audio multi-canaux (entrelacé)
|
||||
const numChannels = this.options.channels || 1;
|
||||
|
||||
if (numChannels === 1) {
|
||||
// Mono : un seul canal
|
||||
const channelId = this.options.inputDeviceChannel || 0;
|
||||
this.inputChannelBuffers.set(channelId, float32Data);
|
||||
this.inputChannelBuffers.set(0, float32Data);
|
||||
} else {
|
||||
// Multi-canaux : dé-entrelacer les samples
|
||||
// Format entrelacé : [L0, R0, L1, R1, ...] → [L0, L1, ...] et [R0, R1, ...]
|
||||
const samplesPerChannel = float32Data.length / numChannels;
|
||||
|
||||
for (let ch = 0; ch < numChannels; ch++) {
|
||||
const channelBuffer = new Float32Array(samplesPerChannel);
|
||||
|
||||
for (let i = 0; i < samplesPerChannel; i++) {
|
||||
channelBuffer[i] = float32Data[i * numChannels + ch];
|
||||
}
|
||||
|
||||
// Mapper canal hardware → canal logique (peut être configuré)
|
||||
const logicalChannelId = this.options.channelMapping?.[ch] ?? ch;
|
||||
this.inputChannelBuffers.set(logicalChannelId, channelBuffer);
|
||||
this.inputChannelBuffers.set(ch, channelBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
// ÉTAPE 0 : Envoyer les données de chaque canal vers les server audio users
|
||||
// Alimenter chaque server audio user avec son canal d'entrée
|
||||
for (const [, user] of this.serverAudioUsers) {
|
||||
const channelData = this.inputChannelBuffers.get(user.inputChannel);
|
||||
if (channelData) {
|
||||
@@ -490,206 +377,18 @@ export class AudioBridge extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
// ÉTAPE 1 : Inputs physiques → Groupes (via GroupAudioRouter)
|
||||
const groupBuffers = this.groupAudioRouter.processInputsToGroups(
|
||||
this.inputChannelBuffers
|
||||
);
|
||||
|
||||
if (this.stats.framesCapture % 100 === 0) {
|
||||
// Détecter si l'audio est du silence (toutes les samples < 0.001)
|
||||
let totalEnergy = 0;
|
||||
this.inputChannelBuffers.forEach((buffer) => {
|
||||
for (let i = 0; i < buffer.length; i++) {
|
||||
totalEnergy += Math.abs(buffer[i]);
|
||||
}
|
||||
});
|
||||
const avgEnergy = totalEnergy / (this.inputChannelBuffers.size * (this.options.frameSize || 960));
|
||||
console.log(`[AudioBridge] Frame ${this.stats.framesCapture}: ${this.inputChannelBuffers.size} inputs → ${groupBuffers.size} groupes | Énergie audio: ${avgEnergy.toFixed(6)}`);
|
||||
}
|
||||
|
||||
// ÉTAPE 2 : Pour chaque groupe, envoyer vers le LiveKitClient correspondant
|
||||
groupBuffers.forEach((groupBuffer, groupName) => {
|
||||
// Les groupes sont MONO (Float32Array de N samples)
|
||||
// Mais la config globale peut être STÉRÉO (channels=2)
|
||||
// → Adapter selon la configuration
|
||||
|
||||
let pcmBuffer;
|
||||
const configChannels = this.options.channels || 1;
|
||||
|
||||
if (configChannels === 1) {
|
||||
// Config MONO : envoyer directement
|
||||
pcmBuffer = this._float32ToBuffer(groupBuffer);
|
||||
} else if (configChannels === 2) {
|
||||
// Config STÉRÉO : dupliquer le canal mono
|
||||
const samplesPerChannel = groupBuffer.length;
|
||||
const stereoBuffer = new Float32Array(samplesPerChannel * 2);
|
||||
|
||||
// Entrelacer : [M0, M1, M2, ...] → [M0, M0, M1, M1, M2, M2, ...]
|
||||
for (let i = 0; i < samplesPerChannel; i++) {
|
||||
stereoBuffer[i * 2] = groupBuffer[i]; // Canal gauche
|
||||
stereoBuffer[i * 2 + 1] = groupBuffer[i]; // Canal droit (dupliqué)
|
||||
}
|
||||
|
||||
pcmBuffer = this._float32ToBuffer(stereoBuffer);
|
||||
} else {
|
||||
console.error(`❌ Nombre de canaux non supporté: ${configChannels}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Récupérer le client LiveKit pour ce groupe
|
||||
const client = this.liveKitClients.get(groupName);
|
||||
|
||||
// Envoi vers LiveKit via sendAudioData (prend du PCM 16-bit)
|
||||
// Note: LiveKit gère lui-même l'encodage Opus en interne
|
||||
if (client && client.isConnected) {
|
||||
client.sendAudioData(pcmBuffer);
|
||||
if (this.stats.framesCapture % 100 === 0) {
|
||||
const channelLabel = configChannels === 1 ? 'mono' : `${configChannels}ch`;
|
||||
console.log(`[AudioBridge] → LiveKit groupe "${groupName}": ${pcmBuffer.length} bytes (${channelLabel})`);
|
||||
}
|
||||
} else {
|
||||
if (this.stats.framesCapture % 100 === 0) {
|
||||
console.log(`[AudioBridge] ⚠️ LiveKit non connecté pour groupe "${groupName}", audio non envoyé`);
|
||||
}
|
||||
}
|
||||
|
||||
// Émettre aussi pour monitoring/debug
|
||||
this.emit('groupAudioOut', { groupName, pcmBuffer });
|
||||
});
|
||||
|
||||
// ÉTAPE 3 : Loopback local - Groupes → Outputs physiques (sans passer par LiveKit)
|
||||
const outputBuffers = this.groupAudioRouter.processGroupsToOutputs(groupBuffers);
|
||||
|
||||
if (this.stats.framesCapture % 100 === 0) {
|
||||
console.log(`[AudioBridge] Loopback local: ${groupBuffers.size} groupes → ${outputBuffers.size} outputs`);
|
||||
}
|
||||
|
||||
// ÉTAPE 4 : Envoyer chaque output à la carte son
|
||||
const numOutputChannels = this.options.channels || 1;
|
||||
|
||||
if (numOutputChannels === 1) {
|
||||
// Mono : un seul output
|
||||
if (outputBuffers.size > 0) {
|
||||
const [firstChannelId, outputBuffer] = outputBuffers.entries().next().value;
|
||||
const pcmBuffer = this._float32ToBuffer(outputBuffer);
|
||||
this.audioBackend.queueAudio(pcmBuffer);
|
||||
|
||||
if (this.stats.framesCapture % 100 === 0) {
|
||||
console.log(`[AudioBridge] → Output mono (canal ${firstChannelId}): ${pcmBuffer.length} bytes`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Multi-canaux : entrelacer les samples
|
||||
// Récupérer les buffers dans l'ordre des canaux hardware
|
||||
const channelBuffers = [];
|
||||
const samplesPerChannel = this.options.frameSize;
|
||||
|
||||
for (let ch = 0; ch < numOutputChannels; ch++) {
|
||||
const logicalChannelId = this.options.channelMapping?.[ch] ?? ch;
|
||||
const buffer = outputBuffers.get(logicalChannelId);
|
||||
|
||||
if (buffer && buffer.length === samplesPerChannel) {
|
||||
channelBuffers.push(buffer);
|
||||
} else {
|
||||
// Canal absent ou taille incorrecte : silence
|
||||
channelBuffers.push(new Float32Array(samplesPerChannel));
|
||||
}
|
||||
}
|
||||
|
||||
// Entrelacer : [L0, L1, ...] et [R0, R1, ...] → [L0, R0, L1, R1, ...]
|
||||
const interleavedBuffer = new Float32Array(samplesPerChannel * numOutputChannels);
|
||||
|
||||
for (let i = 0; i < samplesPerChannel; i++) {
|
||||
for (let ch = 0; ch < numOutputChannels; ch++) {
|
||||
interleavedBuffer[i * numOutputChannels + ch] = channelBuffers[ch][i];
|
||||
}
|
||||
}
|
||||
|
||||
const pcmBuffer = this._float32ToBuffer(interleavedBuffer);
|
||||
this.audioBackend.queueAudio(pcmBuffer);
|
||||
|
||||
if (this.stats.framesCapture % 100 === 0) {
|
||||
console.log(`[AudioBridge] → Output multi-canaux (${numOutputChannels}ch): ${pcmBuffer.length} bytes`);
|
||||
}
|
||||
}
|
||||
|
||||
this.stats.framesCapture++;
|
||||
this.stats.framesPlayback++;
|
||||
} catch (error) {
|
||||
console.error('Erreur routing capture:', error);
|
||||
this.stats.errors.capture++;
|
||||
}
|
||||
});
|
||||
|
||||
// ===== FLUX 2 : LECTURE (Clients → LiveKit → Groupes → Carte Son) =====
|
||||
|
||||
// Écouter l'audio entrant de LiveKit (sera connecté par LiveKitServerBridge)
|
||||
this.on('groupAudioIn', ({ groupName, pcmBuffer }) => {
|
||||
try {
|
||||
// Convertir PCM Buffer → Float32Array
|
||||
const float32Data = this._bufferToFloat32(pcmBuffer);
|
||||
const samplesReceived = float32Data.length;
|
||||
|
||||
// Initialiser l'accumulateur pour ce groupe si nécessaire
|
||||
if (!this.liveKitFrameAccumulators.has(groupName)) {
|
||||
this.liveKitFrameAccumulators.set(groupName, {
|
||||
buffer: new Float32Array(960), // Frame size attendu par GroupRouter
|
||||
offset: 0
|
||||
});
|
||||
}
|
||||
|
||||
const accumulator = this.liveKitFrameAccumulators.get(groupName);
|
||||
|
||||
// Vérifier que le buffer ne débordera pas
|
||||
const availableSpace = 960 - accumulator.offset;
|
||||
const samplesToCopy = Math.min(samplesReceived, availableSpace);
|
||||
|
||||
// Copier les samples dans l'accumulateur
|
||||
if (samplesToCopy > 0) {
|
||||
accumulator.buffer.set(float32Data.subarray(0, samplesToCopy), accumulator.offset);
|
||||
accumulator.offset += samplesToCopy;
|
||||
}
|
||||
|
||||
// Si on a accumulé assez de samples (960), router vers les outputs
|
||||
if (accumulator.offset >= 960) {
|
||||
// Vérifier que le backend est toujours actif (évite crash pendant shutdown)
|
||||
if (!this.audioBackend) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Stocker le buffer complet pour le routing
|
||||
this.groupBuffersFromLiveKit.set(groupName, accumulator.buffer);
|
||||
|
||||
// ÉTAPE 3 : Groupes → Outputs physiques (via GroupAudioRouter)
|
||||
const outputBuffers = this.groupAudioRouter.processGroupsToOutputs(
|
||||
this.groupBuffersFromLiveKit
|
||||
);
|
||||
|
||||
// ÉTAPE 4 : Envoyer chaque output à la carte son
|
||||
outputBuffers.forEach((outputBuffer, channelId) => {
|
||||
const pcmBuffer = this._float32ToBuffer(outputBuffer);
|
||||
this.audioBackend.queueAudio(pcmBuffer);
|
||||
});
|
||||
|
||||
// Réinitialiser l'accumulateur
|
||||
accumulator.offset = 0;
|
||||
accumulator.buffer.fill(0);
|
||||
|
||||
this.stats.framesPlayback++;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erreur routing lecture:', error);
|
||||
this.stats.errors.playback++;
|
||||
}
|
||||
});
|
||||
|
||||
// Démarrage des streams audio
|
||||
await this.audioBackend.startCapture();
|
||||
await this.audioBackend.startPlayback();
|
||||
|
||||
console.log('✓ Routing audio bidirectionnel actif');
|
||||
console.log(' → Carte Son → GroupRouter → LiveKit → Clients');
|
||||
console.log(' ← Carte Son ← GroupRouter ← LiveKit ← Clients');
|
||||
console.log('✓ Routing audio actif');
|
||||
console.log(' → Carte Son → Server Audio Users → LiveKit → Clients');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -819,13 +518,6 @@ export class AudioBridge extends EventEmitter {
|
||||
this.audioBackend = null;
|
||||
}
|
||||
|
||||
// Déconnecter tous les clients LiveKit
|
||||
for (const [groupName, client] of this.liveKitClients.entries()) {
|
||||
console.log(`🔌 Déconnexion LiveKit groupe "${groupName}"...`);
|
||||
await client.destroy();
|
||||
}
|
||||
this.liveKitClients.clear();
|
||||
|
||||
// Arrêter les server audio users
|
||||
for (const [name, user] of this.serverAudioUsers.entries()) {
|
||||
console.log(`🔌 Arrêt server audio user "${name}"...`);
|
||||
@@ -833,11 +525,6 @@ export class AudioBridge extends EventEmitter {
|
||||
}
|
||||
this.serverAudioUsers.clear();
|
||||
|
||||
if (this.groupAudioRouter) {
|
||||
this.groupAudioRouter.destroy();
|
||||
this.groupAudioRouter = null;
|
||||
}
|
||||
|
||||
if (this.jitterBuffer) {
|
||||
this.jitterBuffer.destroy();
|
||||
this.jitterBuffer = null;
|
||||
@@ -855,7 +542,6 @@ export class AudioBridge extends EventEmitter {
|
||||
|
||||
// Nettoyer les buffers
|
||||
this.inputChannelBuffers.clear();
|
||||
this.groupBuffersFromLiveKit.clear();
|
||||
|
||||
// Nettoyer le pool de buffers
|
||||
this.bufferPool.float32 = [];
|
||||
|
||||
@@ -34,15 +34,12 @@ class AudioBridgeManager extends EventEmitter {
|
||||
const config = configManager.get();
|
||||
console.log('🎵 Démarrage AudioBridge avec configuration:', config.audio);
|
||||
|
||||
// Générer un token JWT par groupe
|
||||
const liveKitTokens = [];
|
||||
|
||||
// Fonction pour slugifier le nom (identique à admin.js)
|
||||
const slugify = (text) => {
|
||||
return text
|
||||
.toString()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.replace(/[̀-ͯ]/g, '')
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/\s+/g, '-')
|
||||
@@ -50,45 +47,6 @@ class AudioBridgeManager extends EventEmitter {
|
||||
.replace(/--+/g, '-');
|
||||
};
|
||||
|
||||
for (const group of config.groups || []) {
|
||||
const groupId = slugify(group.name);
|
||||
const groupName = group.name;
|
||||
|
||||
const token = new AccessToken(
|
||||
config.server?.livekit?.apiKey || 'devkey',
|
||||
config.server?.livekit?.apiSecret || 'secret',
|
||||
{
|
||||
identity: `AudioBridge-${groupId}`,
|
||||
name: `Audio Bridge - ${groupName}`,
|
||||
metadata: JSON.stringify({
|
||||
role: 'bridge',
|
||||
group: groupId,
|
||||
capabilities: ['audio-routing', 'monitoring']
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
// Permissions complètes pour ce groupe
|
||||
token.addGrant({
|
||||
room: groupId, // Chaque groupe a sa propre room
|
||||
roomJoin: true,
|
||||
canPublish: true,
|
||||
canSubscribe: true,
|
||||
canPublishData: true
|
||||
});
|
||||
|
||||
const jwt = await token.toJwt();
|
||||
liveKitTokens.push({ groupName, groupId, token: jwt });
|
||||
|
||||
console.log(`✓ Token JWT généré pour groupe "${groupName}" (room: ${groupId})`);
|
||||
}
|
||||
|
||||
if (liveKitTokens.length === 0) {
|
||||
console.warn('⚠️ Aucun groupe configuré, AudioBridge ne pourra pas démarrer');
|
||||
this.isRunning = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Générer un token JWT par server audio user
|
||||
const serverAudioUsers = [];
|
||||
|
||||
@@ -118,11 +76,13 @@ class AudioBridgeManager extends EventEmitter {
|
||||
|
||||
const jwt = await token.toJwt();
|
||||
|
||||
const outputChannel = user.output_channel ?? user.outputChannel;
|
||||
|
||||
serverAudioUsers.push({
|
||||
name: user.name,
|
||||
groupId,
|
||||
inputChannel: user.input_channel ?? user.inputChannel ?? 0,
|
||||
outputChannel: user.output_channel ?? user.outputChannel ?? 0,
|
||||
outputChannel: outputChannel !== null && outputChannel !== undefined ? outputChannel : null,
|
||||
token: jwt
|
||||
});
|
||||
|
||||
@@ -160,17 +120,11 @@ class AudioBridgeManager extends EventEmitter {
|
||||
// Créer l'instance avec la config
|
||||
this.bridge = new AudioBridge({
|
||||
...audioConfig,
|
||||
// Options LiveKit (multi-rooms)
|
||||
liveKitUrl,
|
||||
liveKitTokens, // Tableau de { groupName, groupId, token }
|
||||
// Server audio users
|
||||
serverAudioUsers,
|
||||
// Options de routing
|
||||
routing: config.audio?.routing || {},
|
||||
groups: config.groups || [],
|
||||
maxInputChannels: 32,
|
||||
maxOutputChannels: 32,
|
||||
// Device IDs extraits
|
||||
inputDeviceId,
|
||||
outputDeviceId
|
||||
});
|
||||
|
||||
@@ -18,7 +18,9 @@ class ServerAudioUser extends EventEmitter {
|
||||
|
||||
this.name = options.name;
|
||||
this.inputChannel = parseInt(options.inputChannel, 10);
|
||||
this.outputChannel = parseInt(options.outputChannel, 10);
|
||||
this.outputChannel = (options.outputChannel !== null && options.outputChannel !== undefined)
|
||||
? parseInt(options.outputChannel, 10)
|
||||
: null;
|
||||
this.groupId = options.groupId;
|
||||
this.frameSize = options.frameSize || 960;
|
||||
this.sampleRate = options.sampleRate || 48000;
|
||||
@@ -43,7 +45,7 @@ class ServerAudioUser extends EventEmitter {
|
||||
|
||||
_setupClientEvents() {
|
||||
this.client.on('connected', () => {
|
||||
console.log(`[ServerAudioUser:${this.name}] Connecté à room "${this.groupId}" (in:${this.inputChannel} → out:${this.outputChannel})`);
|
||||
console.log(`[ServerAudioUser:${this.name}] Connecté à room "${this.groupId}" (in:${this.inputChannel} → out:${this.outputChannel ?? 'aucune'})`);
|
||||
this.emit('connected');
|
||||
});
|
||||
|
||||
@@ -139,8 +141,10 @@ class ServerAudioUser extends EventEmitter {
|
||||
}
|
||||
|
||||
this.mixedOutput = mix;
|
||||
if (this.outputChannel !== null) {
|
||||
this.emit('outputReady', mix);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convertit Buffer/Int16Array PCM 16-bit → Float32Array [-1.0, 1.0]
|
||||
|
||||
+12
-45
@@ -6,55 +6,22 @@ audio:
|
||||
jitterBufferMs: 40
|
||||
device:
|
||||
inputDeviceId: Loopback Audio 4
|
||||
outputDeviceId: Haut-parleurs MacBook Pro
|
||||
outputDeviceId: Périphérique agrégé
|
||||
sampleRate: 48000
|
||||
routing:
|
||||
inputToGroup:
|
||||
"0":
|
||||
- default
|
||||
"1": []
|
||||
"2": []
|
||||
"4":
|
||||
- technique
|
||||
"5":
|
||||
- technique
|
||||
groupToOutput:
|
||||
technique:
|
||||
- "1"
|
||||
production:
|
||||
- "0"
|
||||
- "1"
|
||||
default:
|
||||
- "0"
|
||||
gains: {}
|
||||
channelNames:
|
||||
inputs:
|
||||
"0": Mac
|
||||
"1": Talkback FOH
|
||||
"2": Retour Console
|
||||
"3": Liaison Scène
|
||||
"4": Monitor Mix
|
||||
"5": Spare 1
|
||||
"0": Loopback L
|
||||
"1": Loopback R
|
||||
outputs:
|
||||
"0": L
|
||||
"1": R
|
||||
"2": Talkback Console
|
||||
# Utilisateurs audio gérés côté serveur.
|
||||
# Chaque entrée crée un participant LiveKit indépendant avec un canal physique
|
||||
# d'entrée (microphone/ligne) et un canal physique de sortie dédié (mix-minus naturel).
|
||||
#
|
||||
# Exemple (décommenter et adapter) :
|
||||
# server_audio_users:
|
||||
# - name: foh
|
||||
# group: default # ID du groupe LiveKit (room) à rejoindre
|
||||
# input_channel: 1 # Index canal physique d'entrée (depuis inputDeviceId)
|
||||
# output_channel: 2 # Index canal physique de sortie (vers outputDeviceId)
|
||||
# - name: returns
|
||||
# group: default
|
||||
# input_channel: 2
|
||||
# output_channel: 3
|
||||
server_audio_users: []
|
||||
|
||||
"0": Casque L
|
||||
"1": Casque R
|
||||
"2": Mac L
|
||||
"3": Mac R
|
||||
server_audio_users:
|
||||
- name: Utilisateur Serveur
|
||||
group: default
|
||||
input_channel: 0
|
||||
output_channel: 0
|
||||
groups:
|
||||
- name: Default
|
||||
audioBitrate: 96
|
||||
|
||||
+1
-19
@@ -334,30 +334,12 @@ apiRouter.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,
|
||||
virtualChannels
|
||||
virtualChannels: []
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user