ThrottleWebSocketChannel class

A WebSocketChannel wrapper that applies a ThrottleController's profile to a WebSocket connection: the handshake, every inbound frame, and every outbound frame — and records them in the live log alongside HTTP traffic.

The same conditions apply as for HTTP: latency and jitter delay each frame, the bandwidth cap slows large frames, packet loss drops individual frames, and failure injection / an offline condition fails the connection.

Wrap whatever channel you already create:

import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:flutter_network_throttler/web_socket.dart';

final raw = WebSocketChannel.connect(Uri.parse('wss://example.com/socket'));
final socket = ThrottleWebSocketChannel(raw, controller: controller);

socket.stream.listen(handleMessage);
socket.sink.add('ping');
Inheritance
  • Object
  • StreamChannelMixin
  • ThrottleWebSocketChannel
Implemented types
  • StreamChannelMixin

Constructors

ThrottleWebSocketChannel(WebSocketChannel inner, {required ThrottleController controller, Uri? url})
Wraps inner, throttling it through controller.
ThrottleWebSocketChannel.connect(Uri uri, {required ThrottleController controller, Iterable<String>? protocols})
Opens a throttled connection to uri in one call.
factory

Properties

closeCode → int?
The close code set when the WebSocket connection is closed.
no setter
closeReason → String?
The close reason set when the WebSocket connection is closed.
no setter
controller → ThrottleController
The controller whose profile drives throttling decisions.
final
hashCode → int
The hash code for this object.
no setterinherited
inner → WebSocketChannel
The underlying channel doing the real WebSocket I/O.
final
protocol → String?
The subprotocol selected by the server.
no setter
ready → Future<void>
A future that will complete when the WebSocket connection has been established.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sink → WebSocketSink
The sink for sending values to the other endpoint.
no setteroverride
stream → Stream
The single-subscription stream that emits values from the other endpoint.
no setteroverride

Methods

cast<S>() → StreamChannel<S>
Returns a copy of this with the generic type coerced to S.
inherited
changeSink(StreamSink change(StreamSink)) → StreamChannel
Returns a copy of this with sink replaced by change's return value.
inherited
changeStream(Stream change(Stream)) → StreamChannel
Returns a copy of this with stream replaced by change's return value.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pipe(StreamChannel other) → void
Connects this to other, so that any values emitted by either are sent directly to the other.
inherited
toString() → String
A string representation of this object.
inherited
transform<S>(StreamChannelTransformer<S, dynamic> transformer) → StreamChannel<S>
Transforms this using transformer.
inherited
transformSink(StreamSinkTransformer transformer) → StreamChannel
Transforms only the sink component of this using transformer.
inherited
transformStream(StreamTransformer transformer) → StreamChannel
Transforms only the stream component of this using transformer.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited