MCPcopy Create free account
hub / github.com/FastLED/FastLED / initializeVideoRecorder

Function initializeVideoRecorder

src/platforms/wasm/compiler/index.ts:1132–1205  ·  view source on GitHub ↗

* Initializes the video recorder with canvas and audio context

()

Source from the content-addressed store, hash-verified

1130 * Initializes the video recorder with canvas and audio context
1131 */
1132function initializeVideoRecorder() {
1133 // Wait for DOM to be ready
1134 if (document.readyState === 'loading') {
1135 document.addEventListener('DOMContentLoaded', initializeVideoRecorder);
1136 return;
1137 }
1138
1139 const recordButton = document.getElementById('record-btn');
1140
1141 if (!recordButton) {
1142 console.warn('Record button not found, video recording disabled');
1143 return;
1144 }
1145
1146 // Check if worker mode is active - if so, use worker-based recording
1147 if (window.fastLEDWorkerManager && window.fastLEDWorkerManager.isWorkerActive) {
1148 console.log('Worker mode active - using worker-based video recording');
1149 initializeWorkerVideoRecorder(recordButton);
1150 return;
1151 }
1152
1153 // For non-worker mode, wait for canvas to be ready
1154 const canvas = document.getElementById('myCanvas');
1155 if (!canvas) {
1156 console.warn('Canvas not found, video recording disabled');
1157 return;
1158 }
1159
1160 // Wait for canvas to be properly initialized with graphics manager
1161 let retryCount = 0;
1162 const maxRetries = 30; // Max 6 seconds of retrying
1163 let initialized = false; // Track if initialization succeeded
1164
1165 const tryInitialize = () => {
1166 // Stop retrying if already initialized
1167 if (initialized) {
1168 return;
1169 }
1170
1171 try {
1172 // Check if worker mode became active during retry period
1173 if (window.fastLEDWorkerManager && window.fastLEDWorkerManager.isWorkerActive) {
1174 console.log('Worker mode became active - switching to worker-based recording');
1175 initializeWorkerVideoRecorder(recordButton);
1176 initialized = true; // Mark as successfully initialized
1177 return;
1178 }
1179
1180 // Check if graphics manager has been initialized (this is the real dependency)
1181 if (typeof window.graphicsManager === 'undefined' && typeof graphicsManager === 'undefined') {
1182 throw new Error('Graphics manager not initialized yet');
1183 }
1184
1185 // Validate canvas element exists (without creating conflicting context)
1186 if (!canvas || !canvas.getContext) {
1187 throw new Error('Canvas not ready yet');
1188 }
1189

Callers 1

index.tsFile · 0.85

Calls 3

addEventListenerMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected