Skip to content

Commit b70cc63

Browse files
НиколайНиколай
authored andcommitted
Refactoring of communication infrastructure
1 parent aec7731 commit b70cc63

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const express = require('express');
22
const app = express();
3-
const server = require('http').createServer(app);
4-
const io = require('socket.io')(server);
3+
const io = require('socket.io');
54
const port = process.env.PORT || 5001;
65
const fs = require('fs');
76

@@ -11,21 +10,19 @@ app.get('/', (req, res) => {
1110
res.sendFile(`${__dirname }./public/index.html`);
1211
});
1312

14-
io.on('connection', socket => {
13+
var sock = io.listen(app.listen(port));
14+
15+
sock.on('connection', socket => {
1516
console.log('a user connected');
1617

1718
socket.on('chat message', msg => {
1819
fs.appendFile('log.txt', `${msg.author}: ${msg.text} ${new Date()}\n`, (err) => {
1920
if (err) throw err;
2021
});
21-
io.emit('chat message', msg);
22+
sock.emit('chat message', msg);
2223
});
2324

2425
socket.on('disconnect', () => {
2526
console.log('a user disconnected');
2627
});
2728
});
28-
29-
server.listen(port, () => {
30-
console.log(`Server listening at port1 ${port}`);
31-
});

src/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import MainApp from './app';
77

88
import io from 'socket.io-client';
99
import { sendMessage } from './actions/actionCreators';
10-
const socket = io('http://localhost:5001');
10+
const socket = io();
1111

1212
socket.on('chat message', (message) => {
1313
store.dispatch(sendMessage(message.author, message.text));

0 commit comments

Comments
 (0)