forked from DRMALL/drm_api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebsocket.js
47 lines (35 loc) · 1.05 KB
/
websocket.js
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
const Bug = require('./model/Bug')
const Order = require('./model/Order')
const myEmitter = require('./tcp/emitter')
var sendEndNews = ''
class WebSocket {
constructor(io) {
this.io = io
this.init()
}
init() {
this.io.of('/socket').on('connection', socket => {
myEmitter.on('coming', (app_data) => {
if(typeof sendEndNews == 'object') {
console.log('clearTimeout')
clearTimeout(sendEndNews)
}
socket.emit('news', app_data)
sendEndNews = setTimeout(() => {
socket.emit('news', {number: '', ts: new Date().getTime(), data: []} )
}, 1000*60*5 )
})
myEmitter.on('orderNotice', (noticeResult) => {
socket.emit('orderNotice', noticeResult)
})
socket.on('orderIsHandled', (id, fn) => {
console.log(id)
// Order.find({_id: id}).exec((err, res) => {
// if(err) console.error(err)
// this.io.emit('orderNotice', { code: 200, message: 'ok', data: res })
// })
})
})
}
}
module.exports = WebSocket