-
-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (24 loc) · 663 Bytes
/
index.js
File metadata and controls
29 lines (24 loc) · 663 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
const server = require('../../server');
const { get, socket } = server.router;
const { render } = server.reply;
server({
socket: {
path: '/custompath'
}
},
get('/', ctx => {
ctx.session.counter = ctx.session.counter || 0;
return render('index.html');
}),
socket('connect', ctx => {
// Emit an event every second with +1 on the session
setInterval(() => {
// Increment the counter
ctx.session.counter++;
// For socket.io you need to manually save it
ctx.session.save();
// Send the value to the currently connected socket
ctx.socket.emit('message', ctx.session.counter);
}, 1000);
})
);