Question: var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); var clients = []; app.get('/', function (req, res){ res.sendFile(__dirname + '/index.html'); }); io.on('connection',
var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); var clients = []; app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); io.on('connection', function(socket) { socket.on('sessionInfo', function (data) { //create client object and add to clients array var clientInfo = new Object(); clientInfo.customId = data.customId; clientInfo.clientId = socket.id; clients.push(clientInfo); }) socket.on('chat message', function (msg) { //joined message io.emit(msg, '--' + socket.client.id + ' just joined the room!!!'); }); }) io.on('disconnect', function(socket){ //remove client from array when disconnected for(var i = 0; i < clients.length; ++i) { var c = clients[i]; if (c.clientId == socketId) { clients.splice(i,1); break; } } //disconnect message io.emit('chat message', '--' + socket.client.id + ' just left the room!!!'); }); http.listen(3000, function(){ console.log('listening on *:3000'); }); Question 1: What third-party modules does this project use? What are they? What are their versions? How did you find that information?
Question 2: Who are the contributors for socket.io module? List their names and email addresses.
Question 3: What do you need to do if the event name chat message is changed to trump in index.html file so that the application doesnt break?
var socket = io();
$('form').submit(function(){
socket.emit('trump', $('#m').val());
$('#m').val('');
return false;
});
socket.on('trump', function(msg){
$('#messages').append($('
').text(msg));
});
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
