MCPcopy Index your code
hub / github.com/nukeop/nuclear / resolveStream

Function resolveStream

packages/player/src/hooks/useStreamResolution.ts:166–212  ·  view source on GitHub ↗
(
  item: QueueItem,
  t: TFunction,
  autoPlay: boolean,
)

Source from the content-addressed store, hash-verified

164};
165
166const resolveStream = async (
167 item: QueueItem,
168 t: TFunction,
169 autoPlay: boolean,
170): Promise<void> => {
171 activeController?.abort();
172 activeController = new AbortController();
173 const { signal } = activeController;
174
175 const { updateItemState } = useQueueStore.getState();
176 const { setSrc, play, stop } = useSoundStore.getState();
177
178 if (autoPlay) {
179 stop();
180 }
181 updateItemState(item.id, { status: 'loading', error: undefined });
182
183 const candidates = await resolveCandidates(item.track);
184 if (signal.aborted) {
185 return;
186 }
187 if (!candidates) {
188 setItemError(item.id, 'errors.noCandidatesFound', t);
189 return;
190 }
191
192 updateItemCandidates(item, candidates);
193
194 const resolvedCandidate = await resolveStreamWithFallback(
195 candidates,
196 item,
197 signal,
198 );
199 if (signal.aborted) {
200 return;
201 }
202 if (!resolvedCandidate?.stream) {
203 setItemError(item.id, 'errors.allCandidatesFailed', t);
204 return;
205 }
206
207 const audioSource = await buildAudioSource(resolvedCandidate);
208 setSrc(audioSource);
209 if (autoPlay) {
210 play();
211 }
212};
213
214export const useStreamResolution = (): void => {
215 const { t } = useTranslation('streaming');

Callers 1

onCurrentItemChangedFunction · 0.85

Calls 9

stopFunction · 0.85
resolveCandidatesFunction · 0.85
setItemErrorFunction · 0.85
updateItemCandidatesFunction · 0.85
buildAudioSourceFunction · 0.85
setSrcFunction · 0.85
playFunction · 0.85
getStateMethod · 0.80

Tested by

no test coverage detected