fix websocket closed

Signed-off-by: ale <ale@manalejandro.com>
This commit is contained in:
ale 2025-06-08 02:50:17 +02:00
parent 4b79569b2d
commit 8306df346a
Signed by: ale
GPG Key ID: 244A9C4DAB1C0C81

View File

@ -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;