Skip to content

Commit

Permalink
console: Fix stream reconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
kschiffer committed Dec 11, 2023
1 parent 8925c04 commit 0c81e80
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
8 changes: 3 additions & 5 deletions pkg/webui/console/lib/events/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ export const eventMessages = {

'synthetic.status.reconnected:type': 'Stream reconnected',
'synthetic.status.reconnected:preview': 'The stream connection has been re-established',

'synthetic.status.reconnected:details':
'The Console was able to reconnect to the internet and resumed the event stream. Subsequent event data will be received and displayed. Note that event data which was possibly emitted during the network disruption will not be re-delivered.',
'The Console was able to reconnect to the network and resumed the event stream. Subsequent event data will be received and displayed. Note that event data which was possibly emitted during the network disruption will only be re-delivered within the range of the event retention configuration for your network.',

'synthetic.status.closed:type': 'Stream connection closed',
'synthetic.status.closed:preview': 'The connection was closed by the stream provider',

'synthetic.status.closed:preview': 'The connection was closed',
'synthetic.status.closed:details':
'The Console received a close signal from the stream provider. This usually means that the backend server shut down. This can have various causes, such as scheduled maintenance or malfunction which caused a forced restart. The Console will then reconnect automatically once the stream provider becomes available again.',
'The event stream was closed. This can be for various reasons, such as your machine going into standby mode or the internet connection being interrupted. The stream will reconnect automatically once the internet connection has been re-established.',

'synthetic.status.cleared:type': 'Events cleared',
'synthetic.status.cleared:preview': 'The events list has been cleared',
Expand Down
14 changes: 7 additions & 7 deletions pkg/webui/console/store/middleware/logics/events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 The Things Network Foundation, The Things Industries B.V.
// Copyright © 2019 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -132,16 +132,16 @@ const createEventsConnectLogics = (reducerName, entityName, onEventsStart) => {

try {
channel = await onEventsStart([id], filterRegExp, EVENT_TAIL, after)
dispatch(startEventsSuccess(id, { silent }))

channel.on('open', () => dispatch(startEventsSuccess(id, { silent })))
channel.on('message', message => dispatch(getEventSuccess(id, message)))
channel.on('error', error => dispatch(getEventFailure(id, error)))
channel.on('close', wasClientRequest =>
dispatch(closeEvents(id, { silent: wasClientRequest })),
)

channel.on('open', () => dispatch(startEventsSuccess(id, { silent })))
channel.on('close', wasClientRequest => {
dispatch(closeEvents(id, { silent: wasClientRequest }))
channel = null
})
} catch (error) {
console.log('err', error)
if (isUnauthenticatedError(error)) {
// The user is no longer authenticated; reinitiate the auth flow
// by refreshing the page.
Expand Down
6 changes: 3 additions & 3 deletions pkg/webui/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,10 @@
"console.lib.events.definitions.synthetic.status.reconnecting:details": "The Console will periodically try to reconnect to the event stream if the connection was interrupted.",
"console.lib.events.definitions.synthetic.status.reconnected:type": "Stream reconnected",
"console.lib.events.definitions.synthetic.status.reconnected:preview": "The stream connection has been re-established",
"console.lib.events.definitions.synthetic.status.reconnected:details": "The Console was able to reconnect to the internet and resumed the event stream. Subsequent event data will be received and displayed. Note that event data which was possibly emitted during the network disruption will not be re-delivered.",
"console.lib.events.definitions.synthetic.status.reconnected:details": "The Console was able to reconnect to the network and resumed the event stream. Subsequent event data will be received and displayed. Note that event data which was possibly emitted during the network disruption will only be re-delivered within the range of the event retention configuration for your network.",
"console.lib.events.definitions.synthetic.status.closed:type": "Stream connection closed",
"console.lib.events.definitions.synthetic.status.closed:preview": "The connection was closed by the stream provider",
"console.lib.events.definitions.synthetic.status.closed:details": "The Console received a close signal from the stream provider. This usually means that the backend server shut down. This can have various causes, such as scheduled maintenance or malfunction which caused a forced restart. The Console will then reconnect automatically once the stream provider becomes available again.",
"console.lib.events.definitions.synthetic.status.closed:preview": "The connection was closed",
"console.lib.events.definitions.synthetic.status.closed:details": "The event stream was closed. This can be for various reasons, such as your machine going into standby mode or the internet connection being interrupted. The stream will reconnect automatically once the internet connection has been re-established.",
"console.lib.events.definitions.synthetic.status.cleared:type": "Events cleared",
"console.lib.events.definitions.synthetic.status.cleared:preview": "The events list has been cleared",
"console.lib.events.definitions.synthetic.status.cleared:details": "The list of displayed events has been cleared.",
Expand Down
3 changes: 3 additions & 0 deletions sdk/js/src/api/stream/subscribeToWebSocketStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export default async (

// Event listener for 'close'
wsInstances[url].addEventListener('close', closeEvent => {
// TODO: Handle close event codes.
// https://github.com/TheThingsNetwork/lorawan-stack/issues/6752

delete wsInstances[url]
Object.values(subscriptions)
.filter(s => s.url === url)
Expand Down

0 comments on commit 0c81e80

Please sign in to comment.