//
// Config.jsx
//
// Copyright (c) 2019 2020 Andrea Bondavalli. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
//
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import { toast } from 'react-toastify';
import RestAPI from './Services';
import Loader from './Loader';
class Config extends Component {
static propTypes = {
setTitleExtras: PropTypes.func.isRequired
};
constructor(props) {
super(props);
this.state = {
version: '',
httpPort: '',
rtspPort: '',
rtspPortErr: false,
logSeverity: '',
playoutDelay: '',
playoutDelayErr: false,
ticFrameSizeAt1fs: '',
maxTicFrameSize: '',
maxTicFrameSizeErr: false,
sampleRate: '',
rtpMcastBase: '',
rtpMcastBaseErr: false,
rtpPort: '',
rtpPortErr: false,
ptpDomain: '',
ptpDscp: '',
sapInterval: '',
sapIntervalErr: false,
mdnsEnabled: false,
streamerEnabled: false,
streamerChannels: 0,
streamerChIntervalErr: false,
streamerFiles: 0,
streamerFilesIntervalErr: false,
streamerFileDuration: 0,
streamerFileDurationIntervalErr: false,
syslogProto: '',
syslogServer: '',
syslogServerErr: false,
statusFile: '',
interfaceName: '',
customNodeId: '',
customNodeIdErr: false,
macAddr: '',
ipAddr: '',
errors: 0,
isConfigLoading: false,
isVersionLoading: false,
autoSinksUpdate: false
};
this.onSubmit = this.onSubmit.bind(this);
this.inputIsValid = this.inputIsValid.bind(this);
this.setTitleExtras = this.setTitleExtras.bind(this);
}
componentDidMount() {
this.setState({isConfigLoading: true});
this.setState({isVersionLoading: true});
RestAPI.getVersion()
.then(response => response.json())
.then(
data => this.setState(
{
version: data.version,
isVersionLoading: false
}))
.catch(err => this.setState({isVersionLoading: false}));
RestAPI.getConfig()
.then(response => response.json())
.then(
data => this.setState(
{
httpPort: data.http_port,
rtspPort: data.rtsp_port,
logSeverity: data.log_severity,
playoutDelay: data.playout_delay,
ticFrameSizeAt1fs: data.tic_frame_size_at_1fs,
maxTicFrameSize: data.max_tic_frame_size,
sampleRate: data.sample_rate,
rtpMcastBase: data.rtp_mcast_base,
rtpPort: data.rtp_port,
ptpDomain: data.ptp_domain,
ptpDscp: data.ptp_dscp,
sapMcastAddr: data.sap_mcast_addr,
sapInterval: data.sap_interval,
mdnsEnabled: data.mdns_enabled,
streamerEnabled: data.streamer_enabled,
streamerChannels: data.streamer_channels,
streamerFiles: data.streamer_files_num,
streamerFileDuration: data.streamer_file_duration,
streamerPlayerBufferFiles: data.streamer_player_buffer_files_num,
syslogProto: data.syslog_proto,
syslogServer: data.syslog_server,
statusFile: data.status_file,
interfaceName: data.interface_name,
customNodeId: data.custom_node_id,
macAddr: data.mac_addr,
ipAddr: data.ip_addr,
nodeId: data.node_id,
autoSinksUpdate: data.auto_sinks_update,
isConfigLoading: false
}))
.catch(err => this.setState({isConfigLoading: false}));
}
setTitleExtras() {
if (!this.state.isConfigLoading) {
var nodeId = this.state.customNodeId === '' ? this.state.nodeId : this.state.customNodeId;
this.props.setTitleExtras(nodeId + " - " + this.state.ipAddr);
}
}
inputIsValid() {
return !this.state.playoutDelayErr &&
!this.state.maxTicFrameSizeErr &&
!this.state.rtpMcastBaseErr &&
!this.state.sapMcastAddrErr &&
!this.state.rtpPortErr &&
!this.state.rtspPortErr &&
!this.state.sapIntervalErr &&
!this.state.streamerChIntervalErr &&
!this.state.streamerFilesIntervalErr &&
!this.state.streamerFileDurationIntervalErr &&
!this.state.syslogServerErr &&
(!this.state.customNodeIdErr || this.state.customNodeId === '') &&
!this.state.isVersionLoading &&
!this.state.isConfigLoading;
}
onSubmit(event) {
event.preventDefault();
RestAPI.setConfig(
this.state.logSeverity,
this.state.syslogProto,
this.state.syslogServer,
this.state.rtpMcastBase,
this.state.rtpPort,
this.state.rtspPort,
this.state.playoutDelay,
this.state.ticFrameSizeAt1fs,
this.state.sampleRate,
this.state.maxTicFrameSize,
this.state.sapMcastAddr,
this.state.sapInterval,
this.state.mdnsEnabled,
this.state.customNodeId,
this.state.autoSinksUpdate,
this.state.streamerEnabled,
this.state.streamerChannels,
this.state.streamerFiles,
this.state.streamerFileDuration,
this.state.streamerPlayerBufferFiles)
.then(response => toast.success('Applying new configuration ...'));
}
render() {
return (
{this.setTitleExtras()}
{this.state.isVersionLoading ?
:
Version
}
{this.state.isConfigLoading ?
:
Audio Config
}
{this.state.isConfigLoading ?
:
HTTP Streamer Config
}
{this.state.isConfigLoading ?
:
Network Config
}
{this.state.isConfigLoading ?
:
Logging Config
}
)
}
}
export default Config;