Total Complexity | 6 |
Complexity/F | 1 |
Lines of Code | 36 |
Function Count | 6 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | const express = require('express'); |
||
2 | |||
3 | |||
4 | const app = express(); |
||
5 | |||
6 | app.get('/chat', (req, res) => { |
||
7 | res.send('<h1>Hello world</h1>'); |
||
8 | }); |
||
9 | |||
10 | |||
11 | |||
12 | const server = app.listen(3001, function() { |
||
13 | console.log('server running on port 3001'); |
||
|
|||
14 | }); |
||
15 | |||
16 | |||
17 | const io = require('socket.io')(server, { |
||
18 | cors: { |
||
19 | origin: '*', |
||
20 | methods: ["GET", "POST"] |
||
21 | } |
||
22 | }); |
||
23 | |||
24 | io.on('connection', (socket) => { |
||
25 | console.log('a user connected'); |
||
26 | socket.broadcast.emit('hi'); |
||
27 | socket.on('chat message', (msg) => { |
||
28 | console.log('message: ' + msg); |
||
29 | }); |
||
30 | socket.on('disconnect', () => { |
||
31 | console.log('user disconnected'); |
||
32 | }); |
||
33 | socket.on('chat message', (msg) => { |
||
34 | io.emit('chat message', msg); |
||
35 | }); |
||
36 | }); |