Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implementation of WebSockets to address changes in kbss-cvut/termit#290
React-Scripts & Create React App Configuration Override
React-Scripts does not allow the modification of webpack configuration, which was required to support
.mjs
files required by a new library SvenKirschbaum/react-stomp-hooks.To add an option to override some configurations, Craco was added as a dev dependency.
Changed dependencies
Some package versions were adjusted to address audit security issues.
Changes
ActionType
was changed from constant to enum to allow usage of actions as typed keysdispatches vocabulary term count loading action on success
test, which seemed to be wrongBrowserStorage
will now artificially fire storage events to allow listening of token change (same for SecurityUtils when the token is cleared)WebSocket handling
WebSocket connection is established automatically by
WebSocketWrapper
when a security token is available (not blank), and the lost connection is automatically reconnected.Publishing
The
useStompClient()
hook can be used to publish a message from a component, or thewithStompClient
wrapper can be used for HOC.Subscribing
The component can subscribe to messages during its lifetime with the
useSubscription
hook or thewithSubscription
wrapper for HOC.Subscribing in a component has a disadvantage - the subscription is canceled and renewed every time React decides to remount the element, so the subscription may eventually miss some message (and BE is notified about un/subscribing every time too).
As an alternative, it is possible to register a global
WebSocketDispatcher
, which will be active for the life-cycle ofWebSocketWrapper
.Global dispatchers are registered in
src/reducer/WebSocketDispatchers.ts#DISPATCHERS
constant for individual actions using a helper function to construct the key-value pair.Dispatcher is defined by subscribed destinations, relevant action, and the message callback.
Each dispatcher may listen to one or more destinations.
All registered dispatchers are instanced by
WebSocketApp
asWebSocketDispatcherSubscriber
components.