diff --git a/src/js/components/DebugInfo.js b/src/js/components/DebugInfo.js index 1716ff51..1c2d8564 100755 --- a/src/js/components/DebugInfo.js +++ b/src/js/components/DebugInfo.js @@ -77,6 +77,9 @@ class DebugInfo extends React.Component{
Processes: {this.props.ui.processes ? Object.keys(this.props.ui.processes).length : '0'}
+
+ Enqueue batches: {this.props.mopidy.enqueue_uris_batches ? this.props.mopidy.enqueue_uris_batches.length : '0'} +

_testMode: {window._testMode ? 'on' : 'off'} @@ -92,7 +95,8 @@ class DebugInfo extends React.Component{ const mapStateToProps = (state, ownProps) => { return { - ui: state.ui + ui: state.ui, + mopidy: state.mopidy } } diff --git a/src/js/services/mopidy/middleware.js b/src/js/services/mopidy/middleware.js index cf7b8a2e..8695b906 100755 --- a/src/js/services/mopidy/middleware.js +++ b/src/js/services/mopidy/middleware.js @@ -312,7 +312,11 @@ const MopidyMiddleware = (function(){ var batches = store.getState().mopidy.enqueue_uris_batches var batch = batches[0] - store.dispatch(uiActions.startProcess('MOPIDY_ENQUEUE_URIS', 'Adding '+(batches.length*5)+' URI(s)')) + var total_uris = 0 + for (var i = 0; i < batches.length; i++){ + total_uris += batches[i].uris.length + } + store.dispatch(uiActions.startProcess('MOPIDY_ENQUEUE_URIS', 'Adding '+total_uris+' URI(s)')) // no batches means we're done here } else { @@ -334,8 +338,21 @@ const MopidyMiddleware = (function(){ } var params = {uris: batch.uris} - if (batch.next && current_track_index > -1){ - params.at_position = current_track_index + 1 + + // Play this batch next + if (batch.next){ + + // Make sure we're playing something first + if (current_track_index > -1){ + params.at_position = current_track_index + 1 + + // Default to top of queue if we're not playing + } else { + params.at_position = 0 + } + + // A specific position has been defined + // NOTE: This is likely to be wrong as the original action is unaware of batches or other client requests } else if (batch.at_position){ params.at_position = batch.at_position } @@ -350,15 +367,16 @@ const MopidyMiddleware = (function(){ } store.dispatch(pusherActions.addQueueMetadata(tlids, batch.from_uri)) - // still more URIs? run again in 100ms - // this gives our server time to handle other requests - // crude, but prevents locking the server + // Re-run the batch checker in 100ms. This allows a small window for other + // server requests before our next batch. It's a little crude but it means the server isn't + // locked until we're completely done. setTimeout( function(){ store.dispatch(mopidyActions.enqueueURIsBatchDone()) store.dispatch(mopidyActions.enqueueUrisProcessor()) }, - 100 + 5000 + //100 ) })