Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,24 +352,36 @@ export default class App extends React.Component {

const { mounts, remotes, erroredStreams, url } = this.state;
const sortedStreams = this.sortStreams([...mounts, ...remotes]);
const currentStream = sortedStreams.find(stream => stream.url === url);
const isStreamInErroredList = erroredStreams.some(
stream => stream.url === url
);
const newErroredStreams = isStreamInErroredList
? erroredStreams
: [...erroredStreams, currentStream];

// Pause if all streams are in the errored list
if (erroredStreams.length === sortedStreams.length) {
if (newErroredStreams.length === sortedStreams.length) {
this.pause();
return;
}

const availableStreams = sortedStreams.filter(stream => stream.url !== url);
const currentStream = sortedStreams.find(stream => stream.url === url);
// Available streams are those in `sortedStreams`
// that don't exist in the errored list
const availableStreams = sortedStreams.filter(
stream =>
!newErroredStreams.some(
erroredStream => erroredStream.url === stream.url
)
);

// If the url is already in the errored list, use another url
if (erroredStreams.some(stream => stream.url === url)) {
if (isStreamInErroredList) {
this.setUrl(availableStreams[0].url);
} else {
// Otherwise, add the url to the errored list, then use another url
this.setState(
{ erroredStreams: [...erroredStreams, currentStream] },
() => this.setUrl(availableStreams[0].url)
this.setState({ erroredStreams: newErroredStreams }, () =>
this.setUrl(availableStreams[0].url)
);
}
};
Expand Down