Skip to content

Commit e75e228

Browse files
Merge pull request #463 from 1-23-smy/my-new-branch
added Chat-app
2 parents f3ff28d + fcadcd0 commit e75e228

File tree

11 files changed

+1552
-0
lines changed

11 files changed

+1552
-0
lines changed

.DS_Store

18 KB
Binary file not shown.

Chat-App/.DS_Store

6 KB
Binary file not shown.

Chat-App/app.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const { log } = require('console');
2+
const express = require('express');
3+
const path=require('path');
4+
const app = express();
5+
const PORT = process.env.port || 3000;
6+
const server=app.listen(PORT, () => {
7+
console.log(`Server is running on port ${PORT}.`);
8+
}
9+
)
10+
const io=require('socket.io')(server);
11+
12+
app.use(express.static(path.join(__dirname, 'public')));
13+
14+
let socketsConnected=new Set();
15+
16+
io.on('connection', onConnected);
17+
18+
19+
function onConnected(socket){
20+
socketsConnected.add(socket.id);
21+
io.emit("clients-total", socketsConnected.size);
22+
socket.on('disconnect', () => {
23+
console.log("Socket disconnected: " + socket.id);
24+
socketsConnected.delete(socket.id);
25+
io.emit("clients-total", socketsConnected.size);
26+
})
27+
28+
socket.on('message', (data) => {
29+
// console.log(data);
30+
socket.broadcast.emit('chat-message', data);
31+
})
32+
33+
socket.on('feedback', (data) => {
34+
socket.broadcast.emit('feedback', data);
35+
})
36+
}
37+

Chat-App/iphone_text_message.mp3

11.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)