Bugfix live status state (#1689)

* fix bug and add some documentation

* Prevent is_live fetching when playing stream and going back to livestream page

Co-authored-by: Rafael <rafael.saes@odysee.com>
This commit is contained in:
mayeaux 2022-06-14 15:33:56 +02:00 committed by GitHub
parent e6a563443e
commit bd9a6ac2bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -107,7 +107,7 @@ export default function LivestreamPage(props: Props) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useFetchLiveStatus(livestreamChannelId, doFetchChannelLiveStatus);
useFetchLiveStatus(isStreamPlaying ? undefined : livestreamChannelId, doFetchChannelLiveStatus);
React.useEffect(() => {
setActiveStreamUri(!isCurrentClaimLive && isChannelBroadcasting ? activeLivestreamForChannel.claimUri : false);

View file

@ -15,12 +15,18 @@ const defaultState: LivestreamState = {
socketConnectionById: {},
};
/**
* Update state.viewersById with the latest data
* @param {object} activeLivestreams - streams with fetched data
* @param {object} originalState - streams with only their view counts
* @returns {*} - updated viewersById object if active streams passed, otherwise return old data
*/
function updateViewersById(activeLivestreams, originalState) {
if (activeLivestreams) {
const viewersById = Object.assign({}, originalState);
Object.values(activeLivestreams).forEach((data) => {
// $FlowFixMe: mixed
if (data.claimId && data.viewCount) {
if (data && data.claimId && data.viewCount) {
// $FlowFixMe: mixed
viewersById[data.claimId] = data.viewCount;
}