Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 1.2.8 #1119

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cadt-ui",
"version": "1.2.7",
"version": "1.2.8",
"private": true,
"author": "Chia Network Inc. <[email protected]>",
"homepage": "./",
Expand Down
34 changes: 28 additions & 6 deletions src/store/actions/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const SOCKET_STATUS = keyMirror(
let socket;
let interval;
let reconnectInterval = 1000;
let reconnectAttempts = 0;

const notifyRefresh = _.debounce(dispatch => {
NotificationManager.info(
Expand All @@ -33,7 +34,7 @@ const notifyRefresh = _.debounce(dispatch => {
() => dispatch(refreshApp(true)),
true,
);
}, 100);
}, 1000);

const initListenersForEachMessageType = dispatch => {
Object.keys(messageTypes).forEach(key => {
Expand Down Expand Up @@ -84,20 +85,35 @@ export const emitAction = actionCreator => {
};

const reconnectSocket = _.debounce(dispatch => {
if (!socket || (socket && !socket.connected)) {
if (reconnectAttempts <= 10 && (!socket || !socket.connected)) {
console.log(
'Attempting to reconnect to socket server...',
reconnectAttempts,
);
dispatch(initiateSocket());
setTimeout(() => {
if (!socket || (socket && !socket.connected)) {
if (!socket || !socket.connected) {
reconnectSocket(dispatch);
}
reconnectInterval = reconnectInterval * 2;
reconnectInterval *= 2;
}, reconnectInterval);
} else if (reconnectAttempts > 10) {
console.log("Couldn't connect to socket server. Max attempts reached.");
dispatch(setSocketStatus(SOCKET_STATUS.OFFLINE));

clearInterval(interval);
}
}, 100);
}, 1000);

export const initiateSocket = remoteHost => {
disconnectSocket();

if (reconnectAttempts > 10) {
return;
}

reconnectAttempts++;

const WS_HOST = `${remoteHost || constants.API_HOST}/ws`;
const transports = ['websocket'];

Expand Down Expand Up @@ -158,16 +174,22 @@ export const initiateSocket = remoteHost => {
console.log('Attempting to connect to socket_id: ', socket.id);
console.log('### Socket Connected ###');
dispatch(setSocketStatus(SOCKET_STATUS.CONNECTED));
reconnectAttempts = 0;
socket.emit('authentication');
});

initListenersForEachMessageType(dispatch);

interval = setInterval(() => {
if (!socket || (socket && !socket.connected)) {
if (reconnectAttempts <= 10 && (!socket || !socket.connected)) {
dispatch(setSocketStatus(SOCKET_STATUS.OFFLINE));
clearInterval(interval);
reconnectSocket(dispatch);
} else if (reconnectAttempts > 10) {
console.log("Couldn't connect to socket server. Max attempts reached.");
dispatch(setSocketStatus(SOCKET_STATUS.OFFLINE));
clearInterval(interval);
disconnectSocket();
}
}, 5000);
};
Expand Down
Loading