-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (35 loc) · 1.24 KB
/
index.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
36
37
38
39
40
41
42
43
44
45
46
require('dotenv').config();
const { httpServer, emitter } = require('./chat-emitter');
const chatManager = require('./classes/manager')();
chatManager.conversationManager.createChannel('main');
emitter.io.on('connection', socket => {
chatManager.handleSocketConnect(socket);
chatManager.handleBotSpawnRequest();
console.log(socket.handshake.headers['x-forwarded-for']);
socket.on('disconnect', () => {
chatManager.userManager.remove(socket);
chatManager.purgeIfEmpty();
});
socket.on('channel-message', textContent => {
chatManager.handleNewMessage(socket, textContent);
});
socket.on('need-messages', (channelId, messageIdArray, callback) => {
chatManager.handleGetMessagesRequest(channelId, messageIdArray, callback);
});
socket.on('set-channel', channelId => {
chatManager.handleChannelSwitch(socket, channelId);
});
socket.on('create-channel', label => {
chatManager.conversationManager.createChannel(label);
});
socket.on('update-name', newName => {
chatManager.handleNameChange(socket, newName);
});
socket.on('is-typing', () => {
chatManager.handleIsTyping(socket);
});
});
const port = process.env.PORT;
httpServer.listen(port, () => {
console.log(`Server running at port ${port}`);
});