Skip to content

Commit

Permalink
Stripping out bridges, search result more scrolling, fix state breaka…
Browse files Browse the repository at this point in the history
…ge when search ends
  • Loading branch information
pascalopitz committed Jun 7, 2017
1 parent 858fc0f commit f556d07
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"main": "main.js",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
17 changes: 17 additions & 0 deletions src/ui/actions/BrowserListActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/ui/actions/SearchBarActions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash';
import Dispatcher from '../dispatcher/AppDispatcher';
import Constants from '../constants/Constants';

Expand All @@ -21,7 +22,9 @@ function createSearchPromise(type, term, options) {
return;
}

resolve(result);
resolve(_.assign(result, {
type, term, search: true,
}));
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/BrowserList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class BrowserList extends Component {
}
}

_playAlbum (e) {
_playAlbum () {
BrowserListActions.play(this.state.currentState);
}

Expand Down
1 change: 1 addition & 0 deletions src/ui/constants/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Constants = {

BROWSER_SELECT_ITEM: '',
BROWSER_SCROLL_RESULT: '',
BROWSER_SEARCH_SCROLL_RESULT: '',
BROWSER_BACK: '',
BROWSER_HOME: '',
BROWSER_PLAY: '',
Expand Down
2 changes: 1 addition & 1 deletion src/ui/helpers/resourceLoader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash';

const MAX_CONNECTIONS = 5;
const MAX_CONNECTIONS = 35;

const heap = [];
const pending = {};
Expand Down
17 changes: 12 additions & 5 deletions src/ui/services/SonosService.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const SonosService = {

new Search((sonos) => {

if (sonos.model.match(/^BR/)) {
return;
}

bb.promisifyAll(sonos);

if(this._searchInterval) {
Expand Down Expand Up @@ -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) => {
Expand All @@ -86,6 +91,7 @@ const SonosService = {
});

listener.addService('/ZoneGroupTopology/Event', persistSubscription);

firstResultProcessed = true;
}
});
Expand Down Expand Up @@ -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),
});
});
},
Expand Down Expand Up @@ -403,7 +408,7 @@ const SonosService = {

Dispatcher.dispatch({
actionType: Constants.SONOS_SERVICE_TOPOLOGY_EVENT,
groups: this.excludeStereoPairs(zones),
groups: this.excludeStereoPairsAndBridges(zones),
});
}
break;
Expand Down Expand Up @@ -550,7 +555,7 @@ const SonosService = {
}
},

excludeStereoPairs (zones) {
excludeStereoPairsAndBridges (zones) {

// TODO: find a better place for this
zones.forEach((z) => {
Expand All @@ -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();
},

Expand Down
5 changes: 5 additions & 0 deletions src/ui/sonos/Sonos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/ui/stores/BrowserListStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const BrowserListStore = _.assign({}, events.EventEmitter.prototype, {

endSearch () {
this._search = false;
this._history = _.without(this._history, 'search');
},

getSearchMode () {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f556d07

Please sign in to comment.