Skip to content

Commit

Permalink
Fixing Soundcloud music service, anonymous service adding, removing s…
Browse files Browse the repository at this point in the history
…ervices
  • Loading branch information
pascalopitz committed Jun 2, 2020
1 parent fba10a7 commit 974cb60
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 37 deletions.
6 changes: 6 additions & 0 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const maskJson = require('mask-json')(blacklist);

const wakeEvent = require('wake-event');

const deviceProviderName = 'unofficial-sonos-controller-for-linux';

let win;

function createWindow() {
Expand Down Expand Up @@ -128,6 +130,10 @@ function createWindow() {

Menu.setApplicationMenu(menu);

win.webContents.setUserAgent(
// Thanks SoCo: https://github.com/SoCo/SoCo/blob/18ee1ec11bba8463c4536aa7c2a25f5c20a051a4/soco/music_services/music_service.py#L55
`Linux UPnP/1.0 Sonos/36.4-41270 (ACR_:${deviceProviderName})`
);
win.loadURL(
url.format({
pathname: path.join(__dirname, 'window.html'),
Expand Down
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.2.0-beta2",
"version": "0.2.0-beta2.1",
"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.2.0-beta2",
"version": "0.2.0-beta2.1",
"description": "Unoffical sonos controller for linux",
"main": "app/main.js",
"homepage": "http://pascalopitz.github.io/unoffical-sonos-controller-for-linux/",
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/BrowserListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class InlineMenu extends PureComponent {
item.metadata.class === 'object.item.audioItem.audioBroadcast');

const isService = item.action === 'service';
const isSonosPlaylist = item._raw.parentID === 'SQ:';
const isSonosPlaylist = item._raw && item._raw.parentID === 'SQ:';

const scrollContainerNode = getClosest(
containerRef.current,
Expand Down
4 changes: 2 additions & 2 deletions src/ui/helpers/sonos.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class SonosEnhanced extends Sonos {
return new ContentDirectoryEnhanced(this.host, this.port);
}

async getHouseholdId() {
async getZPInfo() {
const data = await request(
'http://' + this.host + ':' + this.port + '/status/zp'
)
.then((response) => response.data)
.then(Helpers.ParseXml);

return data.ZPSupportInfo.ZPInfo.HouseholdControlID;
return data.ZPSupportInfo.ZPInfo;
}

async getAvailableServices() {
Expand Down
27 changes: 10 additions & 17 deletions src/ui/reducers/BrowserListReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const initialState = {
],
};

const resetState = () => {
return {
...initialState,
};
};

export default handleActions(
{
[Constants.BROWSER_SEARCH]: (state, action) => {
Expand Down Expand Up @@ -102,23 +108,10 @@ export default handleActions(
};
},

[Constants.BROWSER_HOME]: () => {
return {
...initialState,
};
},

[Constants.MUSICSERVICE_AUTH_TOKEN_RECEIVED]: () => {
return {
...initialState,
};
},

[Constants.MUSICSERVICE_SESSION_ID_RECEIVED]: () => {
return {
...initialState,
};
},
[Constants.BROWSER_HOME]: resetState,
[Constants.MUSICSERVICE_AUTH_TOKEN_RECEIVED]: resetState,
[Constants.MUSICSERVICE_ANONYMOUS]: resetState,
[Constants.MUSICSERVICE_SESSION_ID_RECEIVED]: resetState,

[Constants.BROWSER_BACK]: (state) => {
const { history } = state;
Expand Down
1 change: 1 addition & 0 deletions src/ui/reducers/MusicServicesReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default handleActions(
[Constants.MUSICSERVICE_ADD_CANCEL]: closeDialogue,
[Constants.MUSICSERVICE_AUTH_TOKEN_RECEIVED]: closeDialogue,
[Constants.MUSICSERVICE_SESSION_ID_RECEIVED]: closeDialogue,
[Constants.MUSICSERVICE_ANONYMOUS]: closeDialogue,
},
initialState
);
7 changes: 5 additions & 2 deletions src/ui/reduxActions/BrowserListActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,11 @@ const selectBrowseServices = async (item) => {

const selectService = async (item) => {
const client = new MusicServiceClient(item.service.service);
client.setAuthToken(item.service.authToken.authToken);
client.setKey(item.service.authToken.privateKey);

if (client.auth !== 'Anonymous') {
client.setAuthToken(item.service.authToken.authToken);
client.setKey(item.service.authToken.privateKey);
}

const res = await client.getMetadata('root', 0, 100);
const searchTermMap = await client.getSearchTermMap();
Expand Down
9 changes: 8 additions & 1 deletion src/ui/reduxActions/MusicServicesActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,12 @@ export const getLink = createAction(
);

export const addAnonymousService = createAction(
Constants.MUSICSERVICE_ANONYMOUS
Constants.MUSICSERVICE_ANONYMOUS,
async (client) => {
// TODO: fix this
await SonosService.rememberMusicService(
client._serviceDefinition,
null
);
}
);
21 changes: 10 additions & 11 deletions src/ui/services/MusicServiceClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { Helpers } from 'sonos';
import SonosService from '../services/SonosService';

const NS = 'http://www.sonos.com/Services/1.1';
const deviceProviderName = 'unofficial-sonos-controller-for-linux';
const RUNTIME_ID = 'unofficial-sonos-controller-for-linux';
const deviceProviderName = 'Sonos';

function withinEnvelope(body, headers = '') {
return [
Expand Down Expand Up @@ -43,8 +42,7 @@ class MusicServiceClient {
headers: {
SOAPAction: `"${NS}#${action}"`,
'Content-type': 'text/xml; charset=utf8',
// Thanks SoCo: https://github.com/SoCo/SoCo/blob/18ee1ec11bba8463c4536aa7c2a25f5c20a051a4/soco/music_services/music_service.py#L55
'User-Agent': `Linux UPnP/1.0 Sonos/36.4-41270 (ACR_:${deviceProviderName})`,
'Accept-Language': 'en,en-AU;q=0.9,en-US;q=0.5',
},
body: soapBody,
});
Expand Down Expand Up @@ -235,7 +233,7 @@ class MusicServiceClient {
const headers = [
'<ns:credentials>',
'<ns:deviceId>',
RUNTIME_ID,
SonosService.deviceId,
'</ns:deviceId>',
'<ns:deviceProvider>',
deviceProviderName,
Expand Down Expand Up @@ -296,7 +294,7 @@ class MusicServiceClient {
const headers = [
'<ns:credentials>',
'<ns:deviceId>',
RUNTIME_ID,
SonosService.deviceId,
'</ns:deviceId>',
'<ns:deviceProvider>',
deviceProviderName,
Expand Down Expand Up @@ -353,6 +351,7 @@ class MusicServiceClient {
'<ns:count>',
count,
'</ns:count>',
'<ns:recursive>false</ns:recursive>',
'</ns:getMetadata>',
].join('');

Expand Down Expand Up @@ -480,7 +479,7 @@ class MusicServiceClient {
const headers = [
'<ns:credentials>',
'<ns:deviceId>',
RUNTIME_ID,
SonosService.deviceId,
'</ns:deviceId>',
'<ns:deviceProvider>',
deviceProviderName,
Expand Down Expand Up @@ -519,7 +518,7 @@ class MusicServiceClient {
return [
'<ns:credentials>',
'<ns:deviceId>',
RUNTIME_ID,
SonosService.deviceId,
'</ns:deviceId>',
'<ns:deviceProvider>',
deviceProviderName,
Expand All @@ -535,7 +534,7 @@ class MusicServiceClient {
return [
'<ns:credentials>',
'<ns:deviceId>',
RUNTIME_ID,
SonosService.deviceId,
'</ns:deviceId>',
'<ns:deviceProvider>',
deviceProviderName,
Expand All @@ -548,7 +547,7 @@ class MusicServiceClient {
this.key,
'</ns:key>',
'<ns:householdId>',
SonosService.householdId,
SonosService.householdId.split('.')[0],
'</ns:householdId>',
'</ns:loginToken>',
'</ns:credentials>',
Expand All @@ -558,7 +557,7 @@ class MusicServiceClient {
return [
'<ns:credentials>',
'<ns:deviceId>',
RUNTIME_ID,
SonosService.deviceId,
'</ns:deviceId>',
'<ns:deviceProvider>',
deviceProviderName,
Expand Down
5 changes: 4 additions & 1 deletion src/ui/services/SonosService.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ const SonosService = {
const [first] = devices;
const groups = await first.getAllGroups();

this.householdId = await first.getHouseholdId().catch(() => null);
const zpInfo = await first.getZPInfo().catch(() => {});

this.householdId = zpInfo.HouseholdControlID;
this.deviceId = zpInfo.SerialNumber;

Listener.on('ZonesChanged', (...args) =>
this.onZoneGroupTopologyEvent(first, ...args)
Expand Down

0 comments on commit 974cb60

Please sign in to comment.