* Actually initializes the video recorder once canvas is ready
(canvas, recordButton)
| 1461 | * Actually initializes the video recorder once canvas is ready |
| 1462 | */ |
| 1463 | function actuallyInitializeVideoRecorder(canvas, recordButton) { |
| 1464 | // Note: Audio context removed for async video recorder |
| 1465 | // Audio recording will be handled separately if needed |
| 1466 | |
| 1467 | // Check if MediaRecorder is supported |
| 1468 | if (typeof MediaRecorder === 'undefined') { |
| 1469 | console.warn('MediaRecorder API not supported, video recording disabled'); |
| 1470 | recordButton.style.display = 'none'; |
| 1471 | return; |
| 1472 | } |
| 1473 | |
| 1474 | // Always use default settings (no localStorage persistence) |
| 1475 | const defaultSettings = window.getVideoSettings ? window.getVideoSettings() : null; |
| 1476 | |
| 1477 | try { |
| 1478 | // Validate canvas is ready (without creating a context that would conflict with graphics manager) |
| 1479 | if (!canvas.getContext) { |
| 1480 | throw new Error('Canvas does not support getContext method'); |
| 1481 | } |
| 1482 | |
| 1483 | // Don't create a context here - the graphics manager handles context creation |
| 1484 | // Just validate the canvas element is ready for use |
| 1485 | |
| 1486 | // Create video recorder instance with optimized settings |
| 1487 | videoRecorder = new VideoRecorder({ |
| 1488 | canvas, |
| 1489 | audioContext: null, // Disable audio for better performance |
| 1490 | fps: defaultSettings?.fps || 60, |
| 1491 | settings: { |
| 1492 | // Use default settings but exclude fps to avoid conflicts |
| 1493 | ...defaultSettings, |
| 1494 | fps: undefined, // Remove fps from settings to ensure constructor fps parameter takes precedence |
| 1495 | }, |
| 1496 | onStateChange: (isRecording) => { |
| 1497 | // Update button visual state |
| 1498 | if (isRecording) { |
| 1499 | recordButton.classList.add('recording'); |
| 1500 | // Update icon |
| 1501 | const recordIcon = recordButton.querySelector('.record-icon'); |
| 1502 | const stopIcon = recordButton.querySelector('.stop-icon'); |
| 1503 | if (recordIcon) recordIcon.style.display = 'none'; |
| 1504 | if (stopIcon) stopIcon.style.display = 'block'; |
| 1505 | } else { |
| 1506 | recordButton.classList.remove('recording'); |
| 1507 | // Update icon |
| 1508 | const recordIcon = recordButton.querySelector('.record-icon'); |
| 1509 | const stopIcon = recordButton.querySelector('.stop-icon'); |
| 1510 | if (recordIcon) recordIcon.style.display = 'block'; |
| 1511 | if (stopIcon) stopIcon.style.display = 'none'; |
| 1512 | } |
| 1513 | |
| 1514 | // Update tooltip with current encoding format |
| 1515 | // Use setTimeout to ensure the state change is complete |
| 1516 | setTimeout(() => { |
| 1517 | if (window.updateRecordButtonTooltip) { |
| 1518 | window.updateRecordButtonTooltip(); |
| 1519 | } |
| 1520 | }, 0); |
no test coverage detected