Skip to content

Commit

Permalink
added Chat-app
Browse files Browse the repository at this point in the history
  • Loading branch information
1-23-smy committed Oct 1, 2023
1 parent b591985 commit fcadcd0
Show file tree
Hide file tree
Showing 11 changed files with 1,552 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added Chat-App/.DS_Store
Binary file not shown.
37 changes: 37 additions & 0 deletions Chat-App/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { log } = require('console');
const express = require('express');
const path=require('path');
const app = express();
const PORT = process.env.port || 3000;
const server=app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
}
)
const io=require('socket.io')(server);

app.use(express.static(path.join(__dirname, 'public')));

let socketsConnected=new Set();

io.on('connection', onConnected);


function onConnected(socket){
socketsConnected.add(socket.id);
io.emit("clients-total", socketsConnected.size);
socket.on('disconnect', () => {
console.log("Socket disconnected: " + socket.id);
socketsConnected.delete(socket.id);
io.emit("clients-total", socketsConnected.size);
})

socket.on('message', (data) => {
// console.log(data);
socket.broadcast.emit('chat-message', data);
})

socket.on('feedback', (data) => {
socket.broadcast.emit('feedback', data);
})
}

Binary file added Chat-App/iphone_text_message.mp3
Binary file not shown.
Loading

0 comments on commit fcadcd0

Please sign in to comment.