-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
35 lines (26 loc) · 922 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const path = require('path');
const express = require('express');
const http = require('http');
const socketio = require('socket.io');
const app = express();
const server = http.createServer(app);
const io = socketio(server);
//Set static folder
app.use(express.static(path.join(__dirname, 'public')));
//Run when a client connects
io.on('connection', socket => {
console.log('New websocket connection');
socket.emit('message', 'Welcome to GradAssist');
//Brodcast when a user connects
socket.emit('message', 'A user has joined the chat');
//Runs when client disconnects
socket.on('disconnect', ()=> {
io.emit('message', 'A user has left the chat')
});
//Listen for chatMessage
socket.on('chatMessage', () => {
io.emit('message', msg);
})
});
const PORT = 3000 || process.env.PORT;
server.listen(PORT, () => console.log(`Server running on port ${PORT} `));