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

Method requestStreamsForAgent

app/src/utils/streamManager.ts:112–161  ·  view source on GitHub ↗

The primary method for acquiring streams, using a "blueprint" approach.

(agentId: string, requiredStreams: PseudoStreamType[])

Source from the content-addressed store, hash-verified

110
111 /** The primary method for acquiring streams, using a "blueprint" approach. */
112 public async requestStreamsForAgent(agentId: string, requiredStreams: PseudoStreamType[]): Promise<void> {
113 Logger.debug("StreamManager", `Processing stream blueprint for agent '${agentId}': [${requiredStreams.join(', ')}]`);
114
115 // Get the appropriate capture implementation based on platform
116 const captureImpl = isWeb() ? browserStreamCapture : tauriStreamCapture;
117
118 // Let the platform-specific implementation map pseudo streams to master streams
119 const requiredMasterStreams = new Set<MasterStreamType>();
120 for (const type of requiredStreams) {
121 const masterStreams = captureImpl.getMasterStreamsForPseudoStream(type);
122 masterStreams.forEach(ms => requiredMasterStreams.add(ms));
123 }
124
125 const acquisitionPromises: Promise<void>[] = [];
126 requiredMasterStreams.forEach(masterType => acquisitionPromises.push(this.ensureMasterStream(masterType, captureImpl)));
127
128 try {
129 await Promise.all(acquisitionPromises);
130
131 for (const type of requiredStreams) {
132 if (!this.isPseudoStreamAvailable(type)) {
133 throw new Error(`Failed to acquire required stream component '${type}'. Permission may have been denied.`);
134 }
135 }
136
137 // --- Centralized Transcription & Mixer Logic ---
138 // Start transcription services and auto-subscribe the agent to each stream type.
139 // This ensures the agent receives all transcribed text from the moment streams are acquired.
140 if (requiredStreams.includes('allAudio')) {
141 await this.initializeAudioMixer();
142 }
143 if (requiredStreams.includes('microphone') && this.microphoneStream) {
144 await this.startTranscriptionForStream('microphone', this.microphoneStream);
145 this.getOrCreateSubscriber(agentId, 'microphone');
146 }
147 if (requiredStreams.includes('screenAudio') && this.screenAudioStream) {
148 await this.startTranscriptionForStream('screenAudio', this.screenAudioStream);
149 this.getOrCreateSubscriber(agentId, 'screenAudio');
150 }
151 // Notify listeners after subscribers are created so hooks can detect them
152 this.notifyListeners();
153 // --- END ---
154
155 requiredStreams.forEach(type => this.userSets.get(type)?.add(agentId));
156
157 } catch (error) {
158 Logger.error("StreamManager", `Failed to fulfill stream blueprint for agent '${agentId}'.`, error);
159 throw error;
160 }
161 }
162
163 /**
164 * Keep the screen stream alive for a holder that isn't an agent (an MCP turn), so an agent

Callers 11

handleApplyChangesFunction · 0.80
handleStartTestFunction · 0.80
startMicFunction · 0.80
startMicFunction · 0.80
handleStartScreenFunction · 0.80
handleStartCameraFunction · 0.80
handleStartMicrophoneFunction · 0.80
handleStartScreenAudioFunction · 0.80
handleStartAllAudioFunction · 0.80
startAgentLoopFunction · 0.80
holdCaptureFunction · 0.80

Calls 12

ensureMasterStreamMethod · 0.95
initializeAudioMixerMethod · 0.95
getOrCreateSubscriberMethod · 0.95
notifyListenersMethod · 0.95
isWebFunction · 0.90
pushMethod · 0.80
allMethod · 0.80
errorMethod · 0.80
debugMethod · 0.45

Tested by

no test coverage detected