Files
vue-pult/server/simple-linux-radio.js
sasha 3e90269b0b Initial commit: Vue.js тир управления система
- Клиентская часть Vue 3 + Vite
- Серверная часть Node.js + WebSocket
- Система авторизации и смен
- Управление игровыми портами
- Поддержка тем (светлая/темная)
- Адаптивный дизайн

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-19 12:24:22 +03:00

111 lines
3.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Простейший радио плеер для Linux - для отладки
const { spawn } = require('child_process');
class SimpleLinuxRadio {
constructor() {
this.process = null;
this.volume = 70;
}
play(url) {
this.stop();
console.log('[SIMPLE-RADIO] 🎵 Запуск радио:', url);
console.log('[SIMPLE-RADIO] 📊 Громкость:', this.volume);
// Метод 1: Прямой запуск mpg123
try {
this.process = spawn('mpg123', [url], {
stdio: ['ignore', 'pipe', 'pipe']
});
this.process.stdout.on('data', (data) => {
console.log('[SIMPLE-RADIO] stdout:', data.toString());
});
this.process.stderr.on('data', (data) => {
console.log('[SIMPLE-RADIO] stderr:', data.toString());
});
this.process.on('error', (error) => {
console.error('[SIMPLE-RADIO] ❌ Ошибка mpg123:', error.message);
// Пробуем альтернативный метод
console.log('[SIMPLE-RADIO] 🔄 Пробуем альтернативный метод...');
this.playAlternative(url);
});
this.process.on('exit', (code) => {
console.log('[SIMPLE-RADIO] Процесс завершен с кодом:', code);
});
} catch (e) {
console.error('[SIMPLE-RADIO] ❌ Не удалось запустить mpg123:', e);
this.playAlternative(url);
}
}
playAlternative(url) {
// Метод 2: Через ffplay (обычно доступен)
try {
this.process = spawn('ffplay', [
'-nodisp',
'-autoexit',
'-loglevel', 'error',
url
], {
stdio: ['ignore', 'pipe', 'pipe']
});
console.log('[SIMPLE-RADIO] 🎵 Используем ffplay');
this.process.on('error', (error) => {
console.error('[SIMPLE-RADIO] ❌ ffplay тоже не работает:', error.message);
console.log('[SIMPLE-RADIO] 💡 Установите плеер: sudo apt install mpg123 ffmpeg');
});
} catch (e) {
console.error('[SIMPLE-RADIO] ❌ Критическая ошибка:', e);
}
}
stop() {
if (this.process) {
console.log('[SIMPLE-RADIO] ⏹️ Остановка радио');
try {
this.process.kill();
} catch (e) {
console.error('[SIMPLE-RADIO] Ошибка остановки:', e);
}
this.process = null;
}
}
setVolume(vol) {
this.volume = vol;
console.log('[SIMPLE-RADIO] 🔊 Громкость изменена на:', vol);
// В простой версии просто сохраняем значение
}
}
// Тестовая функция
function testRadio() {
const radio = new SimpleLinuxRadio();
const testUrl = 'http://air.radiorecord.ru:8102/dub_320';
console.log('[TEST] Запускаем тест радио...');
radio.play(testUrl);
setTimeout(() => {
console.log('[TEST] Останавливаем через 5 секунд...');
radio.stop();
}, 5000);
}
// Экспортируем для использования
module.exports = { SimpleLinuxRadio };
// Если запущен напрямую - тестируем
if (require.main === module) {
testRadio();
}