feat: added on connection websocket server callback
This commit is contained in:
parent
a6fe1bff19
commit
cbd6bd4791
@ -15,7 +15,7 @@ const PORT = normalizePort(process.env.PORT || '6595')
|
|||||||
|
|
||||||
const debug = initDebug('deemix-gui:server')
|
const debug = initDebug('deemix-gui:server')
|
||||||
export const app: Application = express()
|
export const app: Application = express()
|
||||||
const ws = new WsServer({ noServer: true })
|
const wss = new WsServer({ noServer: true })
|
||||||
const server = http.createServer(app)
|
const server = http.createServer(app)
|
||||||
|
|
||||||
/* === Middlewares === */
|
/* === Middlewares === */
|
||||||
@ -35,10 +35,16 @@ if (process.env.NODE_ENV !== 'test') {
|
|||||||
server.listen(PORT)
|
server.listen(PORT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wss.on('connection', ws => {
|
||||||
|
ws.on('message', message => {
|
||||||
|
console.log('received: %s', message)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
/* === Server callbacks === */
|
/* === Server callbacks === */
|
||||||
server.on('upgrade', (request, socket, head) => {
|
server.on('upgrade', (request, socket, head) => {
|
||||||
ws.handleUpgrade(request, socket, head, socket => {
|
wss.handleUpgrade(request, socket, head, socket => {
|
||||||
ws.emit('connection', socket, request)
|
wss.emit('connection', socket, request)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
server.on('error', getErrorCb(PORT))
|
server.on('error', getErrorCb(PORT))
|
||||||
|
Loading…
Reference in New Issue
Block a user