adapter_websocket 0.1.8
adapter_websocket: ^0.1.8 copied to clipboard
A Flutter WebSocket adapter with auto-reconnect, heartbeat, interceptors, ACK confirmation, message queuing, topic multiplexing, and connection pooling.
0.1.8 #
Bug Fixes #
- Connection: Fixed a race in
WebSocketChannelAdapter.connect()where a stale connection's callbacks could overwrite the state of a newer one, subscriptions leaked across reconnects, and a stalled handshake could leaveconnect()hanging forever (connection generation counting + timeout now terminates the pending future). - ACK: Fixed
__ack__-pending messages being silently lost on disconnect — pending ACKs are now requeued for redelivery and late ACK frames are consumed instead of leaking into the message stream. - ACK / Queue: Draining the message queue no longer blocks behind one unacknowledged ACK message (previously up to
ackTimeout × maxAckRetries), and failed sends while connected now fall back to the queue instead of being lost. - Heartbeat: Fixed a race where
stop()during an in-flight heartbeat send could re-arm a zombie timeout timer and trigger auto-reconnect after an intentional disconnect. - Heartbeat: The mechanism now deactivates cleanly after
maxMissedHeartbeats(stats no longer report a dead heartbeat as active) and can be restarted after reconnection. - Reconnection: Fixed disconnections that occurred while a reconnect attempt was in flight being swallowed, which could leave the client permanently offline; superseded attempts can no longer report success or cancel a newer cycle. Also fixed an exponent overflow crash in exponential backoff with unlimited retries.
- Topics:
ChannelManager.route()no longer throws on malformed envelopes from the server (non-stringtopic/eventvalues are now guarded instead of hardcast). - Interceptors: The public
errorStreamnow forwards errors through the error interceptor chain — returningnullfromonErroractually suppresses the error, matchingonSend/onReceivesemantics. - Added
WebSocketClient.isReconnectingto distinguish "disconnected" from "automatically reconnecting".
Improvements #
- Restored the web platform declaration in
pubspec.yaml(a Dart-only registrant viadartPluginClass) so pub.dev correctly shows web support — it had been dropped accidentally in 0.1.7. - Added a canonical entry point at
package:adapter_websocket/adapter_websocket.dart; the oldwebsocket_plugin.dartimport remains as a backwards-compatible alias.
Example #
- Added a self-driving in-process mock WebSocket server (
example/lib/local_mock_websocket_adapter.dart) that answers heartbeat/ACK/topic traffic and broadcasts periodic events with zero network access — switch between Mock (local) and Real server right in the demo UI. Native builds use a real local WebSocket server; web builds use an in-memory transport with identical behaviour.
Tests #
- Added 13 regression tests covering all of the above fixes, plus an example integration test exercising the full mock flow (echo, ACK, heartbeat, topics, simulated disconnect → auto-reconnect).
- Made the previously jitter-dependent exponential-backoff test deterministic.
0.1.7 #
New Features #
WebSocketMessagenow has acopyWith()method for convenient object duplication.
Improvements #
- ACK:
AckManager.sendWithAck()now embeds__ack_id__directly into the JSON payload so the server can echo it back without out-of-band framing. - Message Queue: Added
useAckflag support; messages that were originally sent with ACK enabled are re-enqueued with the flag preserved and re-sent with ACK on reconnect. - Channel Manager:
ChannelManagernow passes aWebSocketMessage(instead of raw data) to the underlying send path, enabling full interceptor and ACK pipeline support for topic messages. - Reconnection Manager: Infinite-retry configuration (
maxReconnectAttempts = 0) is now displayed correctly in connection stats. - WebSocket Client: Refactored the message stream processing pipeline for clearer separation between raw transport, interceptor chain, and topic dispatch.
- WebSocketConfig.copyWith(): Supports explicit
nullclearing for optional fields (e.g.httpClient,expectedPongMessagePattern) so callers can reset a field without creating a whole new config. - README: Extended cross-platform availability table to document which configuration fields are supported on Web vs. native.
Build #
- Updated package version to
0.1.7. - Removed resource files that are not supported on the Web platform from the asset bundle.
0.1.6 #
Bug Fixes #
- Fixed Swift Package Manager (SPM) support for iOS and macOS: added
Package.swiftatios/adapter_websocket/Package.swiftandmacos/adapter_websocket/Package.swift, which is the path Flutter's SPM integration actually resolves. The previously existing root-levelios/Package.swiftandmacos/Package.swiftwere not found by the pub.dev validator or Flutter tooling.
0.1.5 #
Improvements #
- Explicitly declared the web platform in
pubspec.yaml(pluginClass: none), confirming that web WebSocket support is handled entirely in Dart viaweb_socket_channelwith no native plugin class required.
0.1.4 #
Improvements #
- Removed unused plugin scaffold files (
adapter_websocket_web.dart,untitled5_method_channel.dart,websocket_platform_interface.dart) that were generated byflutter create --template=pluginbut never wired into actual functionality. - Removed corresponding unused dependencies:
flutter_web_plugins,plugin_platform_interface. - Removed the empty web plugin class registration from
pubspec.yaml; web WebSocket support continues to work throughweb_socket_channel.
0.1.3 #
Improvements #
- Refactored
WebSocketChannelAdapterinternals to fully support the WASM platform, removing remainingdart:iodependencies from the connection path via conditional imports. - Improved
CompressionInterceptorreliability on native platforms. - Added GitHub Pages live demo (automatically deployed on every push to
master).
0.1.2 #
Bug Fixes #
- Fixed
CompressionInterceptornot actually applying gzip on native platforms — replaced stub with proper conditional import ofdart:ioGZipCodec. - Fixed
library_private_types_in_public_apilint violations inAckManagerandWebSocketTopicconstructors by inlining function types. - Removed unnecessary
librarydirective fromwebsocket_plugin.dart.
Improvements #
- WASM compatibility: removed top-level
dart:iodependency fromWebSocketConfigandWebSocketChannelAdapterusing conditional imports; package now compiles for WASM targets. - Added Swift Package Manager support (
Package.swift) for iOS and macOS. WebSocketConfig.httpClientfield is now typed asObject?to avoid adart:ioimport in the public API; the native adapter casts it internally.
0.1.1 #
0.1.0 #
New Features #
- Interceptor / Middleware —
WebSocketInterceptorabstract class andInterceptorChainfor inspecting, transforming, or suppressing messages at send and receive time. Ships with a built-inLoggingInterceptor. - Message Queue (offline buffer) —
MessageQueuebuffers outgoing messages while the connection is down and automatically flushes them on reconnect. Configurable viaenableMessageQueue,maxQueueSize, andmessageQueueTimeout. - ACK Confirmation —
AckManagerinjects a unique__ack_id__into outgoing messages and waits for server acknowledgement. Supports configurable timeout and automatic retries. Configurable viaenableAck,ackTimeout, andmaxAckRetries. - Topic Multiplexing (Channel/Topic) —
ChannelManagerandWebSocketTopicenable multiple logical channels over a single WebSocket connection using a JSON envelope format ({"topic":"…","event":"…","payload":…}). Access viaclient.channel('topic:name'). - Compression —
CompressionInterceptortransparently gzip-compresses outgoing messages above a configurable byte threshold and decompresses incoming messages. Available on native platforms (not web). - Connection Pool —
WebSocketPoolmanages multipleWebSocketClientinstances across different server endpoints with round-robin, random, or least-connections load balancing. Supportsbroadcast()to all connected clients.
Improvements #
WebSocketConfig.copyWith()now includesexpectedPongMessagePattern.WebSocketClientmessage pipeline runs through the interceptor chain before sending and after receiving.WebSocketClient.send()andsendMessage()enqueue messages when disconnected (ifenableMessageQueueis enabled) instead of immediately throwing.- Queue is drained automatically on reconnect success (both from
connect()and from the reconnection manager). connectionStatsnow includesmessageQueue,ack,channels, andinterceptorsfields.
Bug Fixes #
- Fixed
_isHeartbeatMessage()null dereference when onlyexpectedPongMessagewas set. - Fixed
copyWith()droppingexpectedPongMessagePattern. - Fixed heartbeat pong waiting logic ignoring
expectedPongMessagePattern. - Fixed
handleIncomingMessage()not recognising pong responses matched byexpectedPongMessagePattern. - Fixed
WebSocketClient._publishStats()not being called after initiating reconnection from heartbeat timeout. - Fixed shadowed variable in
reconnection_manager_test.dartcausing NullPointerException. - Fixed
ReconnectionManagertimer leak between tests by addingtearDown. - Fixed
reconnection_manager_test.dart"max attempts" test not waiting long enough for exponential backoff. - Fixed
websocket_plugin_test.dartunstable-connection test relying on 30-second instability timer.
0.0.2 #
- TODO: Describe initial release.