diff --git a/js/host.js b/js/host.js index deb47ad..4e469a3 100644 --- a/js/host.js +++ b/js/host.js @@ -43,6 +43,7 @@ socket.on('changeHostLabel', function(data) { message: username + " is now the host." }, { type: 'info', + delay: 800, animate: { enter: 'animated fadeInUp', exit: 'animated fadeOutRight' @@ -70,6 +71,7 @@ function disconnected() { message: " You are now out of sync of the host" }, { type: 'warning', + delay: 400, animate: { enter: 'animated fadeInUp', exit: 'animated fadeOutRight' diff --git a/js/sync.js b/js/sync.js index 8370173..03bde9a 100644 --- a/js/sync.js +++ b/js/sync.js @@ -77,6 +77,7 @@ function syncVideo(roomnum) { message: " The room is now synced with you" }, { type: 'success', + delay: 400, animate: { enter: 'animated fadeInUp', exit: 'animated fadeOutRight' diff --git a/server.js b/server.js index b8006ed..a0b9616 100644 --- a/server.js +++ b/server.js @@ -329,21 +329,26 @@ io.sockets.on('connection', function(socket) { socket.on('change host', function(data) { var roomnum = data.room var newHost = socket.id - console.log("I want to be the host and my socket id is: " + newHost); - //console.log(io.sockets.adapter.rooms['room-' + socket.roomnum]) + var currHost = io.sockets.adapter.rooms['room-' + socket.roomnum].host - // Broadcast to current host and set false - socket.broadcast.to(io.sockets.adapter.rooms['room-' + socket.roomnum].host).emit('unSetHost'); - // Reset host - io.sockets.adapter.rooms['room-' + socket.roomnum].host = newHost - // Broadcast to new host and set true - socket.emit('setHost') - - io.sockets.adapter.rooms['room-' + socket.roomnum].hostName = socket.username - // Update host label in all sockets - io.sockets.in("room-" + roomnum).emit('changeHostLabel', { - username: socket.username - }); + // If socket is already the host! + if (newHost != currHost) { + console.log("I want to be the host and my socket id is: " + newHost); + //console.log(io.sockets.adapter.rooms['room-' + socket.roomnum]) + + // Broadcast to current host and set false + socket.broadcast.to(currHost).emit('unSetHost'); + // Reset host + io.sockets.adapter.rooms['room-' + socket.roomnum].host = newHost + // Broadcast to new host and set true + socket.emit('setHost') + + io.sockets.adapter.rooms['room-' + socket.roomnum].hostName = socket.username + // Update host label in all sockets + io.sockets.in("room-" + roomnum).emit('changeHostLabel', { + username: socket.username + }); + } });