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'; import { Radio, Segment, Header, Image, Modal, Icon, Button, Table, Form, Label, Dropdown } from 'semantic-ui-react' export default class ScreenComponent extends React.Component { constructor(props) { super(props); this.state = { currentMediaProduct: null, isShowingDeleteScreenModal: false }; } async componentDidMount() { 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] }) } } async onTogglePresenter(e) { try { const isPresenting = !this.props.screen.isPresenting; const res = await superagent.put(`/api/admin/screen/${this.props.screen.id}`).accept('json').send({ isPresenting }); this.props.onScreenUpdated(); } catch (e) { console.error(e); } } async onToggleMonitor(e) { try { const isMonitor = !this.props.screen.isMonitor; const res = await superagent.put(`/api/admin/screen/${this.props.screen.id}`).accept('json').send({ isMonitor }); this.props.onScreenUpdated(); } catch (e) { console.error(e); } } async onSetScreenFormat(e, { name, value }) { try { const res = await superagent.put(`/api/admin/screen/${this.props.screen.id}`).accept('json').send({ format: value }); this.props.onScreenUpdated(); } catch (e) { console.error(e); } } getEstimatedPosition() { if (this.props.screen.sharedMediaSession) { const { position, serverTime, startTime } = this.props.screen.sharedMediaSession; return (position + ((1000.0 * (serverTime - startTime)) - position)); } throw new Error("Can't do it."); } async pauseSharedMediaSession(e) { try { const position = this.getEstimatedPosition(); const res = await superagent.put(`/api/admin/screen/${this.props.screen.id}/session`).accept('json').send({ action: "Pause", position }); this.props.onScreenUpdated(); } catch (e) { console.error(e); } } async resumeSharedMediaSession(e) { try { const position = this.getEstimatedPosition(); const res = await superagent.put(`/api/admin/screen/${this.props.screen.id}/session`).accept('json').send({ action: "Resume", position }); this.props.onScreenUpdated(); } catch (e) { console.error(e); } } async seekSharedMediaSession(e) { try { // HACK HACK HACK // // Without this, the position will reset to 0. const position = this.getEstimatedPosition(); const res = await superagent.put(`/api/admin/screen/${this.props.screen.id}/session`).accept('json').send({ action: "Seek", position: position + 5000 }); this.props.onScreenUpdated(); } catch (e) { console.error(e); } } showDeleteScreenModal(roomIndex, e) { this.setState({ isShowingDeleteScreenModal: true}); } async onDeleteScreen(e) { e.preventDefault(); this.setState({ isShowingDeleteScreenModal: false }); try { const res = await superagent.delete(`/api/admin/screen/${this.props.screen.id}`).accept('json'); this.props.onScreenUpdated(); } catch (e) { console.error(e); } } closeDeleteScreenModal(e) { this.setState({isShowingDeleteScreenModal: false}); } render() { if (!this.props.screen) { return (
) } const createdAt = formatInTimeZone(new Date(this.props.screen.createdAt), DEFAULT_TIMEZONE, 'PPPp z'); const fromNow = formatDistanceToNow(new Date(this.props.screen.createdAt), { addSuffix: true }); const screenTitle =
#{this.props.screenIndex + 1} {this.props.screen.name}
return ( {screenTitle} Created: {createdAt} ({fromNow})
{(this.props.screen.screenType === "MediaServer") && Media Server } {(this.props.screen.screenType === "MediaServer") && Controls

Format:
} {(this.props.screen.screenType === "ChannelId") && Channel
{this.props.screen.channel.name}
{this.props.screen.channel.description}
} {(this.props.screen.screenType === "LocalFileId") && Local File {this.props.screen.sharedMediaSession.localFileId} } {(this.props.screen.screenType === "App") && External Url {this.props.screen.sharedMediaSession.appUrl} } {(this.props.screen.screenType === "LocalFileId") && Playback State: Position: {this.props.screen.sharedMediaSession.position}
{this.props.screen.sharedMediaSession.state === "Playing" && } {this.props.screen.sharedMediaSession.state === "Paused" && }
} {(this.props.screen.screenType === "BigMediaId") && Media Product {this.props.screen.mediaProduct.title} } {(this.props.screen.screenType === "BigMediaId" || this.props.screen.screenType === "App") && Playback State: Position: {this.props.screen.sharedMediaSession.position}
{this.props.screen.sharedMediaSession.state === "Playing" && } {this.props.screen.sharedMediaSession.state === "Paused" && }
}
{

Are you sure you want to delete the screen {this.props.screen.screenType} ({this.props.screen.id})?

People will have nothing to watch!!!

}
); } }