diff options
Diffstat (limited to 'src/App.js')
-rw-r--r-- | src/App.js | 38 |
1 files changed, 31 insertions, 7 deletions
@@ -29,13 +29,14 @@ class App extends Component { selectedStream: 0 }; this.streamCount = 0; + this.streamName = ""; } - checkStream(result) { + checkStream(source) { const prevCount = this.streamCount; - if (result.source !== undefined) { - if (Array.isArray(result)) { - this.streamCount = result.length; + if (source !== undefined) { + if (Array.isArray(source)) { + this.streamCount = source.length; } else { this.streamCount = 1; } @@ -109,8 +110,8 @@ class App extends Component { .then(response => response.json()) .then(result => { this.debug(result); - this.checkStream(result); const source = result.icestats.source; + const countChanged = !this.checkStream(source); if (source !== undefined) { let multipleStreams = Array.isArray(source); if (!multipleStreams && Array.isArray(this.state.response.source)) { @@ -135,13 +136,29 @@ class App extends Component { }) ); } + let prevSelectedStream = this.state.selectedStream; + if (countChanged) { + let prevStream = source.find( + s => s.server_name === this.streamName + ); + prevSelectedStream = source.indexOf(prevStream); + if (prevSelectedStream === -1) { + prevSelectedStream = 0; // TODO: Mostrar mensaje + } + if (this.state.selectedStream !== prevSelectedStream) { + this.refreshPlayer(); + } + } this.setState( { response: result.icestats, streamsAvailable: streams, - multipleSources: multipleStreams + multipleSources: multipleStreams, + selectedStream: prevSelectedStream }, - () => this.compareSongs() + () => { + this.compareSongs(); + } ); } } else { @@ -170,6 +187,7 @@ class App extends Component { }, () => { const { source } = this.state.response; + this.checkStream(source); if (source !== undefined && Array.isArray(source)) { let streams = []; source.map((stream, index) => @@ -185,12 +203,14 @@ class App extends Component { streamsAvailable: streams, ready: true }); + this.streamName = source[0].server_name; } else if (source !== undefined) { this.setState({ multipleSources: false, selectedStream: 0, ready: true }); + this.streamName = source.server_name; } } ) @@ -276,8 +296,12 @@ class App extends Component { fluid selection options={streamsAvailable} + value={selectedStream} onChange={(e, d) => this.setState({ selectedStream: d.value }, () => { + this.streamName = this.state.response.source[ + d.value + ].server_name; let audio = document.getElementById("player"); if (audio !== null) { audio.pause(); |