Open
Conversation
Moves the js/WebSocket to an atom so the send-f func can use the recreated ws after reconnection. Refactors websocket-transport so a setup-ws func can be reused. The reconnect-timeout atom and clearing may be unnecessary, but it feels like some clean up of the js/setTimeout might be proper.
Also renames `state` to `ws-state` to avoid conflict with ns-level `state` def.
Re-requests plasma streams from the client when reconnecting to the server. Adds the :event and :args to the state's stream maps so they can be re-requested later. Maybe there's a stronger opinion on whether to call on-open, on-reconnect, and the order of things. For now, this is enough to have apps work without refresh across server restarts.
- Drops the js/console.logs - Don't call on-open when reconnecting (only on-reconnect is called) - redistributes the functions somewhat, hopefully for readability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refactors
plasma.client/websocket-transportto recreate the websocket ondisconnect, with an exponential back-off.
An important piece of this is re-
:plasma/request-ing the known streams onreconnect, so the frontend defstreams continue to consume from the backend once the
client has reconnected.
This supports clients staying connected to streams across server restarts, which
is helpful especially when developing against your own server, or otherwise
restarting it by hand (the current behavior requires a browser refresh to
restore defhandler/defstream usage).
Two new attrs are supported on
plasma.client/websocket-transport::auto-reconnect?- defaults to true, disable withnilorfalse:on-reconnect- a function invoked after a successful reconnect.Note thaton-reconnectis called beforeon-openfor now,and
on-openis still called when reconnecting - perhaps weshould only invoke one of these.
on-openis called when firstconnecting (never when reconnecting),
on-reconnectis called whenreconnecting.
Feel free to call out any style/re-arrangement/refactors - it feels like there
could be a cleaner impl than doing this all in
websocket-transport, butthere's also a bunch of context to share across the send/open/close/message
funcs, so maybe it's best as is.