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

    jishiAuthor
    Headliner II
    December 15, 2013
    Okay, ynot, I pushed a fix for freeBSD.

    Could you please also test this (relevant for a bug report):

    code:

    var os = require('os');
    console.log(os.networkInterfaces());


    Add that to a js file (test.js or similar) and invoke it with "node test.js", and send me the output? I want to see if it actually finds any interfaces, or if they are incorrectly labeled as "internal". It would be nice if I didn't have to install a VM with freeBSD just to test this 🙂
    Contributor I
    December 15, 2013
    The fall back works well. Thank you.

    As suspected, FreeBsd 91.p5 returns the following output:

    {}

    when interrogating for the network interface list

    Thanks again. Yvon.
    jishiAuthor
    Headliner II
    December 15, 2013
    Did some updates to the web-controller, it now has working player mute buttons, and you can seek in tracks by dragging the progress-bar.

    Will add mousewheel/click to it later on.

    Enjoy!
    Lyricist III
    December 16, 2013
    Yes, this is because you are running node 0.6.x. You need 0.8 or higher, and you might need to install it manually of it isn't in the ubuntu repos.

    Now i got it. I have to upgrade "node" itself. Sorry.

    Will do it tomorrow.

    Sacha
    Lyricist III
    December 16, 2013
    Now i got it. I have to upgrade "node" itself. Sorry.

    Will do it tomorrow.

    Sacha


    Hi jishi,

    Works perfect. Well done. Very usefull.

    Sacha
    Contributor I
    December 16, 2013
    If I might ask, what are the future plans for this controller. Do you plan to support local music libraries, query tools, add / remove tracks form queue, etc. similar to the native controller.

    Are you also planning to support other browsers and in particular mobile browsers.

    This is a very nice tool and it seems to perform well and is quite flexible. Good job.
    jishiAuthor
    Headliner II
    December 16, 2013
    If I might ask, what are the future plans for this controller. Do you plan to support local music libraries, query tools, add / remove tracks form queue, etc. similar to the native controller.

    Are you also planning to support other browsers and in particular mobile browsers.

    This is a very nice tool and it seems to perform well and is quite flexible. Good job.


    Well, my main goal was to implement the basic functionality for desktop browsers. That is pretty much there now, because I settled for only handling favorites to begin with. When I have made the final tweaks I will package it as version 1.0. I will not support additional browsers for the desktop version for the time being. Firefox and Chrome are available on all desktop/laptop platforms, including chromebook, so I consider that a waste.

    Phase two was to implement a spotify-centric version of the web controller, that would use the spotify search engine and behave more like the spotify client when it comes to functionality. Mostly because I more or less use Sonos exclusively for Spotify streaming.

    Some other loose ideas is party lockdown mode with a basic web controller for smartphones (only queue), a better mobile controller for all modern mobile platforms etc. When the basic functionality is there, all those other ideas wouldn't be that hard to implement.

    Also note that the web controller functions has been prioritized based on my own usage pattern. For example, I never edit my queue, so that hasn't been a priority for me. If enough people think that it would be useful, I might prioritize that function. But the main focus will be to make it useful for as many as possible.

    And lastly, I have done this in my spare time, by myself, and I don't have an infinite amount of time 😉. It has been fun and quite a challenge, but every now and then I need to rest as well. If people want to help out, I'll gladly accept pull requests.
    Contributor I
    December 18, 2013
    Thanks for the info. I understand the magnitude of the tasks and the time it takes and certainly do appreciate the effort.

    I will consider the pull request if I can wrap my head around the existing code and comm techniques early in the new year. I would like to be able to access my local music library and have search and queue up capabilities similar to those in the official controller as well as the old purple controller.

    Thanks again. Yvon.
    Lyricist III
    December 19, 2013
    Hi Jishi,
    On one of my Raspberry Pi running wheezy-raspbian I have installed NodeJS and the "Hello World" example is working. But I can't understand how to install the LIRC driver. The problem are due to my limited Linux skills. The IR code and Electronics isn't no problem for me.

    So I plan to use FLIRC (emulates keyboards keys then IR is recivied) and wonder how difficult it's to change the Node code (sonos-remote-control) to act on some key pressed instead and were to start?

    I'm a windows programmer but are not used with Java and WEB interface.
    Lyricist III
    December 20, 2013
    Hi Jishi,

    I´m also interessted in the queue capability. So that we are able to queue an uri. I currectly write a module for "fhem" a opensource homeautomation system to support your node. Let you know about the progress.

    Best regards

    Sacha