You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been experimenting with the heartbeat feature and as reported on comment #206 (comment) , this seems not sending any messages via websocket.
const {
sendMessage,
sendJsonMessage,
lastJsonMessage,
readyState,
getWebSocket,
} = useWebSocket(socketUrl, {
onClose: (event) => { console.log("onClose : " + event) },
onError: (event) => { console.log("onError : " + event) },
onOpen: () => {
console.log("Connection opened.");
},
// share: true,
skipAssert: true,
retryOnError: true,
//Will attempt to reconnect on all close events, such as server shutting down
shouldReconnect: (closeEvent) => {
return true;
},
// Defaults to 20, so increased to 10000
reconnectAttempts: 10000,
//attemptNumber will be 0 the first time it attempts to reconnect, so this equation results in a reconnect pattern of 1 second, 2 seconds, 4 seconds, 8 seconds, and then caps at 10 seconds until the maximum number of attempts is reached
reconnectInterval: (attemptNumber) => {
const maxTime = 300; // Maximum time for reconnection
const baseTime = 2; // Base time for exponential backoff
// Calculate reconnect time using exponential backoff
const reconnectTime = Math.min(maxTime, Math.pow(baseTime, attemptNumber)) * 1000;
console.log("Reconnect attempt will be made in : " + reconnectTime + " ms");
return reconnectTime;
},
// Default
heartbeat: true,
}, connect);
Option 2 for heartbeat
heartbeat: {
message: 'ping',
returnMessage: 'pong',
timeout: 60000, // 1 minute, if no response is received, the connection will be closed
interval: 2500, // every 25 seconds, a ping message will be sent
},
Option 3 for heartbeat
heartbeat: {
message: function () {
return JSON.stringify({
type: 'ping'
});
},
returnMessage: function () {
return JSON.stringify({
status: 'success',
message: 'pong',
});
},
timeout: 60000, // 1 minute, if no response is received, the connection will be closed
interval: 2500, // every 25 seconds, a ping message will be sent
}
Note : You can see one of the option I choose is skipAssert: true, . This was because of error I was getting
app.js:22773 Uncaught (in promise) Error
at assertIsWebSocket (app.js:22773:17)
at bindCloseHandler (app.js:22836:38)
at attachListeners (app.js:22897:34)
at createOrJoinSocket (app.js:23097:56)
at app.js:23507:85
at step (app.js:23387:25)
at Object.next (app.js:23334:20)
at fulfilled (app.js:23305:30)
So using skipAssert: true, has fixed the error. The note probably is another issue I should open.
The text was updated successfully, but these errors were encountered:
Hey,
I have been experimenting with the heartbeat feature and as reported on comment #206 (comment) , this seems not sending any messages via websocket.
Option 2 for heartbeat
Option 3 for heartbeat
Note : You can see one of the option I choose is
skipAssert: true,
. This was because of error I was gettingSo using
skipAssert: true,
has fixed the error. The note probably is another issue I should open.The text was updated successfully, but these errors were encountered: