forked from cjzeven/Yii-GuestBook-Socket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (27 loc) · 850 Bytes
/
server.js
File metadata and controls
34 lines (27 loc) · 850 Bytes
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
const http = require('http')
const socket = require('socket.io')
const server = http.createServer()
const io = socket.listen(server)
const port = 3000
server.listen(port, function() {
console.log('Server listening at', port)
})
io.on('connection', function(socket) {
socket.on('create_guestbook', function() {
io.emit('replace_guestbook')
io.emit('replace_unread_counter')
})
socket.on('check_as_read', function() {
io.emit('replace_guestbook')
io.emit('replace_unread_counter')
io.emit('replace_read_counter')
})
socket.on('update_guestbook', function() {
io.emit('replace_guestbook')
});
socket.on('delete_guestbook', function() {
io.emit('replace_guestbook')
io.emit('replace_read_counter')
io.emit('replace_unread_counter')
});
})