prevent livestream api calls if no livestream claim exists: #6632
This commit is contained in:
parent
b5fec393c6
commit
7802337655
2 changed files with 13 additions and 8 deletions
|
@ -2064,9 +2064,6 @@
|
||||||
"Skip Navigation": "Skip Navigation",
|
"Skip Navigation": "Skip Navigation",
|
||||||
"Reset": "Reset",
|
"Reset": "Reset",
|
||||||
"Reset to original (previous) publish date": "Reset to original (previous) publish date",
|
"Reset to original (previous) publish date": "Reset to original (previous) publish date",
|
||||||
"%title% by %channelTitle%": "%title% by %channelTitle%",
|
|
||||||
"%title% by %channelTitle% %ariaDate%": "%title% by %channelTitle% %ariaDate%",
|
|
||||||
"%title% by %channelTitle% %ariaDate%, %mediaDuration%": "%title% by %channelTitle% %ariaDate%, %mediaDuration%",
|
|
||||||
"Search for something...": "Search for something...",
|
"Search for something...": "Search for something...",
|
||||||
"--end--": "--end--"
|
"--end--": "--end--"
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,11 @@ export default function LivestreamLink(props: Props) {
|
||||||
const [livestreamClaim, setLivestreamClaim] = React.useState(false);
|
const [livestreamClaim, setLivestreamClaim] = React.useState(false);
|
||||||
const [isLivestreaming, setIsLivestreaming] = React.useState(false);
|
const [isLivestreaming, setIsLivestreaming] = React.useState(false);
|
||||||
const livestreamChannelId = (channelClaim && channelClaim.claim_id) || ''; // TODO: fail in a safer way, probably
|
const livestreamChannelId = (channelClaim && channelClaim.claim_id) || ''; // TODO: fail in a safer way, probably
|
||||||
|
const isChannelEmpty = !channelClaim || !channelClaim.meta || !channelClaim.meta.claims_in_channel;
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (livestreamChannelId) {
|
// Don't search empty channels
|
||||||
|
if (livestreamChannelId && !isChannelEmpty) {
|
||||||
Lbry.claim_search({
|
Lbry.claim_search({
|
||||||
channel_ids: [livestreamChannelId],
|
channel_ids: [livestreamChannelId],
|
||||||
has_no_source: true,
|
has_no_source: true,
|
||||||
|
@ -35,7 +37,7 @@ export default function LivestreamLink(props: Props) {
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}
|
}
|
||||||
}, [livestreamChannelId]);
|
}, [livestreamChannelId, isChannelEmpty]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
function fetchIsStreaming() {
|
function fetchIsStreaming() {
|
||||||
|
@ -53,17 +55,23 @@ export default function LivestreamLink(props: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let interval;
|
let interval;
|
||||||
if (livestreamChannelId) {
|
// Only call livestream api if channel has livestream claims
|
||||||
|
if (livestreamChannelId && livestreamClaim) {
|
||||||
if (!interval) fetchIsStreaming();
|
if (!interval) fetchIsStreaming();
|
||||||
interval = setInterval(fetchIsStreaming, 10 * 1000);
|
interval = setInterval(fetchIsStreaming, 10 * 1000);
|
||||||
}
|
}
|
||||||
|
// Prevent any more api calls on update
|
||||||
|
if (!livestreamChannelId || !livestreamClaim) {
|
||||||
|
if (interval) {
|
||||||
|
clearInterval(interval);
|
||||||
|
}
|
||||||
|
}
|
||||||
return () => {
|
return () => {
|
||||||
if (interval) {
|
if (interval) {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [livestreamChannelId]);
|
}, [livestreamChannelId, livestreamClaim]);
|
||||||
|
|
||||||
if (!livestreamClaim || !isLivestreaming) {
|
if (!livestreamClaim || !isLivestreaming) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue