Skip to content

Commit

Permalink
add client-side setup for DJ feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledbettj committed Jan 9, 2013
1 parent 53cfcae commit 19197b3
Show file tree
Hide file tree
Showing 3 changed files with 3,389 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/assets/javascripts/application.js
Expand Up @@ -11,4 +11,5 @@
//= require tabs
//= require follow
//= require report
//= require custom-playlist-settings
//= require custom-playlist-settings
//= require dj
62 changes: 62 additions & 0 deletions app/assets/javascripts/dj.js
@@ -0,0 +1,62 @@
/*jshint browser:true undef:true strict:false jquery:true*/
/*global io */

var exports = window.Tubalr || {};

window.Tubalr = (function(exports) {
var DJ = function(username, opts) {
opts = opts || {};

this.username = username;

this.server = opts.server || 'localhost';
this.port = opts.port || 8900;

this.socket = io.connect(this.server, {port: this.port});
this.onUpdate = opts.onUpdate || function() {};
};

DJ.prototype.startBroadcasting = function(videoId, videoElapsed) {
if (!this.broadcasting) {
this.broadcasting = true;
this.socket.emit('start', {
from: this.username,
id: videoId,
at: videoElapsed
});
}
};

DJ.prototype.stopBroadcasting = function() {
if (this.broadcasting) {
this.broadcasting = false;

this.socket.emit('stop', {
from: this.username
});
}
};

DJ.prototype.updateBroadcast = function(videoId, videoElapsed) {
if (this.broadcasting) {
this.socket.emit('change', {
from: this.username,
id: videoId,
at: videoElapsed
});
}
};

DJ.prototype.listenTo = function(who) {
var self = this;

this.socket.on('dj-' + who, function(msg) {
self.onUpdate(msg);
});

this.socket.emit('subscribe', {target: who});
};

exports.DJ = DJ;
return exports;
})(exports);

0 comments on commit 19197b3

Please sign in to comment.