-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapp.js
executable file
·105 lines (91 loc) · 3.98 KB
/
app.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const fs = require('fs');
const express = require('express');
const app = express();
const db = require('./models/index');
//routes
const routes = require('./src/routes');
//assets
app.use('/assets', express.static('assets'));
app.use('/build', express.static('public/build'));
const WEBPACK_ASSETS_URL = 'http://localhost:8080';
if (app.get('env') == 'production') {
var assets_names = JSON.parse(fs.readFileSync(__dirname + '/assets/webpack-assets.json', 'utf8'));
var scripts = [assets_names.app.js];
} else {
var scripts = [WEBPACK_ASSETS_URL + '/build/app.js'];
}
//Set view engine
app.set('view engine', 'ejs');
//use routes with /api
app.use('/', routes);
//Allow react router to handle the get requests
app.get('/*', function(req, res) {
res.render('index', {scripts: scripts});
});
const server = app.listen(4000, function() {
console.log('App listening on port 4000!');
});
module.exports = server;
db.sequelize
.sync({
force: false
})
.then(() => {
console.log('DB Synced');
});
//socket server
const io = require('socket.io')(server, {wsEngine: 'ws'});
const handleConnections = require('./src/socketRoutes/connectionManager');
const handleBiding = require('./src/socketRoutes/bidManager');
//socket routes
io.sockets.on('connection', socket => {
socket.on('openAuction', (namespace, owner_id, max_user) => {
handleConnections.ownerSocket(socket, namespace, owner_id, max_user);
});
socket.on('closeAuction', (namespace, owner_id) => {
handleConnections.closeAuction(socket, io, namespace, owner_id);
});
socket.on('joinRoom', (namespace, user_id) => {
handleConnections.joinAuction(socket, namespace, user_id);
});
socket.on('newBid', (namespace, user_id, userName, bid_value) => {
const clientSocket = handleConnections.getAllClientSockets(namespace)[user_id];
const adminSocket = handleConnections.getAdminSocket(namespace);
handleBiding.handleBid(io, socket, namespace, user_id, userName, bid_value, clientSocket, adminSocket);
});
socket.on('newSecretBid', (namespace, user_id, userName, bid_value) => {
const clientSocket = handleConnections.getAllClientSockets(namespace)[user_id];
const adminSocket = handleConnections.getAdminSocket(namespace);
handleBiding.handleSecretBid(io, socket, namespace, user_id, userName, bid_value, clientSocket, adminSocket);
});
socket.on('biddingStart', (namespace, owner_id, catalog) => {
handleConnections.currentCatalog(socket, namespace, owner_id, catalog);
});
socket.on('biddingSkip', (owner_id, namespace, catalogName) => {
handleConnections.skipBidding(io, socket, namespace, owner_id, catalogName);
});
socket.on('biddingStop', (owner_id, namespace, catalogName, isSecretBid) => {
handleConnections.stopBidding(io, socket, namespace, owner_id, catalogName, isSecretBid);
});
socket.on('disconnect', reason => {
handleConnections.leaveAuction(socket, socket.user_id, socket.namespace);
});
socket.on('pauseBidding', (owner_id, namespace, catalog) => {
handleConnections.pauseBidding(io, socket, namespace);
});
socket.on('resumeBidding', (owner_id, namespace, catalog) => {
handleConnections.resumeBidding(io, socket, namespace);
});
socket.on('deleteBids', (allBids, owner_id, namespace, catalog) => {
handleBiding.deleteBids(io, socket, allBids, namespace, owner_id, catalog);
});
socket.on('deleteSecretBids', (secretBids, deleteSecretBids, owner_id, namespace, catalog) => {
handleBiding.deleteSecretBids(io, socket, secretBids, deleteSecretBids, namespace, owner_id, catalog);
});
socket.on('changeRegistrationStatus', namespace => {
handleConnections.changeRegistrationStatus(io, socket, namespace);
});
socket.on('secretBidStatus', (owner_id, namespace, catalog, isSecretBid) => {
handleConnections.changeSecretBidStatus(io, socket, namespace, isSecretBid);
});
});