fix not being able to re-enable sockets until page refresh

This commit is contained in:
Henry Jameson 2021-01-13 21:33:20 +02:00
parent 64fa662644
commit 48bef143d8
3 changed files with 12 additions and 1 deletions

View file

@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Handle punycode in screen names - Handle punycode in screen names
- Fixed local dev mode having non-functional websockets in some cases - Fixed local dev mode having non-functional websockets in some cases
- Show notices for websocket events (errors, abnormal closures, reconnections) - 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 ## [2.2.2] - 2020-12-22
### Added ### Added

View file

@ -40,7 +40,16 @@ const api = {
// Global MastoAPI socket control, in future should disable ALL sockets/(re)start relevant sockets // Global MastoAPI socket control, in future should disable ALL sockets/(re)start relevant sockets
enableMastoSockets (store) { enableMastoSockets (store) {
const { state, dispatch } = 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') return dispatch('startMastoUserSocket')
}, },
disableMastoSockets (store) { disableMastoSockets (store) {

View file

@ -1152,6 +1152,7 @@ export const ProcessedWS = ({
// 1000 = Normal Closure // 1000 = Normal Closure
eventTarget.close = () => { socket.close(1000, 'Shutting down socket') } eventTarget.close = () => { socket.close(1000, 'Shutting down socket') }
eventTarget.getState = () => socket.readyState
return eventTarget return eventTarget
} }