import React from 'react'; import superagent from 'superagent'; import { fromUnixTime, formatDistanceToNow } from "date-fns"; import { formatInTimeZone } from 'date-fns-tz' import constants, { DEFAULT_TIMEZONE } from '../CloudApi/Constants.js'; import ApiButtonModal from '../CloudApi/ApiButtonModal.jsx'; import { splitUpperCamelCase } from '../CloudApi/ApiUtils.js'; import BigApiErrorMessage from '../CloudApi/BigApiErrorMessage.jsx'; import ScreenComponent from './ScreenComponent.jsx'; import { Radio, Segment, Header, Image, Modal, Icon, Button, Table, Form, Label, Dropdown } from 'semantic-ui-react' export function renderCompactTitle(storedRoom, liveRoom, extra) { const name = storedRoom.name; const participantsCount = (liveRoom.participantsIndex ? Object.keys(liveRoom.participantsIndex).length : 0); const size = storedRoom.maxUsersPerInstance; const instancePolicy = storedRoom.instancePolicy; const isNSFWRoom = storedRoom.category === "NSFW"; const roomTitle = ( {isNSFWRoom && } {name}  {(storedRoom.visibility === 'private') && } {extra && (instancePolicy && instancePolicy.startsWith("Multiple") ? : )} {extra && ((participantsCount > 0) ? : )} ); return roomTitle; } class RoomComponent extends React.Component { constructor(props) { super(props); this.state = { currentMediaProduct: null, }; } async componentDidMount() { console.log(this.props.room); if (this.props.room.content) { const contentJSON = JSON.parse(decodeURIComponent(this.props.room.content)); let bigMediaId = contentJSON.bigMediaId; const res = await superagent.post("/api/admin/media/query").send({ bigMediaId }); this.setState({ currentMediaProduct: res.body[0] }) } } showSetRoomPrivateModal(roomIndex, e) { this.setState({ isShowingSetRoomPrivateModal: true }); } async onSetRoomPrivate() { this.setState({ isShowingSetRoomPrivateModal: false }); try { console.log(`/cloud/admin/room/${this.props.liveRoom.roomId}`); const res = await superagent.put(`/cloud/admin/room/${this.props.liveRoom.roomId}`).accept('json').send({ visibility: 'Private' }); console.log("Room is now private!"); } catch (e) { console.error(e); } } async onScreenUpdated(screenIndex, e) { this.props.onReloadRoom(); } closeSetRoomPrivateModal(e) { this.setState({ isShowingSetRoomPrivateModal: false }); } showDeleteRoomModal(roomIndex, e) { this.setState({ isShowingDeleteRoomModal: true }); } async onDeleteRoom(e) { this.setState({ isShowingDeleteRoomModal: false }); try { const res = await superagent.delete(`/cloud/admin/room/${this.props.room.roomId}`).accept('json'); } catch (e) { console.error(e); } } closeDeleteRoomModal(e) { this.setState({ isShowingDeleteRoomModal: false }); } sendMessage(selectedBigscreenUser, e) { e.preventDefault(); this.setState({ selectedBigscreenUser, showMessageDialog: true }); } closeMessageModal(e) { this.setState({ showMessageDialog: false }); } onUpdateMessageText(e, { name, value }) { const state = this.state; state[name] = value; this.setState(state); } async onConfirmSendMessage(e) { e.preventDefault(); try { console.log(this.state.selectedBigscreenUser); const payload = { message: this.state.message }; const result = await superagent.post(`/cloud/admin/account/${this.state.selectedBigscreenUser.bigscreenAccountId}/message`).send(payload).accept('json'); } catch (e) { console.log(e); } this.setState({ showMessageDialog: false, message: undefined, selectedBigscreenUser: undefined }); } async onUpdateAdminSettings(e, { name, value }) { console.log(name, value); return this.props.onUpdateRoom(this.props.roomIndex, e, { adminSettings: name, value }); } renderTitle() { let ownerLink = null; if (this.props.ownerBigscreenAccount) { ownerLink = ( by {this.props.ownerBigscreenAccount.username} ); } const title = (
🏠 Room: {this.props.room.name} {ownerLink}
); const createdAt = formatInTimeZone(new Date(this.props.room.createdAt), DEFAULT_TIMEZONE, 'PPPp z'); const fromNow = formatDistanceToNow(new Date(this.props.room.createdAt), { addSuffix: true }); return (
{title}

{(this.props.liveRoom) ? : } Created: {createdAt} ({fromNow})

🏠 Room Actions... }>

Are you sure you want to set the room {this.props.room.name} ({this.props.room.roomId}) to private?

Are you sure you want to delete the room {this.props.room.name} ({this.props.room.roomId})?

This will kick everyone from the room!!!

); } renderRoomInstances() { // HACK HACK HACK // // Server returning null room instance in the array. return this.props.roomInstances && this.props.roomInstances.map((roomInstance) => { return (roomInstance && roomInstance.participants.length > 0) ? Name Room Info Device GPU/CPU OS App Version Tools {roomInstance.participants.map((participant, participantIndex) => { const isAdmin = _.indexOf(this.props.room.adminUserIds, participant.bigscreenUserId) !== -1; const isOwner = this.props.room.owner && participant.userSessionId === this.props.room.owner.userSessionId; let avatarUrl = "/images/avatar_b.jpg"; const bigscreenUser = participant.bigscreenUser; const accountProfile = participant.bigscreenUser.socialProfile; if (accountProfile && accountProfile.oculusProfile && accountProfile.oculusProfile.oculusImageURL) { avatarUrl = accountProfile.oculusProfile.oculusImageURL; } else if (accountProfile && accountProfile.steamProfile && accountProfile.steamProfile.avatarfull) { avatarUrl = accountProfile.steamProfile.avatarfull; } let bigscreenUserHeader = null; if (bigscreenUser && accountProfile) { bigscreenUserHeader = (bigscreenUser.bigscreenAccountId) ? (
{accountProfile.username}
) : (
{accountProfile.username}
); } else { bigscreenUserHeader = (
Missing User Data!!!!
); } return ( {bigscreenUserHeader} {isOwner ? : ""} {isAdmin ? : ""}
{bigscreenUser.systemInfo && bigscreenUser.systemInfo.GPU} {bigscreenUser.systemInfo && bigscreenUser.systemInfo.CPU}
{bigscreenUser.systemInfo && bigscreenUser.systemInfo.operatingSystem} {bigscreenUser.systemInfo && bigscreenUser.systemInfo.version} {this.props.onEjectParticipant && } {this.props.onKickParticipant && }
) })}
: null; }); } render() { if (!this.props.room) { return (
) } if (this.props.compact) { const storedRoom = this.props.room.storedRoomSnapshot; const liveRoom = this.props.room; const anchor = `${storedRoom.roomType}${this.props.roomIndex}`; const participantsCount = (this.props.room.participantsIndex ? Object.keys(this.props.room.participantsIndex).length : 0); let environmentName = storedRoom.environmentId; if (this.props.environmentOptions) { const environmentOption = this.props.environmentOptions.find((environmentOption) => environmentOption.key === storedRoom.environmentId); if (environmentOption) { environmentName = environmentOption.text; } } const environmentLink = ( {environmentName} ); return ( <> {renderCompactTitle(this.props.room.storedRoomSnapshot, this.props.room, this.props.roomIndex)} Room Type {storedRoom.roomType} Environment {environmentLink} Name {storedRoom.name} Category {storedRoom.category} Max Users Per Instance {storedRoom.maxUsersPerInstance} Room Id {storedRoom.roomId} App Version {liveRoom.contextAppVersion} Version {storedRoom.version} Participants {participantsCount}
); } else { const anchor = `${this.props.liveRoom && this.props.liveRoom.roomType}`; const participantsCount = ((this.props.liveRoom && this.props.liveRoom.participantsIndex) ? Object.keys(this.props.liveRoom.participantsIndex).length : 0); return ( <> {this.renderTitle()} {(this.props.room.visibility === 'Public') && Invite Code {this.props.room.inviteCode}  } {(this.props.room.visibility !== 'Private') && Room Id {this.props.room.roomId} } Visibility {this.props.room.visibility} Room Type (Legacy) {this.props.room.roomType} {(this.props.onUpdateRoom && this.props.environmentOptions) ? ( Environment ) : ( Environment {this.props.room.environmentId} )} {(this.props.onUpdateRoom) ? ( Name ) : ( Name {this.props.room.name} )} {(this.props.onUpdateRoom) && Description } {(this.props.onUpdateRoom) && Category } {(this.props.onUpdateRoom) ? ( Max Users Per Instance ) : ( Max Users Per Instance {this.props.room.maxUsersPerInstance} )} {this.props.room && this.props.cloudSchemas && Admin Settings
{Object.keys(this.props.cloudSchemas.AdminSettingsOptions).map((key) => { let adminSettingsOption = this.props.cloudSchemas.AdminSettingsOptions[key]; let options = this.props.cloudSchemas[adminSettingsOption.optionsKey]; let value = this.props.room[key]; return ( {adminSettingsOption.title} ); })}
} {this.props.liveRoom && this.props.liveRoom.mediaServer && Media Server Info } {this.props.liveRoom && this.props.liveRoom.screens && Screens list ({this.props.liveRoom.screens.length}) {this.props.liveRoom.screens.map((screen, screenIndex) => { return (
); })}
} Participants {participantsCount} Version {this.props.room.version} {this.renderRoomInstances()}
{ (this.state.account) &&

Enter a message to send to this user {this.state.selectedUser.username}:

}
); } } } export default RoomComponent;