Skip to content

Commit

Permalink
Reduce Notify Spam
Browse files Browse the repository at this point in the history
Host notification no longer appears if you are already the host. Delays
for other alerts are reduced.
  • Loading branch information
kyle8998 committed Mar 3, 2018
1 parent 201225c commit aaef026
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions js/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions js/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
33 changes: 19 additions & 14 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

});

Expand Down

0 comments on commit aaef026

Please sign in to comment.