@@ -352,24 +352,36 @@ export default class App extends React.Component {
352352
353353 const { mounts, remotes, erroredStreams, url } = this . state ;
354354 const sortedStreams = this . sortStreams ( [ ...mounts , ...remotes ] ) ;
355+ const currentStream = sortedStreams . find ( stream => stream . url === url ) ;
356+ const isStreamInErroredList = erroredStreams . some (
357+ stream => stream . url === url
358+ ) ;
359+ const newErroredStreams = isStreamInErroredList
360+ ? erroredStreams
361+ : [ ...erroredStreams , currentStream ] ;
355362
356363 // Pause if all streams are in the errored list
357- if ( erroredStreams . length === sortedStreams . length ) {
364+ if ( newErroredStreams . length === sortedStreams . length ) {
358365 this . pause ( ) ;
359366 return ;
360367 }
361368
362- const availableStreams = sortedStreams . filter ( stream => stream . url !== url ) ;
363- const currentStream = sortedStreams . find ( stream => stream . url === url ) ;
369+ // Available streams are those in `sortedStreams`
370+ // that don't exist in the errored list
371+ const availableStreams = sortedStreams . filter (
372+ stream =>
373+ ! newErroredStreams . some (
374+ erroredStream => erroredStream . url === stream . url
375+ )
376+ ) ;
364377
365378 // If the url is already in the errored list, use another url
366- if ( erroredStreams . some ( stream => stream . url === url ) ) {
379+ if ( isStreamInErroredList ) {
367380 this . setUrl ( availableStreams [ 0 ] . url ) ;
368381 } else {
369382 // Otherwise, add the url to the errored list, then use another url
370- this . setState (
371- { erroredStreams : [ ...erroredStreams , currentStream ] } ,
372- ( ) => this . setUrl ( availableStreams [ 0 ] . url )
383+ this . setState ( { erroredStreams : newErroredStreams } , ( ) =>
384+ this . setUrl ( availableStreams [ 0 ] . url )
373385 ) ;
374386 }
375387 } ;
0 commit comments