Sonos with node.js, my attempt!



Show first post
This topic has been closed for further comments. You can use the search bar to find a similar topic, or create a new one by clicking Create Topic at the top of the page.

397 replies

Userlevel 4
Badge +14
Current status:

http://upload.grabbarna.se/files/sonos-web-controller-0.4.2.png, you can update it like usual (git pull, rm -r node_modules, npm install)

I have added functional queue listing, which means that it list the queue of the selected zone and you can double click in it to change track. It will lazy load the album art from the players (I use all players for this to speed things up), and then cache it locally for faster access next time. First time load can be a pain though, if you have a large queue.

It doesn't lazy load the queue, but load it in batches of 100 items. On a 3000 items queue this takes approx 30 seconds on my machine, but I think the bottleneck is the Sonos players.

I haven't yet optimized the loading behavior and it is kind of heavy on the browser atm, and it will not reflect changes to the queue yet.

Regarding memory foot print, it seems like there has been some changes between v 0.8 and 0.10. In 0.8 I rarely got over 30 MB, but in 0.10 I can easily use up towards 70 MB. Some says that they have introduced a less aggressive garbage collect, which might explain this. However, it would be nice to hear about your impressions on systems with less RAM, because hopefully it would be more aggressive when you have little free RAM left.
Userlevel 2
I can report after 36 hours of continuous run time node shows no significant change in memory utilization. Configuration is:
freeBSD 9.1
node - development 0.9.3
Web Clients include: Windows, Puppy linux, Ipad, Z10 and Android.

Thanks
Userlevel 4
Badge +14
And a lot of that time it would seem that the "page" is in the background browser window.

Could you explain what you mean by that?
Userlevel 4
Badge +14
I haven't really looked into the memory utilization yet, so any observations are of interest.

I don't know how aggressive the garbage collect in node is, and if you have a lot of free memory I wouldn't be surprised it the memory usage seems high. When you've had it running for a few days, it would be nice to hear what your consumption would be.
Hey J,

Been running the controller through pm2 for just over an hour now....

I've noticed on the "pm2 list", that the memory in use seems to be "slowly" increasing from:

22.5 mb, up to currently 41.992 mb....

Not saying there's a memory leak, as I have no idea what exactly pm2 is reporting for memory utilization. And a lot of that time it would seem that the "page" is in the background browser window.

But I thought you should know, since it's maybe something related to the node 10.0.21 build I've got vs your 0.8.x....
Agreed.... I've got node running in a ubuntu vm, and hosting from there....

So far any testing from desktops and the netbook are working.... Haven't tried the ipad, or the "phablet", phones....

Definitely great work.....
Userlevel 2
Starting to look very good!! I have been following the development closely. I currently have the nodejs webserver hosted on my NAS4Free box running freeBSD. All functions work nicely and so far it makes a very useable controller and is super quick. Keep up the good work. Works with most browsers even mobile devices are reasonably functional. Keep this up and we might actually have a workable controller for the Linux community finally. Thanks again. Any basic assistance or testing required, if I can help certainly let me know. Ynot.
Userlevel 4
Badge +14
Okay, did a basic implementation of favorite selection, double clicking the favorite will replace the queue (or start radio).

I also recorded a video for those of you who don't want to mess around with node and git to try it out, this is how it looks like:

http://www.youtube.com/watch?v=Ad80vH1igFU

Actually, I'm pretty impressed my self with how good it actually behaves in a web browser...
Userlevel 4
Badge +14
I implemented some group management (not sure if something is missing, have I missed something?).

I didn't do the Sonos way because I think it sucks, so I did a drag and drop solution instead. Drag the player name onto another zone to move it, or drop it outside all zones to detach it as a standalone player. What do you guys think about that? I just realized that it might be a problem of you have a lot of players which actually fills up the whole left column, but I will try and find a solution to that.

This will of course not work on a touch device, but the intended usage for this is a desktop (I will focus on a mobile version and a tablet version later). Just realize that a web controller would be useful for ChromeOS users as well.
Cool....

git updates "instruction" reading is obviously going to be on the list...

I also got your suggested pm2 scheduler running, so the server.js can now start on startup.... Much easier to setup configure etc, over the forever, etc.... It's not perfect, I think I have to bounce the pm2 id's on reboot, but after that it has been seeming pretty stable.

So it's definitely coming together.

Nice job....
Userlevel 4
Badge +14
No problem, it's good to get it sorted out. I pushed an update which implements a working group volume now as well. It uses the scroll wheel in the same manner as the official client, but haven't fixed the click adjustment yet. You could adjust volume before, but it never reflected the volume on load, or when adjusted in another client. This do work now.

Soon all the basic control is in place, which will be a milestone 🙂
Will do....

In a little bit of time troubleshooting here this afternoon, I remembered I removed nvm (version manager) when I was trying to get the services working....

So I thought, could be a version 0.8 to 0.10 bug....

So I reinstalled nvm, and then ran this with v0.8 on the original code, and everything seems to work.

I'll change back up to the v0.10 through nvm, and try your fixed server.js, and let you know.

Thanks... for the quick turn around.
Userlevel 4
Badge +14
Actually, I think it really should be there so I committed a fix. Pull or download it again and see if it works.
Userlevel 4
Badge +14
Well, the output seems fine, ad if the browser doesn't get a response, there is probably something regarding how I serve static content.

I see one major difference between steffest fork and mine, and that is on row 14 in server.js:

code:

fileServer.serve(req, res);
}).resume();

vs

fileServer.serve(req, res);
});


I'm missing that resume() statement, which might act up on another platform (because in windows this is fine). It might even be a difference between node 0.8 and 0.10.

Could you try and add it manually and see if that works? I will fix it if that's the case.
Hey J,

Was trying out the new build.... so I took a backup of the ubuntu vm.... then patched everything.... After clean restart... did a tar file for the current node_web_controller and the http-api....

So then I did the fresh grab from git.....

http-api is working, minus the presets, which could just be my coding of the file.... But I can control the volume, etc....

So I thought perfect, I went to the web controller, since I wanted to see what the new version was like..... Installed the new modules in a cleaned out directory (the old files had been deleted).... Then I started the server.js.....

The console window seemed to stop here for a while:

code:
triggering state volume Master Bedroom
triggering state volume Office
triggering state volume LittleRm
triggering state volume Living Room
triggering state volume Rec Room
trying to subscribe to topology 192.168.10.190
triggering state volume Kitchen
undefined 'is active, clearing'
setting timeout
undefined 'is active, clearing'
setting timeout
undefined 'is active, clearing'
setting timeout
undefined 'is active, clearing'
setting timeout
trying to subscribe to topology 192.168.10.194
undefined 'is active, clearing'
setting timeout
undefined 'is active, clearing'
setting timeout
stream end
stream end
stream end
stream end
stream end
stream end


But then it started to receive updates etc, when it was running.

But the web server never seems to respond to a request to load from Chrome or FF.... (30 and 25).

If I old the old untouched version of the code I got from Steffest (fork) back in July, it works from a web perspective.

Let me know what info you need.....

ubuntu 12.10 running in a vmware vm
node v 10.....

TIA,
Userlevel 2
I will take a peek at how it looks / works on the BB Z10 and let you know.

Controller works on BB Z10 except for volume slider control
Userlevel 2
Nice to hear. supporting mobile devices will be the next step, and I will probably allow for a different layout for these devices (meaning, /m url would have a different template set). However, I think that Blackberry phones can be tricky to support.

I will take a peek at how it looks / works on the BB Z10 and let you know.
Userlevel 4
Badge +14
Jishi,
Fiddled around with the web controller using puppy linux and it is starting to look quite promising. Performance is excellent. Eventually I would like to host this server app on my Nas4Free box based on freebsd. I had the purple controller working a while back but its functionality is quite dated. My "clients" would be linux desktops, blackberry phones, android and apple "guest" devices and windows stations as well.

Keep up the good work.


Nice to hear. supporting mobile devices will be the next step, and I will probably allow for a different layout for these devices (meaning, /m url would have a different template set). However, I think that Blackberry phones can be tricky to support.
Userlevel 2
Jishi,
Fiddled around with the web controller using puppy linux and it is starting to look quite promising. Performance is excellent. Eventually I would like to host this server app on my Nas4Free box based on freebsd. I had the purple controller working a while back but its functionality is quite dated. My "clients" would be linux desktops, blackberry phones, android and apple "guest" devices and windows stations as well.

Keep up the good work.
Userlevel 4
Badge +14
Hi buzz. Nice to hear that there actually is an interest, so my work isn't completely in vain :)

I'll start a new thread for the web controller when I feel like the basic functions are fully functional, maybe that'll get more attention.
jishi,

I have negative free time at the moment, but your projects, especially with the raspberry pi, are causing me to develop an "itch" to join the fun.
Userlevel 4
Badge +14
I have taken some time to revive the web controller project I was working on. I have now managed to get the top buttons working (prev, play, next) as well as the position bar (only status, no seek functionality), and the track info.

This updates, instantly, if you control sonos from any other controller, like one would expect.

http://upload.grabbarna.se/files/sonos-web-controller.png

Might not be considered a huge leap in functionality, bit I spent most of the time rewriting stuff that wasn't well thought of. If I finish it, would you use it?
Userlevel 4
Badge +14
From the idea shared here: http://forums.sonos.com/showthread.php?t=16130

I added the simple feature to have an optional timeout with "pauseall", which can easily be used as a sleep function.
Userlevel 4
Badge +14
Just wanted to share that my previous on{x} script became a whole lot easier when having a raspberry pi in the background keeping track of the players.

http://forums.sonos.com/showthread.php?t=30387&highlight=on%7Bx%7D

new code:

code:

// Pauses the queue in the Sonos when a call starts
device.telephony.on('busy', function () {
device.ajax({
url: 'http://192.168.1.112:5005/pauseall',
type: 'GET'
}, function () {});
var notification = device.notifications.createNotification('Pausing players, click to resume');
notification.on('click', function() {
console.log('Resuming players from notification');
device.ajax({
url: 'http://192.168.1.112:5005/resumeall',
type: 'GET'
}, function () {});
});
notification.show();
});

// Pauses the queue in the Sonos when a call starts
device.telephony.on('idle', function () {
// resuming players now
device.ajax({
url: 'http://192.168.1.112:5005/resumeall',
type: 'GET'
}, function () {});
});
Userlevel 4
Badge +14
Yeah, you are probably right. People probably think that crossfade should go in there as well.

I have added a new feature, pauseall and resumeall. This will pause the currently playing zones, and remember for subsequent resumeall calls, which will resume the players that was playing when you paused them.

Useful for home automation, when someone rings the doorbell or when you receive a phone call perhaps.