Skip to main content
Headliner II
March 5, 2013

Sonos with node.js, my attempt!

INFO

Source code here: https://github.com/jishi/node-sonos-http-api
Sonos Web Controller draft (work in progress!): https://github.com/jishi/node-sonos-web-controller
Sonos IR control (requires lircd and IR reciever): https://github.com/jishi/node-sonos-remote-control

==============================================================


I know that there already is an attempt at this by this guy: http://forums.sonos.com/showthread.php?t=32643, but I found it to be a bit lacking in functionality so I decided to write up my own.

I have created a simple web-based API using what I have, which could be useful for integrating stuff with other applications. This web based API is inspired by other RESTful APIs, however I don't think it follows the correct guidelines to be called a REST API.

IT supports most basic features like:

play, pause, seek, next, prev, volume, mute, setAVTransportURI

It also supports these advanced fatures:

State of player as JSON, zone info as JSON, Play favorite item, presets (grouping, volume, avTransportURI)

You can read more in the README for each project.

To run it as a service under linux, I suggest using pm2 (https://github.com/Unitech/pm2). You need to run it in forked mode (-x)!

For Windows, you might try Winser http://jfromaniello.github.io/winser/

Cheers!
    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.

    391 replies

    Contributor I
    November 8, 2013
    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
    Trending Lyricist I
    November 11, 2013
    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,
    jishiAuthor
    Headliner II
    November 11, 2013
    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.
    jishiAuthor
    Headliner II
    November 11, 2013
    Actually, I think it really should be there so I committed a fix. Pull or download it again and see if it works.
    Trending Lyricist I
    November 11, 2013
    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.
    jishiAuthor
    Headliner II
    November 11, 2013
    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 🙂
    Trending Lyricist I
    November 12, 2013
    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....
    jishiAuthor
    Headliner II
    November 12, 2013
    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.
    jishiAuthor
    Headliner II
    November 12, 2013
    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...
    Contributor I
    November 13, 2013
    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.