11. INDEX.JS (SERVER)
Capture Messages - Save to DB
socket.on("chat message", function(msg){
//Print message to db
client.rpush('mes1', msg, redis.print);
io.emit('chat message', msg);
});
Send Messages On Connection As Array
client.lrange(['mes1',0,-1], function (err, reply) {
io.emit('past messages', reply);
}, redis.print);
12. PURE.JS (CLIENT)
Catch array from DB
socket.on('past messages', function(msg){
pastPast(msg);
});
function pastPast(msg){
var messages = msg;
for(var i = 0; i < messages.length; i++){
$('#msg_area').prepend($('<p>').text(messages[i]));
}
}
13. NOW WHAT
• Data needs to save to
disk
• UI needs help