@@ -162,25 +162,7 @@ export function Webcam({ onStreamReady, deviceId, frameRate, selectedAudioDevice
162
162
} ;
163
163
164
164
const newStream = await navigator . mediaDevices . getUserMedia ( constraints ) ;
165
-
166
- // Create a new stream with only the tracks we want
167
- const filteredTracks : MediaStreamTrack [ ] = [ ] ;
168
- if ( deviceId !== "none" ) {
169
- filteredTracks . push ( ...newStream . getVideoTracks ( ) ) ;
170
- }
171
- if ( selectedAudioDeviceId !== "none" ) {
172
- filteredTracks . push ( ...newStream . getAudioTracks ( ) ) ;
173
- }
174
-
175
- // Stop any tracks we're not using
176
- newStream . getTracks ( ) . forEach ( track => {
177
- if ( ! filteredTracks . includes ( track ) ) {
178
- track . stop ( ) ;
179
- }
180
- } ) ;
181
-
182
- const filteredStream = new MediaStream ( filteredTracks ) ;
183
- return filteredStream ;
165
+ return newStream ;
184
166
} catch ( error ) {
185
167
console . error ( "Error accessing media devices." , error ) ;
186
168
return null ;
@@ -192,13 +174,9 @@ export function Webcam({ onStreamReady, deviceId, frameRate, selectedAudioDevice
192
174
if ( frameRate == 0 ) return ;
193
175
194
176
startWebcam ( ) . then ( ( newStream ) => {
195
- replaceStream ( newStream ) ;
196
177
if ( newStream ) {
197
- // Only pass to StreamCanvas if we have video
198
- if ( deviceId !== "none" ) {
199
- setStream ( newStream ) ;
200
- }
201
- // Only call onStreamReady if we have a valid stream
178
+ replaceStream ( newStream ) ;
179
+ setStream ( newStream ) ;
202
180
onStreamReady ( newStream ) ;
203
181
}
204
182
} ) ;
@@ -208,8 +186,20 @@ export function Webcam({ onStreamReady, deviceId, frameRate, selectedAudioDevice
208
186
} ;
209
187
} , [ deviceId , frameRate , selectedAudioDeviceId , startWebcam , replaceStream , onStreamReady ] ) ;
210
188
211
- // Only render StreamCanvas if video is enabled
212
- if ( deviceId === "none" ) {
189
+ const hasVideo = stream && stream . getVideoTracks ( ) . length > 0 ;
190
+ const hasAudio = stream && stream . getAudioTracks ( ) . length > 0 ;
191
+
192
+ // Return audio-only placeholder if we have audio but no video
193
+ if ( ! hasVideo && hasAudio ) {
194
+ return (
195
+ < div className = "w-full h-full flex items-center justify-center" >
196
+ < span className = "text-white" > Audio Only</ span >
197
+ </ div >
198
+ ) ;
199
+ }
200
+
201
+ // Return null if we have neither video nor audio
202
+ if ( ! stream || ( ! hasVideo && ! hasAudio ) ) {
213
203
return null ;
214
204
}
215
205
@@ -218,9 +208,7 @@ export function Webcam({ onStreamReady, deviceId, frameRate, selectedAudioDevice
218
208
< StreamCanvas
219
209
stream = { stream }
220
210
frameRate = { frameRate }
221
- onStreamReady = { ( processedStream ) => {
222
- // Don't call onStreamReady here anymore since we handle it above
223
- } }
211
+ onStreamReady = { ( ) => { } } // We handle stream ready in the parent component
224
212
/>
225
213
</ div >
226
214
) ;
0 commit comments