-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathradio.js
47 lines (38 loc) · 1.57 KB
/
radio.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
47
// load environment variables from .env file
require('dotenv').config()
const Queue = require('./server/core/queue.js');
const QueueManager = require('./server/core/queue-manager.js');
const VotesManager = require('./server/core/votes-manager.js');
const Chat = require('./server/core/chat.js');
const Logger = require('./server/core/logger.js');
const ClientManager = require('./server/core/client-manager.js');
const SERVER_PORT = process.env.PORT || 4000;
const io = require('./server/core/socketio-express-initializer')({
port: SERVER_PORT
});
Logger.info('Server started successfully on port', SERVER_PORT);
// start the server components
const clientManager = new ClientManager(io);
const queue = new Queue(clientManager);
const votesManager = new VotesManager(queue);
const queueManager = new QueueManager(queue);
const chat = new Chat();
clientManager.on('new-client', client => {
// attach client to our components
chat.attachClient(client);
queueManager.attachClient(client);
votesManager.attachClient(client);
clientManager.emitToAll('usersCount', clientManager.getClientsCount());
client.on('disconnect', () => {
clientManager.emitToAll('usersCount', clientManager.getClientsCount());
Logger.info('Client', client.id, 'disconnected');
});
let isAdmin = false; // TODO: Implement admin functionality
if(isAdmin) {
client.on('refresh-them', () => {
clientManager.emitToAll('getRefreshed', true);
});
}
Logger.info('Client', client.id, 'connected');
});
Logger.info('Radio components initialized and waiting');