-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (43 loc) · 1.58 KB
/
app.js
File metadata and controls
56 lines (43 loc) · 1.58 KB
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
const express = require('express')
const app = express()
const server = require('http').createServer(app);
const io = require('socket.io')(server)
app.set('view engine', 'jade')
app.use(express.static(__dirname + '/public'))
app.use(express.static(__dirname + '/assets'))
app.get('/', (req, res) => {
res.render('index', {title: "Hello", message: "Hello World!"})
})
app.get('/room', (req, res) => {
res.render('room')
})
server.listen(4321, '0.0.0.0', () => {
console.log('server running http://localhost:4321');
})
io.on('connection', socket => {
console.log("logged in!!")
// when the client emits 'message', this listens and executes
socket.on("update location", (dataX, dataY) => {
// we tell the client to execute 'update location'
socket.broadcast.emit("update location", dataX, dataY)
console.log(dataX, dataY)
})
socket.on("update infomation", (lX, lY, heat, water, hp) => {
socket.broadcast.emit("update infomation", lX, lY, heat, water, hp)
console.log("Get Info:", lX, lY, heat, water, hp)
})
socket.on("update status", (heat, water, hp) => {
// we tell the client to execute 'update status'
socket.broadcast.emit("update status", heat, water, hp)
console.log("=== Status: ", heat, water, hp)
})
socket.on("set direction", (dataX, dataY) => {
// we tell the client to execute 'update location'
socket.broadcast.emit("set direction", dataX, dataY)
console.log("***** Set Direction at: ", dataX, dataY)
})
// when the user disconnects.. perform this
socket.on('disconnect', () => {
console.log("Goodbye!")
})
})