( item: QueueItem, t: TFunction, autoPlay: boolean, )
| 164 | }; |
| 165 | |
| 166 | const 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 | |
| 214 | export const useStreamResolution = (): void => { |
| 215 | const { t } = useTranslation('streaming'); |
no test coverage detected