Skip to content

Commit

Permalink
prevent eventual race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent-Bouisset committed Feb 6, 2024
1 parent 60ff415 commit 7731780
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions demo/full/scripts/controllers/ContentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,26 @@ function ContentList({
const [licenseServerUrl, setLicenseServerUrl] = React.useState("");
const [serverCertificateUrl, setServerCertificateUrl] = React.useState("");
const [isLowLatencyChecked, setIsLowLatencyChecked] = React.useState(false);
const [isAlreadyLoading, setIsAlreadyLoading] = React.useState(false);

/**
* Load the given content through the player.
* @param {Object|null} content
*/
const loadContent = React.useCallback(
(content: IPlayableContent) => {
getLoadVideoOptions(content).then(
(loadVideoOptions) => {
async (content: IPlayableContent) => {
if (!isAlreadyLoading) {
setIsAlreadyLoading(true);
try {
const loadVideoOptions = await getLoadVideoOptions(content);
loadVideo(loadVideoOptions);
},
/* eslint-disable-next-line no-console */
(err) => console.error(err),
);
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
} finally {
setIsAlreadyLoading(false);
}
}
},
[loadVideo],
);
Expand Down Expand Up @@ -522,7 +528,9 @@ function ContentList({
} else {
content = contentsToSelect[contentChoiceIndex];
}
loadContent(content);
loadContent(content)
// eslint-disable-next-line no-console
.catch((err) => console.log(err));
};

const saveCurrentContent = () => {
Expand Down

0 comments on commit 7731780

Please sign in to comment.