Merge pull request #11 from nwithan8/patch-2

New person_single message for only one person in a room
This commit is contained in:
Hexagon 2019-11-10 21:17:51 +01:00 committed by GitHub
commit 189aac54a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -104,7 +104,8 @@ define({
server: { server: {
person_joined: 'A person joined this room.', person_joined: 'A person joined this room.',
person_left: 'A person left this room.', person_left: 'A person left this room.',
person_count: 'There is {payload} person(s) in this room, including you.', person_count: 'There are {payload} people in this room, including you.',
person_single: 'You are the only person in this room.',
command_failed: 'Server command failed, you\'re probably trying to du something bogus.', command_failed: 'Server command failed, you\'re probably trying to du something bogus.',
bogus: 'Received a bogus message from server.' bogus: 'Received a bogus message from server.'
}, },

View File

@ -53,7 +53,11 @@ io.on('connection', function(socket) {
socket.on('room:count', function () { socket.on('room:count', function () {
if( socket.current_room !== undefined ) { if( socket.current_room !== undefined ) {
var clientsList = io.sockets.adapter.rooms[socket.current_room]; var clientsList = io.sockets.adapter.rooms[socket.current_room];
if( clientsList.length > 1) {
socket.emit('message:server', {msg:'person_count', payload: clientsList.length } ); socket.emit('message:server', {msg:'person_count', payload: clientsList.length } );
} else {
socket.emit('message:server', {msg:'person_single'} );
}
} else { } else {
socket.emit('message:server', {msg:'command_failed'} ); socket.emit('message:server', {msg:'command_failed'} );
} }