Skip to content

Commit

Permalink
added support for new rdio
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Smus committed Mar 18, 2012
1 parent eeebcd8 commit e229cd2
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
66 changes: 66 additions & 0 deletions extension/keysocket-rdio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
var PREV = 20;
var PLAY = 16;
var NEXT = 19;

function simulateClick(selector) {
var evt = document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, false, document, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
document.querySelector(selector).dispatchEvent(evt);
}

var connection = null;
var isConnected = false;

function connect() {
// Connect to a websocket server
connection = new WebSocket('ws://localhost:1337/');

// When the connection is open, send some data to the server
connection.onopen = function() {
console.log('WS open');
isConnected = true;
connection.send('Ping'); // Send the message 'Ping' to the server


// Log errors
connection.onerror = function(error) {
console.log('WS error', error);
};

// Log messages from the server
connection.onmessage = function(e) {
console.log('WS message', e);
var key = e.data;
if (key == PREV) {
// Play the previous song
simulateClick('.left_controls .prev');
} else if (key == NEXT) {
// Play the next song.
simulateClick('.left_controls .next');
} else if (key == PLAY) {
simulateClick('.left_controls .play_pause');
}
};

connection.onclose = function(e) {
console.log('WS close', e);
isConnected = false;
reconnect();
};
};

}

function reconnect() {
// If we're not connected,
if (!isConnected) {
// Attempt to connect.
connect();
// Then ensure we're connected.
setTimeout(reconnect, 1000);
}
}

reconnect();


4 changes: 4 additions & 0 deletions extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"matches": ["http://www.thesixtyone.com/*"],
"js": ["keysocket-t61.js"]
},
{
"matches": ["http://www.rdio.com/*"],
"js": ["keysocket-rdio.js"]
},
{
"matches": ["https://play.google.com/music/*"],
"js": ["keysocket-gmusic.js"]
Expand Down

0 comments on commit e229cd2

Please sign in to comment.