-
Notifications
You must be signed in to change notification settings - Fork 795
feat(ws): add methods taking in a tungstenite config #2373
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this mimics tungsenite's API and is an additional function so no breaking changes.
lgtm, pending nit
@@ -50,6 +50,34 @@ impl WsClient { | |||
Ok(this) | |||
} | |||
|
|||
/// Establishes a new websocket connection. This method allows specifying a custom websocket | |||
/// configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we link to tungsenite's connect functions here in the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/// custom websocket configuration. | ||
pub async fn connect_with_reconnects_and_config( | ||
conn: impl Into<ConnectionDetails>, | ||
reconnects: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
make last argument so arg 1+2 are identical to connect_with_config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, done in last commit, I've also changed the name so its connect_with_config_and_reconnects
which will make it pop in IDE hints once you already decided you want to use a config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config is discarded, so will not apply to successive reconnects. Need to modify the struct to store the Option, and the need to modify the reconnect
function to use it if available
Signed-off-by: Francesco <francesco@fulminlabs.org>
Signed-off-by: Francesco <francesco@fulminlabs.org>
Signed-off-by: Francesco <francesco@fulminlabs.org>
wasm compilation is broken. I believe you'll need to add a few cfg blocks to the new reconnect logic and related imports |
Signed-off-by: Francesco <francesco@fulminlabs.org>
@@ -234,6 +240,70 @@ impl RequestManager { | |||
)) | |||
} | |||
|
|||
#[cfg(not(target_arch = "wasm32"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we DRY these? this and reconnect()
are largely duplicated code. take the part that needs to be conditionally compiled and move it into a smaller function instead of duplicating the entire function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be better now
Signed-off-by: Francesco <francesco@fulminlabs.org>
Motivation
Currently the websocket implementation does not allow to pass in a custom Tungestenite config. For example, its not possible to increase the default msg size over the Tungestenite default, which can lead to
Message Too Long
errors if fetching a lot of events with a lot of fields in them, one case where I've seen this failure in practice is when fetching around 8k events like this one:Solution
This PR adds 2 new methods to the
WsClient
and theWsManager
:connect_with_config
which is the same asconnect
, but allows taking in a Tungstenite config objectconnect_with_config_and_reconnects
which is the same asconnect_with_reconnects
, but allows taking in a Tungstenite config object.PR Checklist