-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
40 lines (30 loc) · 881 Bytes
/
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
const env = require('dotenv').config()
const express = require('express')
const app = express()
const http = require('http').Server(app)
const io = require('socket.io')(http)
const socketCore = require('./src/socket-core')
const port = process.env.PORT || 8080
io.on('connection', socket => {
const {
newMsg,
getPlayers,
newPlayer,
disconnect,
buttonReady,
buttonPressed,
checkAnswer
} = socketCore(socket, io)
socket.on('new_msg', newMsg)
socket.on('get_players', getPlayers)
socket.on('new_player', newPlayer)
socket.on('disconnect', disconnect)
socket.on('button_ready', buttonReady)
socket.on('button_pressed', buttonPressed)
socket.on('check_server_answer', checkAnswer)
})
app.use(express.static(__dirname + '/public'))
const server = http.listen(port, err => {
if (err) throw err
console.log(`Server ready at http://127.0.0.1:${port}`)
})