// vim: set ts=2 sw=2 et tw=80: import React, { Component } from "react"; import { StyledDivCamera } from "./styleComponents"; import { Grid, Checkbox } from "semantic-ui-react"; import { RemoteService } from "../../../remote"; import { endpointURL } from "../../../endpoint"; import { connect } from "react-redux"; import VideocamModal from "./VideocamModal"; class Videocam extends Component { constructor(props) { super(props); this.state = { selectedVideo: undefined }; this.setOnOff = this.setOnOff.bind(this); } openModal = () => { this.setState((state) => { return { selectedVideo: true }; }); }; closeModal = () => { this.setState((state) => { return { selectedVideo: undefined }; }); }; setOnOff(onOff) { const turn = onOff; if (this.props.tab === "Devices") { this.props .saveDevice({ ...this.props.device, on: turn }) .then((res) => turn ? this.refs.vidRef.play() : this.refs.vidRef.pause() ) .catch((err) => console.error("videocamera update error", err)); } else { this.props.updateState( { id: this.props.state.id, on: turn }, this.props.state.kind ); } } get url() { return endpointURL() + this.props.device.path; } render() { const VideocamView = (
this.setOnOff(val.checked)} />
); return
{VideocamView}
; } } const mapStateToProps = (state, ownProps) => ({ device: ownProps.tab === "Devices" ? state.devices[ownProps.id] : state.devices[state.sceneStates[ownProps.id].deviceId], state: state.sceneStates[ownProps.id], }); const VideocamContainer = connect(mapStateToProps, RemoteService)(Videocam); export default VideocamContainer;