// Broadcast new user event
primus.send('updateoverview', this.roomname, this.totusers);
- spark.send('ready', usersData, this.trackscount, nickname, loggedin);
+ spark.send('ready', {
+ trackscount: this.trackscount,
+ usersData: usersData,
+ nickname: nickname,
+ loggedin: loggedin,
+ state: {
+ previewUrl: this.previewUrl,
+ timeleft: this.songtimeleft,
+ status: this.status
+ }
+ });
primus.room(this.roomname).except(spark.id).send('newuser', nickname, usersData);
};
setTimeout(this.sendTrackInfo.bind(this), 30000);
};
-/**
- * Send the room status to the client that asked for it.
- */
-
-Room.prototype.sendStatus = function(callback) {
- callback({
- status: this.status,
- timeleft: this.songtimeleft,
- previewUrl: this.previewUrl
- });
-};
-
/**
* Send the track info to all connected clients.
*/
room.onChatMessage(msg, spark, to);
}
});
- spark.on('getstatus', function(callback) {
- if (isFunction(callback)) {
- room.sendStatus(callback);
- }
- });
spark.on('guess', function(guess) {
if (isString(guess)) {
room.onGuess(spark, guess);
};
// Successfully joined the room
- var ready = function(usersData, trackscount, username, loggedin) {
- nickname = username;
+ var ready = function(data) {
+ nickname = data.nickname;
- if (!loggedin) {
+ if (!data.loggedin) {
document.cookie = 'nickname=' + nickname + ';path=/;';
} else {
subscriber = true;
}
$modal.modal('hide').empty();
- $('#total-tracks span').text(trackscount);
+ $('#total-tracks span').text(data.trackscount);
var $entry = $('<span class="join">' + nickname + ' joined the game</span>');
addChatEntry($entry);
- updateUsers(usersData);
+ updateUsers(data.usersData);
$messagebox.on('keydown', function(event) {
if (event.keyCode === 13) {
primus.on('trackinfo', addTrackInfo);
primus.on('updateusers', updateUsers);
primus.on('userleft', userLeft);
- primus.send('getstatus', setStatus);
+
+ setStatus(data.state);
};
// Show the number of players inside each room