import * as React from "react"; import {Badge, Tabs, Icon} from "antd"; import "./WhiteboardManager.less"; import {Room, ViewMode, RoomState} from "white-web-sdk"; import {GuestUserType, HostUserType} from "../../pages/RoomManager"; import speak from "../../assets/image/speak.svg"; import user_empty from "../../assets/image/user_empty.svg"; import raise_hands_active from "../../assets/image/raise_hands_active.svg"; import WhiteboardChat from "./WhiteboardChat"; import {MessageType} from "./WhiteboardBottomRight"; import ClassroomMedia from "./ClassroomMedia"; import Identicon from "@netless/identicon"; import {ClassModeType, IdentityType, RtcType} from "../../pages/NetlessRoomTypes"; import { observer } from "mobx-react"; import { projectStore } from "../../models/ProjectStore"; const { TabPane } = Tabs; export type WhiteboardManagerProps = { room: Room; userId: string; handleManagerState: () => void; isManagerOpen: boolean | null; isChatOpen: boolean; uuid: string; hostInfo?: HostUserType, cameraState?: ViewMode; disableCameraTransform?: boolean; identity?: IdentityType; userName?: string; userAvatarUrl?: string; rtc?: RtcType; elementId: string; roomState: RoomState; }; export type WhiteboardManagerStates = { activeKey: string; messages: MessageType[]; seenMessagesLength: number, isRtcReady: boolean, }; @observer class WhiteboardManager extends React.Component { public constructor(props: WhiteboardManagerProps) { super(props); this.state = { activeKey: "1", messages: [], seenMessagesLength: 0, isRtcReady: false, }; } public UNSAFE_componentWillReceiveProps(nextProps: WhiteboardManagerProps): void { if (this.props.cameraState !== undefined && this.props.disableCameraTransform !== undefined && nextProps.cameraState !== undefined && nextProps.disableCameraTransform !== undefined) { if (this.props.cameraState !== nextProps.cameraState) { this.props.room.setViewMode(nextProps.cameraState); this.props.room.disableCameraTransform = nextProps.disableCameraTransform; } } if (this.props.isChatOpen !== nextProps.isChatOpen) { if (nextProps.isChatOpen) { this.setState({activeKey: "1"}); } else { this.setState({activeKey: "2"}); } } } public componentDidMount(): void { this.props.room.addMagixEventListener("message", (event: any) => { this.setState({messages: [...this.state.messages, event.payload]}); }); } private renderHost = (): React.ReactNode => { const {userId, roomState} = this.props; const hostInfo: HostUserType = (roomState.globalState as any).hostInfo; if (hostInfo) { if (userId === hostInfo.userId) { return ( ); } else { const thisGuestUsers = (roomState.globalState as any).guestUsers; if (thisGuestUsers) { const selfInfo: GuestUserType = thisGuestUsers.find((guestUser: GuestUserType) => guestUser.userId === userId); if (selfInfo) { return ( ); } else { return ( ); } } else { return ( ); } } } else { return null; } } private handleAgree = (room: Room, guestUser: GuestUserType, guestUsers: GuestUserType[]): void => { const {roomState} = this.props; const hostInfo: HostUserType = (roomState.globalState as any).hostInfo; if (this.props.identity === IdentityType.host) { if (hostInfo && guestUsers) { if (hostInfo.isVideoEnable) { const users = guestUsers.map((user: GuestUserType) => { if (user.userId === guestUser.userId) { user.isReadOnly = false; user.cameraState = ViewMode.Freedom; user.disableCameraTransform = false; user.applyForRtc = true; } return user; }); room.setGlobalState({guestUsers: users}); } else { const users = guestUsers.map((user: GuestUserType) => { if (user.userId === guestUser.userId) { user.isReadOnly = false; user.cameraState = ViewMode.Freedom; user.disableCameraTransform = false; } return user; }); room.setGlobalState({guestUsers: users}); } } } } private handleUnlock = (state: boolean, room: Room, guestUser: GuestUserType, guestUsers: GuestUserType[]): void => { const {identity} = this.props; if (identity === IdentityType.host && guestUsers) { let users; if (state) { // 解锁 users = guestUsers.map((user: GuestUserType) => { if (user.userId === guestUser.userId) { user.isReadOnly = false; user.cameraState = ViewMode.Freedom; user.disableCameraTransform = false; user.applyForRtc = true; } return user; }); } else { // 锁定 users = guestUsers.map((user: GuestUserType) => { if (user.userId === guestUser.userId) { user.isReadOnly = true; user.cameraState = ViewMode.Follower; user.isHandUp = false; user.disableCameraTransform = true; user.applyForRtc = false; } return user; }); } room.setGlobalState({guestUsers: users}); } } private renderGuestIcon = (guestUser: GuestUserType, guestUsers: GuestUserType[]): React.ReactNode => { const {room, roomState} = this.props; const hostInfo: HostUserType = (roomState.globalState as any).hostInfo; const isHost = this.props.identity === IdentityType.host; if (hostInfo && hostInfo.classMode === ClassModeType.lecture) { if (guestUser.isHandUp) { if (guestUser.isReadOnly) { return (
this.handleAgree(room, guestUser, guestUsers)} className={isHost ? "room-member-cell-icon" : "room-member-cell-icon-disable"}>
this.handleUnlock(true, room, guestUser, guestUsers)} className={isHost ? "room-member-cell-icon" : "room-member-cell-icon-disable"}>
); } else { return (
this.handleUnlock(false, room, guestUser, guestUsers)} className={isHost ? "room-member-cell-icon" : "room-member-cell-icon-disable"}>
); } } else { if (!guestUser.isReadOnly) { return
this.handleUnlock(false, room, guestUser, guestUsers)} className={isHost ? "room-member-cell-icon" : "room-member-cell-icon-disable"}>
; } else { return
this.handleUnlock(true, room, guestUser, guestUsers)} className={isHost ? "room-member-cell-icon" : "room-member-cell-icon-disable"}>
; } } } else { if (!guestUser.isReadOnly) { return
this.handleUnlock(false, room, guestUser, guestUsers)} className={isHost ? "room-member-cell-icon" : "room-member-cell-icon-disable"}>
; } else { return
this.handleUnlock(true, room, guestUser, guestUsers)} className={isHost ? "room-member-cell-icon" : "room-member-cell-icon-disable"}>
; } } } private renderGuest = (): React.ReactNode => { const {room, roomState} = this.props; const globalGuestUsers: GuestUserType[] = (roomState.globalState as any).guestUsers; if (globalGuestUsers && globalGuestUsers.length > 0) { const guestNodesOnline = globalGuestUsers.filter(guestUser => guestUser.isOnline); const guestNodes = guestNodesOnline.map((guestUser: GuestUserType, index: number) => { return (
{guestUser.avatar ?
:
}
{guestUser.name ? guestUser.name : guestUser.userId}
{this.renderGuestIcon(guestUser, globalGuestUsers)}
); }); if (guestNodes.length > 0) { return (
{guestNodes}
); } else { return
{projectStore.isEnglish() ? "No students have joined" : "尚且无学生加入"}
; } } else { return
{projectStore.isEnglish() ? "No students have joined" : "尚且无学生加入"}
; } } private handleDotState = (): React.ReactNode => { const {roomState} = this.props; const isActive = this.state.activeKey === "2"; if (this.props.isManagerOpen && !isActive) { const guestUsers: GuestUserType[] = (roomState.globalState as any).guestUsers; if (guestUsers && guestUsers.length > 0) { const handUpGuestUsers = guestUsers.filter((guestUser: GuestUserType) => guestUser.isHandUp); if (handUpGuestUsers && handUpGuestUsers.length > 0) { return "raise hands"; } else { return null; } } else { return null; } } else { return null; } } private renderUserListTitle = (): React.ReactNode => { if (this.props.identity === IdentityType.host) { return (
{projectStore.isEnglish() ? "Users List" : "用户列表"}
); } else { return (
{projectStore.isEnglish() ? "Users List" : "用户列表"}
); } } private renderChatListTitle = (): React.ReactNode => { const isActive = this.state.activeKey === "1"; return (
{projectStore.isEnglish() ? "Live Chat" : "聊天群组"}
); } private handleTabsChange = (evt: any): void => { this.setState({activeKey: evt, seenMessagesLength: this.state.messages.length}); } private handleManagerStyle = (): string => { if (this.props.isManagerOpen) { return "manager-box"; } else { return "manager-box-mask-close"; } } private setMediaAudioState = (state: boolean): void => { const {room, identity, roomState} = this.props; if (identity === IdentityType.host) { room.setGlobalState({hostInfo: { ...(roomState.globalState as any).hostInfo, isAllMemberAudioClose: state, }}); } } private getMediaState = (): boolean => { const {roomState} = this.props; if ((roomState.globalState as any).hostInfo) { const hostInfo: HostUserType = (roomState.globalState as any).hostInfo; if (hostInfo) { return hostInfo.isVideoEnable; } else { return false; } } else { return false; } } private renderAudioController = (): React.ReactNode => { if (!this.getMediaState()) { return null; } if (this.props.identity === IdentityType.host) { const {roomState} = this.props; const hostInfo: HostUserType = (roomState.globalState as any).hostInfo; if (hostInfo) { if (hostInfo.isAllMemberAudioClose) { return (
this.setMediaAudioState(false)} className="guest-box-btn"> 打开学生音频
); } else { return (
this.setMediaAudioState(true)} className="guest-box-btn"> 关闭学生音频
); } } else { return null; } } else { return null; } } public render(): React.ReactNode { if (this.props.isManagerOpen === null) { return null; } else { return (
{this.renderHost()}
{this.renderGuest()} {this.renderAudioController()}
); } } } export default WhiteboardManager;