Person count, visual fixes.
This commit is contained in:
parent
9205eb93b0
commit
05a420d0a7
|
@ -40,6 +40,7 @@ body, html {
|
|||
#chat li {
|
||||
white-space: pre;
|
||||
padding: 2px 15px;
|
||||
color: #343434;
|
||||
}
|
||||
|
||||
/* Message types */
|
||||
|
@ -49,9 +50,10 @@ body, html {
|
|||
}
|
||||
#chat i.motd { color: #99FF99; display:inline-block; line-height: 12px !important; }
|
||||
#chat i.info { color: #999999; }
|
||||
#chat i.server { color: #999999; }
|
||||
#chat i.server { color: #99FFFF; }
|
||||
#chat i.error { color: #ff7777; }
|
||||
#chat i.message { color: #eeeeee; }
|
||||
#chat i.nick { color: #99FF99; }
|
||||
|
||||
/*------------------------------------*\
|
||||
INPUT
|
||||
|
|
|
@ -58,6 +58,15 @@ define('cryptalk', {
|
|||
|
||||
},
|
||||
|
||||
count: function () {
|
||||
if( room ) {
|
||||
socket.emit('room:count');
|
||||
} else {
|
||||
post('error', templates.messages.not_in_room);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
key: function (payload) {
|
||||
// Make sure the key meets the length requirements
|
||||
if (payload.length < 8) {
|
||||
|
@ -177,6 +186,9 @@ define('cryptalk', {
|
|||
.on('room:joined', function (data) {
|
||||
room = data;
|
||||
post('info', $.template(templates.messages.joined_room, { roomName: room }));
|
||||
|
||||
// Automatically count persons on join
|
||||
socket.emit('room:count');
|
||||
})
|
||||
|
||||
.on('room:left', function () {
|
||||
|
@ -198,8 +210,21 @@ define('cryptalk', {
|
|||
})
|
||||
|
||||
.on('message:server', function (data) {
|
||||
var sanitized = $.escapeHtml(data);
|
||||
post('server', data);
|
||||
if( data.msg ) {
|
||||
var sanitized = $.escapeHtml(data.msg);
|
||||
if( templates.server[sanitized] ) {
|
||||
if( data.payload !== undefined ) {
|
||||
var sanitized_payload = $.escapeHtml(data.payload);
|
||||
post('server', $.template(templates.server[sanitized], { payload: sanitized_payload }));
|
||||
} else {
|
||||
post('server', templates.server[sanitized]);
|
||||
}
|
||||
} else {
|
||||
post('error', templates.server.bogus);
|
||||
}
|
||||
} else {
|
||||
post('error', templates.server.bogus);
|
||||
}
|
||||
});
|
||||
|
||||
// Post the help/welcome message
|
||||
|
|
|
@ -26,9 +26,10 @@ define({
|
|||
'Available commands: \n' +
|
||||
' /generate Generate random room \n' +
|
||||
' /join RoomId Join a room \n' +
|
||||
' /leave Leave the room \n' +
|
||||
' /count Count participants of room \n' +
|
||||
' /nick NickName Sets an optional nick \n' +
|
||||
' /key OurStrongPassphrase Sets encryption key \n' +
|
||||
' /leave Leave the room \n' +
|
||||
' /clear Clear on-screen buffer \n' +
|
||||
' /help This \n' +
|
||||
' \n' +
|
||||
|
@ -43,10 +44,10 @@ define({
|
|||
|
||||
post: {
|
||||
motd: '<li><i class="motd">{text}</i></li>',
|
||||
info: '<li>INF> <i class="info">{text}</i></li>',
|
||||
server: '<li>SRV> <i class="server">{text}</i></li>',
|
||||
error: '<li>ERR> <i class="error">{text}</i></li>',
|
||||
message: '<li>{nick}> <i class="message">{text}</i></li>'
|
||||
info: '<li>INF> <i class="info">{text}</i></li>',
|
||||
server: '<li>SRV> <i class="server">{text}</i></li>',
|
||||
error: '<li>ERR> <i class="error">{text}</i></li>',
|
||||
message: '<li><i class="nick">{nick}></i> <i class="message">{text}</i></li>'
|
||||
},
|
||||
|
||||
messages: {
|
||||
|
@ -54,6 +55,7 @@ define({
|
|||
key_ok_ready: 'Key set, you can now start communicating.',
|
||||
key_ok_but_no_room: 'Key set, you can now join a room and start communicating.',
|
||||
msg_no_room: 'You have to join a room before sending messages. See /help.',
|
||||
not_in_room: 'You have to be in a room to count participants...',
|
||||
msg_no_key: 'You have to set an encryption key before sending a message. See /help.',
|
||||
nick_short: 'Nickname is too short, try again.',
|
||||
nick_set: 'From now on, you\'re referred to as \'{nick}\'.',
|
||||
|
@ -68,5 +70,13 @@ define({
|
|||
already_in_room: 'You are already in a room ({roomName}), stoopid.',
|
||||
|
||||
unable_to_decrypt: 'Unabled to decrypt received message, keys does not match.'
|
||||
},
|
||||
|
||||
server: {
|
||||
person_joined: 'A person joined this room.',
|
||||
person_left: 'A person left this room.',
|
||||
person_count: 'There is {payload} person(s) in this room, including you.',
|
||||
command_failed: 'Server command failed, you\'re probably trying to du something bogus.',
|
||||
bogus: 'Received a bogus message from server.',
|
||||
}
|
||||
});
|
23
server.js
23
server.js
|
@ -12,19 +12,32 @@ app.io.route('room', {
|
|||
req.socket.emit('room:generated',room);
|
||||
},
|
||||
join: function(req) {
|
||||
if(req.data) {
|
||||
if( req.data ) {
|
||||
req.socket.emit('room:joined',req.data);
|
||||
req.socket.join(req.data);
|
||||
req.socket.broadcast.to(req.data).emit('message:server', 'A person joined this room');
|
||||
req.socket.broadcast.to(req.data).emit('message:server', {msg:'person_joined'} );
|
||||
req.socket.current_room = req.data;
|
||||
} else {
|
||||
req.socket.emit('message:server', {msg:'command_failed'} );
|
||||
}
|
||||
},
|
||||
leave: function(req) {
|
||||
if(req.data) {
|
||||
if( req.data ) {
|
||||
req.socket.emit('room:left');
|
||||
req.socket.leave(req.data);
|
||||
req.socket.broadcast.to(req.data).emit('message:server', 'A person left this room');
|
||||
req.socket.broadcast.to(req.data).emit('message:server', {msg:'person_left'} );
|
||||
req.socket.current_room = undefined;
|
||||
} else {
|
||||
req.socket.emit('message:server', {msg:'command_failed'} );
|
||||
}
|
||||
},
|
||||
count: function(req) {
|
||||
if( req.socket.current_room !== undefined ) {
|
||||
// This will fail on socket.io >= 1.0
|
||||
var client_count = app.io.sockets.clients(req.socket.current_room).length;
|
||||
req.socket.emit('message:server', {msg:'person_count', payload: client_count } );
|
||||
} else {
|
||||
req.socket.emit('message:server', {msg:'command_failed'} );
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -40,7 +53,7 @@ app.io.sockets.on('connection', function(socket) {
|
|||
socket.on('disconnect', function() {
|
||||
// Notify other users of the room
|
||||
if( socket.current_room !== undefined ) {
|
||||
socket.broadcast.to(socket.current_room).emit('message:server', 'A person left this room');
|
||||
socket.broadcast.to(socket.current_room).emit('message:server', {msg:'person_left'} );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue