import {AbstractModal} from "tc-shared/ui/react-elements/modal/Definitions"; import React, {useContext} from "react"; import {Translatable, VariadicTranslatable} from "tc-shared/ui/react-elements/i18n"; import {IpcRegistryDescription, Registry} from "tc-events"; import {ModalVideoViewersEvents, ModalVideoViewersVariables} from "tc-shared/ui/modal/video-viewers/Definitions"; import {UiVariableConsumer} from "tc-shared/ui/utils/Variable"; import {createIpcUiVariableConsumer, IpcVariableDescriptor} from "tc-shared/ui/utils/IpcVariable"; import {joinClassList} from "tc-shared/ui/react-elements/Helper"; import {ClientTag} from "tc-shared/ui/tree/EntryTags"; import {ClientIconRenderer} from "tc-shared/ui/react-elements/Icons"; import {ClientIcon} from "svg-sprites/client-icons"; import {LoadingDots} from "tc-shared/ui/react-elements/LoadingDots"; const cssStyle = require("./Renderer.scss"); const EventContext = React.createContext>(undefined); const VariablesContext = React.createContext>(undefined); const ViewerRenderer = React.memo((props: { clientId: number, screen: boolean, camera: boolean }) => { const variables = useContext(VariablesContext); const clientInfo = variables.useReadOnly("viewerInfo", props.clientId, undefined); let clientName, clientIcon; if(clientInfo) { clientName = ( ); clientIcon = clientInfo.clientStatus || ClientIcon.PlayerOff; } else { clientName = ( loading ) clientIcon = ClientIcon.PlayerOff; } let videoStatus = []; if(props.camera) { videoStatus.push( ); } if(props.screen) { videoStatus.push( ); } return (
{clientName}
{videoStatus}
) }); const ViewerList = React.memo(() => { const variables = useContext(VariablesContext); const viewers = variables.useReadOnly("videoViewers", undefined, { __internal_client_order: [ ] }); let body; if(typeof viewers.screen === "undefined" && typeof viewers.camera === "undefined") { body = (
You're not sharing any video
); } else if(viewers.__internal_client_order.length) { body = viewers.__internal_client_order.map(clientId => ( = 0} camera={viewers.camera?.indexOf(clientId) >= 0} clientId={clientId} key={"viewer-" + clientId} /> )); } else { body = (
Nobody is watching your video feed :(
); } return (
{body}
) }); const ViewerCount = React.memo((props: { viewer: number[] | undefined }) => { if(!Array.isArray(props.viewer)) { return ( Not Enabled ); } if(props.viewer.length === 1) { return ( 1 Viewer ); } return ( {props.viewer.length} ); }); const ViewerSummary = React.memo(() => { const variables = useContext(VariablesContext); const viewers = variables.useReadOnly("videoViewers", undefined, { __internal_client_order: [ ] }); return (
Video viewers
); }) class Modal extends AbstractModal { private readonly events: Registry; private readonly variables: UiVariableConsumer; constructor(events: IpcRegistryDescription, variables: IpcVariableDescriptor) { super(); this.events = Registry.fromIpcDescription(events); this.variables = createIpcUiVariableConsumer(variables); } protected onDestroy() { super.onDestroy(); this.events.destroy(); this.variables.destroy(); } renderBody(): React.ReactElement { return (
); } renderTitle(): string | React.ReactElement { return ( Video Viewers ); } } export default Modal;