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

    Lyricist III
    November 27, 2013

    Doesn't the playbar have an auto line-in feature like all the other players though?


    Thanks for your quick answer.
    Yes the PlayBar could be configured to autoswitch to SPDIF then the TV will output signal on the SPDIF.

    My current solution is to switch the TV off and on. Also becuse it's a smart TV (not so smart att all) I like to control my music on the PlayBar from the TV browser.

    For sure I will use the Raspberry Pi IR functions.
    /Palle
    jishiAuthor
    Headliner II
    November 27, 2013
    Thanks for your quick answer.
    Yes the PlayBar could be configured to autoswitch to SPDIF then the TV will output signal on the SPDIF.

    My current solution is to switch the TV off and on. Also becuse it's a smart TV (not so smart att all) I like to control my music on the PlayBar from the TV browser.

    For sure I will use the Raspberry Pi IR functions.
    /Palle


    did the TV Browser work with this GUI?
    Lyricist III
    November 27, 2013
    did the TV Browser work with this GUI?

    Yes for sure. It's a LG midrange smart TV launced this year 2013, I think it use some derivate of Chrome. At startup i looks real nice, but after a while some texts is overlayed but all functions works fine.
    [edit] Checked and the scrollbars won't work, but the whole screen will scroll instead. Then Track, Artist, Album strings gets to long they will not do CR/LF instead they will move under the album picture and owerlaying the QUEUE text information.

    I found if I don't display the "mini TV frame" in the smart TV browser the TV sound will automatically return then i quit the smart TV browser and start watching TV. Works perfect for me!
    Lyricist III
    November 27, 2013
    Well my hats is off to you sir looking very good and As per the space thing I guess I was to blame will bang it more and let u know whats up but first blush and we are smiling Nice job
    Lyricist III
    November 27, 2013
    OK so how would one create a preset to u group a group playing and stop all.....Thanks
    jishiAuthor
    Headliner II
    November 27, 2013
    OK so how would one create a preset to u group a group playing and stop all.....Thanks

    Ungroup all players? That's not possible with one preset today, you need to create one preset for each player.

    If you just want to stop all of them, you can just send a pause signal for any player in the group (I assume you are talking about the HTTP API now)
    Lyricist III
    November 27, 2013
    Yes and thanks that will work for now...
    jishiAuthor
    Headliner II
    November 27, 2013
    Yes for sure. It's a LG midrange smart TV launced this year 2013, I think it use some derivate of Chrome. At startup i looks real nice, but after a while some texts is overlayed but all functions works fine.
    [edit] Checked and the scrollbars won't work, but the whole screen will scroll instead. Then Track, Artist, Album strings gets to long they will not do CR/LF instead they will move under the album picture and owerlaying the QUEUE text information.

    I found if I don't display the "mini TV frame" in the smart TV browser the TV sound will automatically return then i quit the smart TV browser and start watching TV. Works perfect for me!


    Yeah, I've heard that modern LG and Samsung is using a version of WebKit, but not sure which one. WebKit do however have some issues with my design because of the expected fixed window size. But for a TV, it would be better to create another UI which suits the format better, and which might be possible to control using the D-pad on the remote and similar. Unfortunately I don't have a smart-TV myself so I can't do any real testing. Next step is to try and create a mobile web UI which will be totally different than the official app, assuming that you can use the touch in an intuitive manner from a phone browser.
    Trending Lyricist I
    November 27, 2013
    New build of the web server seems to be working well.... Updated this afternoon, and just forced the replacement of the sonos-discovery....

    Now onto the http-api.

    Did a fresh git pull at the same time....

    Now, when I load it... I'm getting this:

    code:

    binding SSDP to port 2594
    scanning for players...
    port in use 3500 trying new one
    notification server listening on port 3501

    module.js:485
    throw err;
    ^
    SyntaxError:[path]/node-sonos-http-api/presets.json: Unexpected string
    at Object.parse (native)
    at Object.Module._extensions..json (module.js:482:27)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at [path]/node-sonos-http-api/server.js:12:13
    at Object.cb [as oncomplete] (fs.js:168:19)


    I figure I'm screwing up the presets.json, but I haven't quite figured how.

    I took your sample, and removed all references to your players, and replaced with mine....

    code:

    {
    "all": {"players": [{ "roomName": "LittleRm", "volume": 23 },{ "roomName": "Living Room", "volume": 27 },{ "roomName": "Kitchen", "volume": 18 },{ "roomName": "Office", "volume": 22 },{ "roomName": "Master Bedroom", "volume": 17 },{ "roomName": "Rec Room", "volume": 0 }]},
    "tv": {
    "players": [{ "roomName": "Rec Room", "volume": 50 }],
    "state": "stopped",
    "uri": "x-rincon-stream:RINCON_0000000000001400"
    },
    "AcidJazz": {
    "players": [{ "roomName": "Living Room", "volume": 27 },{ "roomName": "Kitchen", "volume": 18 },{ "roomName": "Office", "volume": 22 }],
    "favorite": "Acid Jazz Radio"
    }
    "Thiev": {
    "players": [{ "roomName": "Living Room", "volume": 27 },{ "roomName": "Kitchen", "volume": 18 },{ "roomName": "Office", "volume": 22 }],
    "favorite": "Thievery Corporation Rdio Radio"
    }
    }


    I'm going to go back a few pages in the thread, and try that "test your file" link you posted J, and see if there's anything it complains about....
    Lyricist III
    November 28, 2013

    code:

    {
    "all": {"players": [{ "roomName": "LittleRm", "volume": 23 },{ "roomName": "Living Room", "volume": 27 },{ "roomName": "Kitchen", "volume": 18 },{ "roomName": "Office", "volume": 22 },{ "roomName": "Master Bedroom", "volume": 17 },{ "roomName": "Rec Room", "volume": 0 }]},
    "tv": {
    "players": [{ "roomName": "Rec Room", "volume": 50 }],
    "state": "stopped",
    "uri": "x-rincon-stream:RINCON_0000000000001400"
    },
    "AcidJazz": {
    "players": [{ "roomName": "Living Room", "volume": 27 },{ "roomName": "Kitchen", "volume": 18 },{ "roomName": "Office", "volume": 22 }],
    "favorite": "Acid Jazz Radio"
    },
    "Thiev": {
    "players": [{ "roomName": "Living Room", "volume": 27 },{ "roomName": "Kitchen", "volume": 18 },{ "roomName": "Office", "volume": 22 }],
    "favorite": "Thievery Corporation Rdio Radio"
    }
    }




    Hi You have missed the "," after ""Acid Jazz Radio" } " I added it in the code above.