//
// Config.js
//
// 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 { toast } from 'react-toastify';
import RestAPI from './Services';
import Loader from './Loader';
require('./styles.css');
class Config extends Component {
constructor(props) {
super(props);
this.state = {
httpPort: '',
logSeverity: '',
playoutDelay: '',
playoutDelayErr: false,
ticFrameSizeAt1fs: '',
ticFrameSizeAt1fsErr: false,
maxTicFrameSize: '',
maxTicFrameSizeErr: false,
sampleRate: '',
rtpMcastBase: '',
rtpMcastBaseErr: false,
rtpPort: '',
rtpPortErr: false,
ptpDomain: '',
ptpDscp: '',
sapInterval: '',
sapIntervalErr: false,
syslogProto: '',
syslogServer: '',
syslogServerErr: false,
statusFile: '',
interfaceName: '',
macAddr: '',
ipAddr: '',
errors: 0,
isConfigLoading: false
};
this.onSubmit = this.onSubmit.bind(this);
this.inputIsValid = this.inputIsValid.bind(this);
}
componentDidMount() {
this.setState({isConfigLoading: true});
RestAPI.getConfig()
.then(response => response.json())
.then(
data => this.setState(
{
httpPort: data.http_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,
sapInterval: data.sap_interval,
syslogProto: data.syslog_proto,
syslogServer: data.syslog_server,
statusFile: data.status_file,
interfaceName: data.interface_name,
macAddr: data.mac_addr,
ipAddr: data.ip_addr,
isConfigLoading: false
}))
.catch(err => this.setState({isConfigLoading: false}));
}
inputIsValid() {
return !this.state.playoutDelayErr &&
!this.state.ticFrameSizeAt1fsErr &&
!this.state.maxTicFrameSizeErr &&
!this.state.rtpMcastBaseErr &&
!this.state.rtpPortErr &&
!this.state.sapIntervalErr &&
!this.state.syslogServerErr &&
!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.playoutDelay,
this.state.ticFrameSizeAt1fs,
this.state.sampleRate,
this.state.maxTicFrameSize,
this.state.sapInterval)
.then(response => toast.success('Config updated, daemon restart ...'));
}
render() {
return (
{this.state.isConfigLoading ?
:
Audio Config
}
{this.state.isConfigLoading ?
:
Network Config
}
{this.state.isConfigLoading ?
:
Logging Config
}
)
}
}
export default Config;