Live video on the AT Protocol

add camera useEffect cleanup function

+11
+11
js/components/src/components/mobile-player/video-async.native.tsx
··· 315 315 const localMediaStream = lms; 316 316 317 317 useEffect(() => { 318 + let acquiredStream: WebRTCMediaStream | null = null; 319 + 318 320 if (ingestMediaSource === IngestMediaSource.DISPLAY) { 319 321 mediaDevices 320 322 .getDisplayMedia() 321 323 .then((stream: WebRTCMediaStream) => { 324 + acquiredStream = stream; 322 325 console.log("display media", stream); 323 326 setLocalMediaStream(stream); 324 327 }) ··· 344 347 }, 345 348 }) 346 349 .then((stream: WebRTCMediaStream) => { 350 + acquiredStream = stream; 347 351 setLocalMediaStream(stream); 348 352 349 353 let errs: string[] = []; ··· 374 378 ); 375 379 }); 376 380 } 381 + 382 + return () => { 383 + if (acquiredStream) { 384 + acquiredStream.getTracks().forEach((track) => track.stop()); 385 + } 386 + setLocalMediaStream(null); 387 + }; 377 388 }, [ingestMediaSource, ingestCamera]); 378 389 379 390 useEffect(() => {