Current code for opening websocket :
139 this.ws = new WebSocket('wss://ws.blockchain.info/inv')
140 this.ws.on('open', () => {
141 this.ws.send('{"op":"unconfirmed_sub"}')
142 setInterval(() => {
143 this.ws.send('{"op":"ping"}')
144 }, 10000)
145 })
At first theres no issue with this code, it keep the websocket still alive everytime my node js running. But starting yesterday the websocket giving an error like this every around 10 sec of opened.
Error: WebSocket is not open: readyState 3 (CLOSED)
at WebSocket.send (/root/project/node_modules/ws/lib/websocket.js:31
at Timeout.setInterval [as _onTimeout] (/root/project/src/master.js:143:17)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
Is that because the websocket is closing by itself? and if yes is theres any way to keep the websocket alive even if its already closed kinda like reopen it. Or maybe theres another alternate way to keep it alive ? The websocket itself is blockchain api. https://blockchain.info/api/api_websocket
Sorry for my newbie question tbh im not a programmer but i want learn how to fix this hope someone on stackoverflow can help me out! :D Thanks Stackoverflow!