Skip to content
Browse files

add client-side setup for DJ feature.

  • Loading branch information...
1 parent 53cfcae commit 19197b30b2426c12b22cc98c2b8f2997e54bc8a4 @ledbettj ledbettj committed Jan 9, 2013
Showing with 3,389 additions and 1 deletion.
  1. +2 −1 app/assets/javascripts/application.js
  2. +62 −0 app/assets/javascripts/dj.js
  3. +3,325 −0 vendor/assets/javascripts/socket.io.js
View
3 app/assets/javascripts/application.js
@@ -11,4 +11,5 @@
//= require tabs
//= require follow
//= require report
-//= require custom-playlist-settings
+//= require custom-playlist-settings
+//= require dj
View
62 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);
View
3,325 vendor/assets/javascripts/socket.io.js
3,325 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.

0 comments on commit 19197b3

Please sign in to comment.
Something went wrong with that request. Please try again.