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

Method startCaptureStream

app/src/utils/tauriStreamCapture.ts:900–1288  ·  view source on GitHub ↗

* Start capture with channel-based streaming. * Works on both desktop and iOS - frames are pushed from Rust as they arrive. * * On desktop: Shows selector window, waits for target selection, then starts xcap with channel * On iOS: Triggers ReplayKit picker, then HTTP-received frames are

(targetId?: string)

Source from the content-addressed store, hash-verified

898 * Returns MediaStreams for display and a cleanup function.
899 */
900 async startCaptureStream(targetId?: string): Promise<CaptureStreamResult> {
901 if (!isTauri()) {
902 throw new Error('Screen capture only available in Tauri');
903 }
904
905 Logger.info("TAURI_STREAM", `Starting channel-based capture stream`);
906
907 // On desktop, show selector and wait for target selection (unless a target is provided
908 // explicitly or was pre-seated via setPreselectedTarget).
909 let selectedTargetId: string | undefined = targetId ?? this.preselectedTargetId ?? undefined;
910 this.preselectedTargetId = null; // consume once
911 if (isDesktop() && !selectedTargetId) {
912 const selected = await this.waitForTargetSelection();
913 if (!selected) {
914 throw new Error('Screen capture cancelled by user');
915 }
916 selectedTargetId = selected;
917 }
918
919 Logger.info("TAURI_STREAM", `Starting capture with target: ${selectedTargetId || 'default'}`);
920
921 // Clean canvas (for AI/recording/preview). The PiP canvas only exists on mobile,
922 // where the status/timer overlay is baked into a separate stream. On desktop the
923 // overlay never draws (it's mobile-only), so a PiP canvas would be a pixel-identical
924 // copy of clean — a wasted per-frame drawImage plus a second canvas.captureStream()
925 // read-back. So on desktop we skip it and reuse the clean stream for the with-pip slot.
926 const usePip = !isDesktop();
927
928 const canvasClean = document.createElement('canvas');
929 // Initial size - will be adapted to actual frame dimensions
930 canvasClean.width = 1920;
931 canvasClean.height = 1080;
932 const ctxClean = canvasClean.getContext('2d');
933 if (!ctxClean) {
934 throw new Error('Failed to create canvas context');
935 }
936
937 const canvasPip = usePip ? document.createElement('canvas') : null;
938 const ctxPip = canvasPip ? canvasPip.getContext('2d') : null;
939 if (canvasPip) {
940 canvasPip.width = 1920;
941 canvasPip.height = 1080;
942 if (!ctxPip) {
943 throw new Error('Failed to create PiP canvas context');
944 }
945 }
946
947 // Create MediaStreams from canvases
948 const cleanStream = canvasClean.captureStream(30);
949 const pipStream = canvasPip ? canvasPip.captureStream(30) : cleanStream;
950
951 let canvasSizeInitialized = false;
952 let frameCount = 0;
953 let isActive = true;
954
955 // Create channels to receive frames and audio from Rust
956 const frameChannel = new Channel<FrameData>();
957 const audioChannel = new Channel<AudioData>();

Callers

nothing calls this directly

Calls 13

pushCaptureConfigMethod · 0.95
stopCaptureMethod · 0.95
getLatestBase64FrameMethod · 0.95
isTauriFunction · 0.90
isDesktopFunction · 0.90
decodeBase64PCMFunction · 0.90
infoMethod · 0.80
warnMethod · 0.80
pcmCallbackMethod · 0.80
errorMethod · 0.80
debugMethod · 0.45

Tested by

no test coverage detected