Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help! This project is based on an open source Node.js application posted at: http://socket.io/get-started/chat/. Your job is to modify the index.js page so that

Please help!

This project is based on an open source Node.js application posted at: http://socket.io/get-started/chat/. Your job is to modify the index.js page so that the app will have two new features:

  1. Whenever someone joins or leaves the room, a message will be displayed to all users.
  2. Instead of having a username, each user is assigned a socket generated session id when he/she first joins

Hint:

  1. You can download this project source code from https://github.com/rauchg/chat-example or use the file provided by your instructor in BlackBoard: unit09_lab.zip.
  2. When a user joins the chat room, you need to register the connect event. For example:

io.on(connect, function(socket)) {

io.emit(chat message, --- someone just joined the room!!!);

});

  1. When a user leaves the chat room, you need to register the disconnect event on that particular socket. For example:

io.on(connection, function(socket) {

socket.on(disconnect, function() {

io.emit(chat message, --- someone just left the room!!!);

});

});

To get the session Id from each user, you can use socket.client.id property. For example: io.emit(chat message, --- + socket.client.id + just joined the room!!!);

index.js

var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); io.on('connection', function(socket){ socket.on('chat message', function(msg){ io.emit('chat message', msg); }); }); http.listen(3000, function(){ console.log('listening on *:3000'); });

index.html

   Socket.IO chat    

    Step by Step Solution

    There are 3 Steps involved in it

    Step: 1

    blur-text-image

    Get Instant Access to Expert-Tailored Solutions

    See step-by-step solutions with expert insights and AI powered tools for academic success

    Step: 2

    blur-text-image

    Step: 3

    blur-text-image

    Ace Your Homework with AI

    Get the answers you need in no time with our AI-driven, step-by-step assistance

    Get Started

    Recommended Textbook for

    More Books

    Students also viewed these Databases questions

    Question

    Persuading Your Audience Strategies for

    Answered: 1 week ago