fix websocket closed
Signed-off-by: ale <ale@manalejandro.com>
This commit is contained in:
parent
4b79569b2d
commit
8306df346a
17
index.js
17
index.js
@ -213,6 +213,11 @@ async function validateMultimediaUrl(url) {
|
||||
// Bitcoin transaction monitoring functions
|
||||
async function initBitcoinMonitoring() {
|
||||
try {
|
||||
// Make sure to stop any existing monitoring first
|
||||
if (btcSocket) {
|
||||
stopBitcoinMonitoring();
|
||||
}
|
||||
|
||||
btcSocket = new Socket();
|
||||
|
||||
btcSocket.onTransaction(async (tx) => {
|
||||
@ -312,10 +317,20 @@ async function processBitcoinTransaction(tx, blockexplorer) {
|
||||
function stopBitcoinMonitoring() {
|
||||
if (btcSocket) {
|
||||
isMonitoring = false;
|
||||
|
||||
// Properly close the WebSocket connection
|
||||
try {
|
||||
if (btcSocket.ws && btcSocket.ws.readyState === 1) { // WebSocket.OPEN = 1
|
||||
btcSocket.ws.close();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error closing WebSocket:', error);
|
||||
}
|
||||
|
||||
btcSocket = null;
|
||||
btcMonitorChannel = null;
|
||||
minBtcAmount = 0; // Reset minimum amount
|
||||
console.log('Bitcoin monitoring stopped');
|
||||
console.log('Bitcoin monitoring stopped and WebSocket closed');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user