2018-11-07 21:26:32 +01:00
|
|
|
/*
|
|
|
|
* devnull_server.js
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
const WebSocket = require('ws');
|
|
|
|
|
2018-11-10 03:23:49 +01:00
|
|
|
let wss = new WebSocket.Server({ port: 5678, perMessageDeflate: true })
|
2018-11-07 21:26:32 +01:00
|
|
|
|
2018-11-10 03:23:49 +01:00
|
|
|
wss.on('connection', (ws) => {
|
2018-11-07 21:26:32 +01:00
|
|
|
|
2018-11-10 03:23:49 +01:00
|
|
|
let handshake = false
|
|
|
|
let authenticated = false
|
|
|
|
|
|
|
|
ws.on('message', (data) => {
|
2018-11-07 21:26:32 +01:00
|
|
|
|
|
|
|
console.log(data.toString('utf-8'))
|
|
|
|
|
|
|
|
if (!handshake) {
|
|
|
|
let response = {
|
|
|
|
"action": "auth/handshake/ok",
|
|
|
|
"body": {
|
|
|
|
"data": {
|
|
|
|
"nonce": "MTI0Njg4NTAyMjYxMzgxMzgzMg==",
|
|
|
|
"version": "0.0.24"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"id": 1
|
|
|
|
}
|
|
|
|
ws.send(JSON.stringify(response))
|
|
|
|
handshake = true
|
|
|
|
} else if (!authenticated) {
|
|
|
|
let response = {
|
|
|
|
"action": "auth/authenticate/ok",
|
|
|
|
"body": {},
|
|
|
|
"id": 2
|
|
|
|
}
|
|
|
|
|
|
|
|
ws.send(JSON.stringify(response))
|
|
|
|
authenticated = true
|
|
|
|
} else {
|
|
|
|
console.log(data)
|
|
|
|
}
|
|
|
|
});
|
2018-11-10 03:23:49 +01:00
|
|
|
})
|