MCPcopy Create free account
hub / github.com/Roy3838/Observer / startVideoStream

Method startVideoStream

app/src/utils/tauriStreamCapture.ts:484–680  ·  view source on GitHub ↗

* Start video-only capture stream. * Independent from audio - use startAudioStream separately if you also need audio. * Works on both desktop and iOS.

(targetId?: string)

Source from the content-addressed store, hash-verified

482 * Works on both desktop and iOS.
483 */
484 async startVideoStream(targetId?: string): Promise<VideoStreamResult> {
485 if (!isTauri()) {
486 throw new Error('Screen capture only available in Tauri');
487 }
488
489 Logger.info("TAURI_STREAM", `Starting video-only capture stream`);
490
491 // Desktop: Show selector and wait for target selection (unless a target is provided
492 // explicitly or was pre-seated via setPreselectedTarget). iOS: ReplayKit picker later.
493 let selectedTargetId: string | undefined = targetId ?? this.preselectedTargetId ?? undefined;
494 this.preselectedTargetId = null; // consume once, regardless of platform
495 if (isDesktop() && !selectedTargetId) {
496 const selected = await this.waitForTargetSelection();
497 if (!selected) {
498 throw new Error('Screen capture cancelled by user');
499 }
500 selectedTargetId = selected;
501 }
502 this.liveTargetId = selectedTargetId ?? null;
503
504 Logger.info("TAURI_STREAM", `Starting video capture with target: ${selectedTargetId || 'iOS broadcast'}`);
505
506 // Clean canvas (for AI/recording/preview). The PiP canvas only exists on mobile,
507 // where the status/timer overlay is baked into a separate stream. On desktop the
508 // overlay never draws (it's mobile-only), so a PiP canvas would be a pixel-identical
509 // copy of clean — a wasted per-frame drawImage plus a second canvas.captureStream()
510 // read-back. So on desktop we skip it and reuse the clean stream for the with-pip slot.
511 const usePip = !isDesktop();
512
513 const canvasClean = document.createElement('canvas');
514 canvasClean.width = 1920;
515 canvasClean.height = 1080;
516 const ctxClean = canvasClean.getContext('2d');
517 if (!ctxClean) {
518 throw new Error('Failed to create canvas context');
519 }
520
521 const canvasPip = usePip ? document.createElement('canvas') : null;
522 const ctxPip = canvasPip ? canvasPip.getContext('2d') : null;
523 if (canvasPip) {
524 canvasPip.width = 1920;
525 canvasPip.height = 1080;
526 if (!ctxPip) {
527 throw new Error('Failed to create PiP canvas context');
528 }
529 }
530
531 const cleanStream = canvasClean.captureStream(30);
532 const pipStream = canvasPip ? canvasPip.captureStream(30) : cleanStream;
533
534 let canvasSizeInitialized = false;
535 let frameCount = 0;
536 let isActive = true;
537
538 const frameChannel = new Channel<FrameData>();
539
540 // Coalescing decode pump: we only ever hold the NEWEST undecoded frame and decode
541 // one at a time. If frames arrive faster than we can decode+draw, the intermediate

Callers 1

Calls 9

pushCaptureConfigMethod · 0.95
getLatestBase64FrameMethod · 0.95
isTauriFunction · 0.90
isDesktopFunction · 0.90
infoMethod · 0.80
warnMethod · 0.80
debugMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected