PlaybackStatus in Mopidy node.js

I was wondering how to use the state described in the playbackStates documentation. According to the figure, there should be 3 states (playing, stopped, and paused), but the problem in my case is that when I use the PlaybackController’s getState()-method I get a state called pending. Is that another state not included in the state-diagram in the documentation?

I am also wondering how to use the PlaybackState in a node.js application. I want to do something like this:

if(mopidy.playback.getState() == mopidy.playback.state.STOPPED){
//do something

But I do not know how to use the class mopidy.core.PlaybackState in node. Any ideas?

Anyone who can help me with this one?
Maybe I should listen for events instead of asking for the state? Any feedback is appreciated.

Mopidy-MusicBox-Webclient uses Mopidy.js to make calls to the Mopidy core. I believe this is the canonical approach for HTTP clients, and may be a good place to start.

Some sample code for what I think you are trying to do is available here:

Subscribing to and responding on the events that Mopidy raises is generally a better approach than interrogating the core directly.

mopidy.playback.getState() is a function that have a async response:

// state is your state


Thank you for your replies. The answer provided are about how to use the getState() function, which is something I am doing as well. However, I want to do different things based on the state you are receiving, e.g the state is 'stopped' or 'playing' or anything else. Instead of:
if (state === 'stopped') //notice the quotes, the word may change in the future.
I would like to use the state variable which contains the value stopped.

Hello, i’m trying this simple code:

var Mopidy = require("mopidy");
var log=console.log;

var mopidy = new Mopidy({
    webSocketUrl: "ws://localhost:6680/mopidy/ws/"

  log (state);

but I get this error:


TypeError: Cannot read property 'getState' of undefined

Please advice, whats wrong?
Thank you


mopidy.playback doesn’t exist before you’re connected to the server. If you wrap your code like this, so it doesn’t run until you’re connected, it should work:

mopidy.on('state:online', function () {
    mopidy.playback.getState().then(function (state) {

See for the details.

ok, but how i can send

can someone share example?
thank you

There’s an example of that in the docs: