// // RemoteSource.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 PropTypes from 'prop-types'; import RestAPI from './Services'; import Loader from './Loader'; import SourceInfo from './SourceInfo'; require('./styles.css'); class RemoteSourceEntry extends Component { static propTypes = { source: PropTypes.string.isRequired, id: PropTypes.string.isRequired, name: PropTypes.string.isRequired, domain: PropTypes.string.isRequired, address: PropTypes.string.isRequired, sdp: PropTypes.string.isRequired, last_seen: PropTypes.number.isRequired, period: PropTypes.number.isRequired, onInfoClick: PropTypes.func.isRequired, }; constructor(props) { super(props); this.state = { rtp_address: 'n/a', port: 'n/a' }; } handleInfoClick = () => { this.props.onInfoClick(this.props.id); }; componentDidMount() { var rtp_address = this.props.sdp.match(/(c=IN IP4 )([0-9.]+)/g); var port = this.props.sdp.match(/(m=audio )([0-9]+)/g); if (rtp_address && port) { this.setState({ rtp_address: rtp_address[0].substr(9), port: port[0].substr(8) }); } } render() { return ( ); } } class RemoteSourceList extends Component { static propTypes = { onReloadClick: PropTypes.func.isRequired }; handleReloadClick = () => { this.props.onReloadClick(); }; render() { return (
{this.props.sources.length > 0 ? : } {this.props.sources}
Source Address Name Domain RTP Address Port Seen Period
No remote sources found.
    
); } } class RemoteSources extends Component { constructor(props) { super(props); this.state = { sources: [], isLoading: false, infoIsOpen: false, infoTitle: '' }; this.onInfoClick = this.onInfoClick.bind(this); this.onReloadClick = this.onReloadClick.bind(this); this.openInfo = this.openInfo.bind(this); this.closeInfo = this.closeInfo.bind(this); this.fetchRemoteSources = this.fetchRemoteSources.bind(this); } fetchRemoteSources() { this.setState({isLoading: true}); RestAPI.getRemoteSources() .then(response => response.json()) .then( data => this.setState( { sources: data.remote_sources, isLoading: false })) .catch(err => this.setState( { isLoading: false } )); } componentDidMount() { this.fetchRemoteSources(); } openInfo(title, source) { this.setState({infoIsOpen: true, infoTitle: title, source: source}); } closeInfo() { this.setState({infoIsOpen: false}); this.fetchRemoteSources(); } onInfoClick(id) { const source = this.state.sources.find(s => s.id === id); this.openInfo("Announced Source Info", source, true); } onReloadClick() { this.fetchRemoteSources(); } render() { //this.state.sources.sort((a, b) => (a.id > b.id) ? 1 : -1); const sources = this.state.sources.map((source) => ( )); return (
{ this.state.isLoading ? : } { this.state.infoIsOpen ? : undefined }
); } } export default RemoteSources;