-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (34 loc) · 1.01 KB
/
index.js
File metadata and controls
43 lines (34 loc) · 1.01 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
const app = require('express')()
const server = require('http').Server(app)
const io = require('socket.io')(server)
var screen
app.get('/', (req, res) => {
res.sendFile(__dirname + '/screen.html')
})
app.get('/r', (req, res) => {
res.sendFile(__dirname + '/remote.html')
})
io.on('connection', (socket) => {
console.log(`${socket.id} connected!`)
socket.emit('hello', {hello: 'world'})
socket.on('hello yourself', (data) => {
console.log(data)
})
socket.on('registerScreen', (data) => {
screen = {}
screen.id = socket.id
})
socket.on('sendToScreen', (data) => {
io.to(screen.id).emit('fromRemote', data)// relay from remote to screen!
})
socket.on('changeColor', () => {
io.to(screen.id).emit('remoteWantsNewColor', socket.id)
})
socket.on('disconnect', (data) => {
console.log(`${socket.id} disconnected. :(`)
})
socket.on('thanks', (data) => {
io.to(data).emit('thanks', socket.id)
})
})
server.listen(3000)