From f556d07cbaf4a830705f18fa56b7b1bf470fdf89 Mon Sep 17 00:00:00 2001 From: Pascal Opitz Date: Wed, 7 Jun 2017 20:39:53 +0930 Subject: [PATCH] Stripping out bridges, search result more scrolling, fix state breakage when search ends --- app/package.json | 2 +- package.json | 2 +- src/ui/actions/BrowserListActions.js | 17 +++++++++++++++++ src/ui/actions/SearchBarActions.js | 5 ++++- src/ui/components/BrowserList.jsx | 2 +- src/ui/constants/Constants.js | 1 + src/ui/helpers/resourceLoader.js | 2 +- src/ui/services/SonosService.js | 17 ++++++++++++----- src/ui/sonos/Sonos.js | 5 +++++ src/ui/stores/BrowserListStore.js | 5 +++++ 10 files changed, 48 insertions(+), 10 deletions(-) diff --git a/app/package.json b/app/package.json index 4949c2b..186747b 100644 --- a/app/package.json +++ b/app/package.json @@ -1,7 +1,7 @@ { "name": "sonos-controller-unofficial", "description": "Unoffical sonos controller for linux.", - "version": "0.0.11", + "version": "0.0.12", "author": "Pascal Opitz ", "main": "main.js", "dependencies": { diff --git a/package.json b/package.json index 6baf2b8..d0aa247 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sonos-controller-unofficial", - "version": "0.0.11", + "version": "0.0.12", "description": "Unoffical sonos controller for linux", "main": "app/main.js", "scripts": { diff --git a/src/ui/actions/BrowserListActions.js b/src/ui/actions/BrowserListActions.js index 3237215..a4fed8e 100644 --- a/src/ui/actions/BrowserListActions.js +++ b/src/ui/actions/BrowserListActions.js @@ -58,6 +58,10 @@ export default { start: state.items.length }; + if (state.items.length >= state.total) { + return; + } + const client = state.serviceClient; if(client && state.total > state.items.length) { @@ -95,6 +99,19 @@ export default { state: state, }); }); + } else if(state.search) { + sonos.searchMusicLibrary(state.type, state.term, params, (err, result) => { + if(err || !result || !result.items) { + return; + } + + state.items = state.items.concat(result.items); + + Dispatcher.dispatch({ + actionType: Constants.BROWSER_SEARCH_SCROLL_RESULT, + state: state, + }); + }); } else { sonos.getMusicLibrary(state.id || state.searchType, params, (err, result) => { if(err || !result || !result.items) { diff --git a/src/ui/actions/SearchBarActions.js b/src/ui/actions/SearchBarActions.js index fcbb644..d0d2a51 100644 --- a/src/ui/actions/SearchBarActions.js +++ b/src/ui/actions/SearchBarActions.js @@ -1,3 +1,4 @@ +import _ from 'lodash'; import Dispatcher from '../dispatcher/AppDispatcher'; import Constants from '../constants/Constants'; @@ -21,7 +22,9 @@ function createSearchPromise(type, term, options) { return; } - resolve(result); + resolve(_.assign(result, { + type, term, search: true, + })); }); }); } diff --git a/src/ui/components/BrowserList.jsx b/src/ui/components/BrowserList.jsx index 8ca1e3f..f0dc024 100644 --- a/src/ui/components/BrowserList.jsx +++ b/src/ui/components/BrowserList.jsx @@ -73,7 +73,7 @@ class BrowserList extends Component { } } - _playAlbum (e) { + _playAlbum () { BrowserListActions.play(this.state.currentState); } diff --git a/src/ui/constants/Constants.js b/src/ui/constants/Constants.js index 5313b92..31c89cc 100644 --- a/src/ui/constants/Constants.js +++ b/src/ui/constants/Constants.js @@ -8,6 +8,7 @@ const Constants = { BROWSER_SELECT_ITEM: '', BROWSER_SCROLL_RESULT: '', + BROWSER_SEARCH_SCROLL_RESULT: '', BROWSER_BACK: '', BROWSER_HOME: '', BROWSER_PLAY: '', diff --git a/src/ui/helpers/resourceLoader.js b/src/ui/helpers/resourceLoader.js index 6c667b6..f8f19e5 100644 --- a/src/ui/helpers/resourceLoader.js +++ b/src/ui/helpers/resourceLoader.js @@ -1,6 +1,6 @@ import _ from 'lodash'; -const MAX_CONNECTIONS = 5; +const MAX_CONNECTIONS = 35; const heap = []; const pending = {}; diff --git a/src/ui/services/SonosService.js b/src/ui/services/SonosService.js index 0182766..f331632 100644 --- a/src/ui/services/SonosService.js +++ b/src/ui/services/SonosService.js @@ -38,6 +38,10 @@ const SonosService = { new Search((sonos) => { + if (sonos.model.match(/^BR/)) { + return; + } + bb.promisifyAll(sonos); if(this._searchInterval) { @@ -71,9 +75,10 @@ const SonosService = { listener.addService('/SystemProperties/Event', persistSubscription); this.queryCurrentTrackAndPlaystate(sonos); + this.queryTopology(sonos); if(!firstResultProcessed) { - this.queryTopology(sonos); + this.queryAccounts(sonos); sonos.getHouseholdId((err, hhid) => { @@ -86,6 +91,7 @@ const SonosService = { }); listener.addService('/ZoneGroupTopology/Event', persistSubscription); + firstResultProcessed = true; } }); @@ -138,12 +144,11 @@ const SonosService = { zone: zone, }); }, 500); - } Dispatcher.dispatch({ actionType: Constants.SONOS_SERVICE_TOPOLOGY_UPDATE, - groups: this.excludeStereoPairs(info.zones), + groups: this.excludeStereoPairsAndBridges(info.zones), }); }); }, @@ -403,7 +408,7 @@ const SonosService = { Dispatcher.dispatch({ actionType: Constants.SONOS_SERVICE_TOPOLOGY_EVENT, - groups: this.excludeStereoPairs(zones), + groups: this.excludeStereoPairsAndBridges(zones), }); } break; @@ -550,7 +555,7 @@ const SonosService = { } }, - excludeStereoPairs (zones) { + excludeStereoPairsAndBridges (zones) { // TODO: find a better place for this zones.forEach((z) => { @@ -564,6 +569,8 @@ const SonosService = { g[0].name = g[0].name + ' (L + R)'; } return _.find(g, { 'coordinator': 'true' }) || g[0]; + }).filter((z) => { + return _.includes(_.keys(this._deviceSearches), z.host); }).value(); }, diff --git a/src/ui/sonos/Sonos.js b/src/ui/sonos/Sonos.js index 12837f0..361affb 100644 --- a/src/ui/sonos/Sonos.js +++ b/src/ui/sonos/Sonos.js @@ -178,11 +178,16 @@ class Sonos { RequestedCount: '100', SortCriteria: '' }; + const searches = searchTypes[searchType] + ':' + searchTerm; + let opts = { ObjectID: searches }; + if(options.start !== undefined) {opts.StartingIndex = options.start;} + if(options.total !== undefined) {opts.RequestedCount = options.total;} + opts = _.extend(defaultOptions, opts); const contentDirectory = new Services.ContentDirectory(this.host, this.port); return contentDirectory.Browse(opts, function (err, data) { diff --git a/src/ui/stores/BrowserListStore.js b/src/ui/stores/BrowserListStore.js index 201264d..d498575 100644 --- a/src/ui/stores/BrowserListStore.js +++ b/src/ui/stores/BrowserListStore.js @@ -101,6 +101,7 @@ const BrowserListStore = _.assign({}, events.EventEmitter.prototype, { endSearch () { this._search = false; + this._history = _.without(this._history, 'search'); }, getSearchMode () { @@ -172,6 +173,10 @@ Dispatcher.register(action => { BrowserListStore.emitChange(); break; + case Constants.BROWSER_SEARCH_SCROLL_RESULT: + BrowserListStore.emitChange(); + break; + case Constants.BROWSER_CHANGE_SEARCH_MODE: BrowserListStore._searchTarget = action.mode; BrowserListStore.emitChange();