Live video on the AT Protocol
1import { selectMySegments } from "features/streamplace/streamplaceSlice";
2import { useAppSelector } from "store/hooks";
3import { PlaceStreamSegment } from "streamplace";
4
5// composite selector that tells us when the current user is live
6export const useLiveUser = (): boolean => {
7 const mySegments = useAppSelector(selectMySegments);
8 if (mySegments.length === 0) {
9 return false;
10 }
11 if (!PlaceStreamSegment.isRecord(mySegments[0].record)) {
12 return false;
13 }
14 const record = mySegments[0].record as PlaceStreamSegment.Record;
15 if (Date.now() - new Date(record.startTime).getTime() < 1000 * 10) {
16 return true;
17 }
18 return false;
19};