A node.js API for creating bots on Dubtrack.fm.
This API is just beginning, and since the Dubtrack Javascript API is not documented yet, features are somewhat limited.
phantomjs
and phantomjs-node
are required. Right now, the API requires phantomjs version 2.0 or greater. Version 1.x hasn't been tested. Please let me know if you get it to work with 1.x.
npm install phantomjs
If you created the Dubtrack account for the bot by connecting through Facebook or Twitter, you will have to first login as that user, and view the cookies in your browser and get the value of the "connect.sid" cookie. It will look something like s%Bp46VM86r0gns4w2krwtQ86JiROoNorcapnylGMTdG9qvs3rfs9YOCacdhFl2MlRCr4e8uM8LuP905RP
.
Otherwise, you can use the Username and Password if you created your account with one. There is currently no way to get a password for an account created through Facebook or Twitter.
Then, create a .js file similar to below, and run it with node:
node bot.js
var DubtrackAPI = require('./dubtrackapi');
// For the cookie route, just set creds to the cookie value
var creds = '...'; // Put the value of the connect.sid cookie here
// For username and password
creds = {
username: '...',
password: '...'
};
var bot = new DubtrackAPI(creds);
bot.connect('chillout-mixer'); // specify the room name part of the url for the room
bot.on('ready', function(data) {
console.log("Ready to go: ", data);
// data contains the currentDJ (by name) and currentTrack (artist and track), and the list of users in the room (does not update on join/depart)
bot.getEvents(function(events) {
console.log("These are the Dubtrack events I respond to: ", events);
});
});
bot.on('chat-message', function(data) {
console.log("got chat: ", data);
});
bot.on('djAdvance', function(data) {
console.log("new song playing: ", data);
});
bot.on('error', function(msg, trace) {
console.log("Got an error from the virtual browser: ", msg, trace);
});