From 48bef143d86b02d7feeeac3e1faa0e5e00e09ea6 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 13 Jan 2021 21:33:20 +0200 Subject: [PATCH] fix not being able to re-enable sockets until page refresh --- CHANGELOG.md | 1 + src/modules/api.js | 11 ++++++++++- src/services/api/api.service.js | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6160c5f4..0b9c7f68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Handle punycode in screen names - Fixed local dev mode having non-functional websockets in some cases - Show notices for websocket events (errors, abnormal closures, reconnections) +- Fix not being able to re-enable websocket until page refresh ## [2.2.2] - 2020-12-22 ### Added diff --git a/src/modules/api.js b/src/modules/api.js index 01c65e49..2be0f236 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -40,7 +40,16 @@ const api = { // Global MastoAPI socket control, in future should disable ALL sockets/(re)start relevant sockets enableMastoSockets (store) { const { state, dispatch } = store - if (state.mastoUserSocket) return + // Do not initialize unless nonexistent or closed + if ( + state.mastoUserSocket && + ![ + WebSocket.CLOSED, + WebSocket.CLOSING + ].includes(state.mastoUserSocket.getState()) + ) { + return + } return dispatch('startMastoUserSocket') }, disableMastoSockets (store) { diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index f4483149..d3d5c68d 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -1152,6 +1152,7 @@ export const ProcessedWS = ({ // 1000 = Normal Closure eventTarget.close = () => { socket.close(1000, 'Shutting down socket') } + eventTarget.getState = () => socket.readyState return eventTarget }