-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathindex.js
More file actions
72 lines (61 loc) · 1.58 KB
/
Copy pathindex.js
File metadata and controls
72 lines (61 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict'
require('colors')
const config = require('./config.json')
let io
const datas = {
stringData: 'foo',
intData: 5,
floatData: 0.5,
boolData: true,
nested: {
hello: 'world'
}
}
const simplyTheBest = [
`I call you when I need you, my heart's on fire`,
`You come to me, come to me wild and wired`,
`Oh, you come to me`,
`give me everything I need.`,
`Give me a lifetime of promises and a world of dreams`,
`Speak the language of love like you know what it means`,
`And it can't be wrong, take my heart`,
`And make it strong, baby`
]
io = require('socket.io')(config.server.port)
io.on('connection', function (socket) {
console.log('connection'.bold.green)
console.log('query:', socket.handshake.query)
let emitInterval = setInterval(() => {
socket.emit('server-event', datas)
socket.emit('pingy')
}, 2000)
socket.emit('array-event', simplyTheBest)
socket
.on('disconnect', () => {
console.log('disconnect'.bold.red)
clearInterval(emitInterval)
})
.on('pongy', (data) => {
console.log('pongy'.blue, data)
})
.on('tina', (lines) => {
JSON.parse(lines).forEach(line => {
console.log('tina'.green, line)
})
})
})
const nsp = io.of('/nsp')
nsp.on('connection', function (socket) {
console.log('connection from namespace /nsp'.bold.green)
let emitInterval = setInterval(() => {
socket.emit('nsping')
}, 2000)
socket
.on('disconnect', () => {
console.log('disconnect from namespace /nsp'.bold.red)
clearInterval(emitInterval)
})
.on('nspong', (data) => {
console.log('nspong'.blue)
})
})