Skip to content

WritheM/plugged

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

plugged

plugged is a (v|f)ast JavaScript API for the plug.dj service.

Installation

npm install plugged

How to use

plugged is relatively easy to use. Most functions are exposed via events, thus it's easy to check for certain data.

To start with a simple bot, do this:

var Plugged = require("plugged");
var plug = new Plugged();

// log into the service
plug.login({ email: "[email protected]", password: "examplepassword" });

plug.on(plug.LOGIN_SUCCESS, function _loginSuccess() {
    plug.cacheChat(true);
    plug.connect("exampleroom");
});

plug.on(plug.JOINED_ROOM, function _joinedRoom() {
    plug.on(plug.ADVANCE, function() {
        //WOOT!
        plug.woot();
    });
});

Events

Most functionality is exposed via Events. The wiki describes how to use what events when.

Server calls

Sometimes you need to call data from the server, for example if you want to get your current playlist, add a new media file or get a certain list of rooms based on a search string. All Server calls are described in the wiki

Facebook login

Some people might prefer taking the oauth route and use their fb login for plug. So this is possible since [email protected] as well. All you have to do is to replace the login object with this one:

...
plug.login({
    userID: "your ID here",
    accessToken: "your access token here"
});
...

to keep the behaivour clear, if you enter both email and facebook login credentials plug will return an "malformed credentials" error.

Restart without the whole login procedure

To save some time you can restart your application without going through the whole login procedure. All you have to do is to save the cookie jar and the auth token and return them to plugged once you start your application again.

getting the necessary data:

plug.getAuthToken(function (err, token) {
    // save the token
});

plug.getJar();

putting it back in:

var token = null;
var jar = null;

// read token and jar from DB, file, etc.

plug.setJar(jar);

// the token has a higher priority
plug.login({ ... }, token);

How you save it and what you want to do with it is up to you. There's a multitude of ways to save this and it's probably better that you do that since you know best how your application should behave and under which conditions like os, environment, etc.

Remember, both, the facebook token and the auth token are not meant forever. So you should keep this in mind while developing your application.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%