From 76656efe2401e1af18cef3ef5344ff145d8056c9 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Tue, 5 Apr 2016 17:22:39 +0200 Subject: [PATCH] removed `getstatus` event --- lib/rooms.js | 24 +++++++++++------------- lib/sparks.js | 5 ----- public/js/app.js | 13 +++++++------ 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/lib/rooms.js b/lib/rooms.js index d7cca04..1f96581 100644 --- a/lib/rooms.js +++ b/lib/rooms.js @@ -168,7 +168,17 @@ Room.prototype.addUser = function(spark, loggedin) { // 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); }; @@ -560,18 +570,6 @@ Room.prototype.sendPlayTrack = function() { 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. */ diff --git a/lib/sparks.js b/lib/sparks.js index 6d63279..91dbdd8 100644 --- a/lib/sparks.js +++ b/lib/sparks.js @@ -160,11 +160,6 @@ var joinRoom = function(room, spark) { 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); diff --git a/public/js/app.js b/public/js/app.js index be798fc..b5156e8 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -783,21 +783,21 @@ }; // 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 = $('' + nickname + ' joined the game'); addChatEntry($entry); - updateUsers(usersData); + updateUsers(data.usersData); $messagebox.on('keydown', function(event) { if (event.keyCode === 13) { @@ -873,7 +873,8 @@ 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 -- 2.54.0