feat(removed websockets): Removing websockets

This commit is contained in:
Chris Troutner
2019-08-10 12:05:19 -07:00
parent bdd0ef17fa
commit fd58feba39
-43
View File
@@ -185,49 +185,6 @@ console.log(`bch-api started on port ${port}`)
* Create HTTP server.
*/
const server = http.createServer(app)
const io = require("socket.io").listen(server)
io.on("connection", socket => {
console.log("Socket Connected")
socket.on("disconnect", () => {
console.log("Socket Disconnected")
})
})
/**
* Setup ZMQ connections if ZMQ URL and port provided
*/
if (process.env.ZEROMQ_URL && process.env.ZEROMQ_PORT) {
console.log(
`Connecting to BCH ZMQ at ${process.env.ZEROMQ_URL}:${process.env.ZEROMQ_PORT}`
)
const bitcoincashZmqDecoder = new BitcoinCashZMQDecoder(process.env.NETWORK)
sock.connect(`tcp://${process.env.ZEROMQ_URL}:${process.env.ZEROMQ_PORT}`)
sock.subscribe("raw")
sock.on("message", (topic, message) => {
try {
const decoded = topic.toString("ascii")
if (decoded === "rawtx") {
const txd = bitcoincashZmqDecoder.decodeTransaction(message)
io.emit("transactions", JSON.stringify(txd, null, 2))
} else if (decoded === "rawblock") {
const blck = bitcoincashZmqDecoder.decodeBlock(message)
io.emit("blocks", JSON.stringify(blck, null, 2))
}
} catch (error) {
const errorMessage = "Error processing ZMQ message"
console.log(errorMessage, error)
wlogger.error(errorMessage, error)
}
})
} else {
console.log(
"ZEROMQ_URL and ZEROMQ_PORT env vars missing. Skipping ZMQ connection."
)
}
/**
* Listen on provided port, on all network interfaces.