[Ethereum] Watching for changes in web3.isConnected()

web3js

I am using Meteor & Web3 to talk to a Geth node, and would like to have an event fire in web3 when the Geth node goes down.

Web3 has the ability to add callbacks to web3.eth.isSyncing to detect changes, but web3.eth.isConnected does not.

How can I detect changes in web3.eth.isConnected without having to use continuous polling?

Best Answer

You can try web3.net.listening

web3.net.listening
// or async
web3.net.getListening(callback(error, result){ ... })

This property is read only and says whether the node is actively listening for network connections or not.

Returns

Boolean - true if the client is actively listening for network connections, otherwise false.