diff options
author | Renard | 2020-03-09 18:48:23 -0300 |
---|---|---|
committer | Renard | 2020-03-09 18:48:23 -0300 |
commit | 4adaf01b3cdc86d560f9c5786a1b66690b757179 (patch) | |
tree | 040443a2367318e8aebb7f8982f4f52e2efa3fca | |
parent | 70c00e125a1083faf9f48f960f3bad77e87b6e76 (diff) | |
download | bairadio-app-4adaf01b3cdc86d560f9c5786a1b66690b757179.tar.gz bairadio-app-4adaf01b3cdc86d560f9c5786a1b66690b757179.tar.xz bairadio-app-4adaf01b3cdc86d560f9c5786a1b66690b757179.zip |
Fix: multiple sources
-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(); |