Add codec support check and better buffering status for listener

This commit is contained in:
3nd3r
2026-01-02 21:44:55 -06:00
parent 1a1f389ab7
commit 41d2d57b7e

View File

@@ -2133,8 +2133,18 @@ function initListenerMode() {
mediaSource.addEventListener('sourceopen', () => { mediaSource.addEventListener('sourceopen', () => {
console.log('📦 MediaSource opened'); console.log('📦 MediaSource opened');
const mimeType = 'audio/webm;codecs=opus';
if (!MediaSource.isTypeSupported(mimeType)) {
console.error(`❌ Browser does not support ${mimeType}`);
const statusEl = document.getElementById('connection-status');
if (statusEl) statusEl.textContent = '❌ Error: Browser does not support WebM/Opus audio';
alert('Your browser does not support WebM/Opus audio format. Please try Chrome, Firefox, or Edge.');
return;
}
try { try {
sourceBuffer = mediaSource.addSourceBuffer('audio/webm;codecs=opus'); sourceBuffer = mediaSource.addSourceBuffer(mimeType);
sourceBuffer.mode = 'sequence'; sourceBuffer.mode = 'sequence';
// Kick off first append if data is already in queue // Kick off first append if data is already in queue
@@ -2337,7 +2347,9 @@ async function enableListenerAudio() {
// If no buffered data yet, wait a bit for it to arrive // If no buffered data yet, wait a bit for it to arrive
if (!hasBufferedData()) { if (!hasBufferedData()) {
console.log('⏳ Waiting for audio data to buffer...'); console.log('⏳ Waiting for audio data to buffer...');
if (audioText) audioText.textContent = 'WAITING FOR STREAM...'; if (audioText) {
audioText.textContent = chunksReceived > 0 ? 'BUFFERING...' : 'WAITING FOR STREAM...';
}
// Wait up to 10 seconds for data to arrive (increased from 5) // Wait up to 10 seconds for data to arrive (increased from 5)
const waitForData = new Promise((resolve) => { const waitForData = new Promise((resolve) => {
@@ -2347,6 +2359,10 @@ async function enableListenerAudio() {
const checkInterval = setInterval(() => { const checkInterval = setInterval(() => {
attempts++; attempts++;
if (audioText && chunksReceived > 0 && audioText.textContent === 'WAITING FOR STREAM...') {
audioText.textContent = 'BUFFERING...';
}
if (attempts % 10 === 0) { // Log every second if (attempts % 10 === 0) { // Log every second
console.log(`⏱️ Attempt ${attempts}/${maxAttempts} - Buffered: ${window.listenerAudio.buffered.length}, ReadyState: ${window.listenerAudio.readyState}`); console.log(`⏱️ Attempt ${attempts}/${maxAttempts} - Buffered: ${window.listenerAudio.buffered.length}, ReadyState: ${window.listenerAudio.readyState}`);
} }