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
|
// Bitcoin transaction monitoring functions
|
||||||
async function initBitcoinMonitoring() {
|
async function initBitcoinMonitoring() {
|
||||||
try {
|
try {
|
||||||
|
// Make sure to stop any existing monitoring first
|
||||||
|
if (btcSocket) {
|
||||||
|
stopBitcoinMonitoring();
|
||||||
|
}
|
||||||
|
|
||||||
btcSocket = new Socket();
|
btcSocket = new Socket();
|
||||||
|
|
||||||
btcSocket.onTransaction(async (tx) => {
|
btcSocket.onTransaction(async (tx) => {
|
||||||
@ -312,10 +317,20 @@ async function processBitcoinTransaction(tx, blockexplorer) {
|
|||||||
function stopBitcoinMonitoring() {
|
function stopBitcoinMonitoring() {
|
||||||
if (btcSocket) {
|
if (btcSocket) {
|
||||||
isMonitoring = false;
|
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;
|
btcSocket = null;
|
||||||
btcMonitorChannel = null;
|
btcMonitorChannel = null;
|
||||||
minBtcAmount = 0; // Reset minimum amount
|
minBtcAmount = 0; // Reset minimum amount
|
||||||
console.log('Bitcoin monitoring stopped');
|
console.log('Bitcoin monitoring stopped and WebSocket closed');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user