Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client reconnect and stream re-request #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

russmatney
Copy link
Member

@russmatney russmatney commented Jun 8, 2023

Refactors plasma.client/websocket-transport to recreate the websocket on
disconnect, with an exponential back-off.

An important piece of this is re-:plasma/request-ing the known streams on
reconnect, 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 with nil or false
  • :on-reconnect - a function invoked after a successful reconnect.

Note that on-reconnect is called before on-open for now,
and on-open is still called when reconnecting - perhaps we
should only invoke one of these.
on-open is called when first
connecting (never when reconnecting), on-reconnect is called when
reconnecting.

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, but
there's also a bunch of context to share across the send/open/close/message
funcs, so maybe it's best as is.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant