lbry-desktop/ui/effects/use-socket-connect.js
2022-03-16 16:36:50 -04:00

23 lines
813 B
JavaScript

// @flow
import React from 'react';
import { formatLbryChannelName } from 'util/url';
export default function useSocketConnect(
isLivestreamClaim: boolean,
claimId: boolean,
channelUrl: ?string,
canonicalUrl: boolean,
doCommentSocketConnect: (string, string, string) => void,
doCommentSocketDisconnect: (string, string) => void
) {
// Establish web socket connection for viewer count.
React.useEffect(() => {
if (!isLivestreamClaim || !claimId || !channelUrl || !canonicalUrl) return;
const channelName = formatLbryChannelName(channelUrl);
doCommentSocketConnect(canonicalUrl, channelName, claimId);
return () => doCommentSocketDisconnect(claimId, channelName);
}, [canonicalUrl, channelUrl, claimId, doCommentSocketConnect, doCommentSocketDisconnect, isLivestreamClaim]);
}