reconnecting-websocket
A wrapper around WebSocket that reconnects when the socket
drops. Uses Backoff to determine the delay between reconnects
Features
tracing- enables thetracingcrate and logs everything it's doingstate-events- changes the Item type of the stream to be an enum that is either a message or a status change Both are enabled by default
Usage
Input means stuff you want to send from this client to the server (Sink)
Outut means stuff you want to receive back from the server (Source)
- Implement
TryFromforMessagefor your input type- The
TryFrom::Errortype must implementDebug
- The
- Implement
TryFrom<Message>for your output type- The
TryFrom::Errortype must implementDebug
- The
- Both input and output need to implement
Unpinand, if using tracing feature,Debug - Use
SocketBuilderto set the URL and configure backoff.get_proto_and_hostcan help constructing the URL relative to the currentwindow.location - Call
SocketBuilder::opento connect the socket. The errorsopenreturns are likely fatal (invalid URL, blocked port), seeWebSocket::openfor details. The first connect is done in the builder so it fails fast if these fatal errors occur but the same kind of error can also occur on any reconnect and be returned by theSocketStreamimplementation - The returned
Socketcan then be polled to get incoming messages.Socket::sendcan be called to send messages orSocket::get_sendercan be used to get anUnboundedSender.Socket::closeor dropping it will drop the innerWebSocketwhich sends a close frame and cleans up the event handlers