Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add client-side setup for DJ feature.
- Loading branch information
Showing
3 changed files
with
3,389 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
Oops, something went wrong.