WebSocketPool class
Manages a pool of WebSocketClient instances across multiple server endpoints.
final pool = WebSocketPool(
configs: [
WebSocketConfig(url: 'wss://server1.example.com'),
WebSocketConfig(url: 'wss://server2.example.com'),
],
strategy: PoolStrategy.roundRobin,
);
await pool.connectAll();
final client = pool.acquire(); // picks next client
await client.sendText('hello');
await pool.broadcast('ping'); // sends to all connected clients
await pool.dispose();
Constructors
-
WebSocketPool({required List<
WebSocketConfig> configs, PoolStrategy strategy = PoolStrategy.roundRobin, WebSocketAdapter adapterFactory(WebSocketConfig)?})
Properties
- connectedCount → int
-
Number of currently connected clients.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- size → int
-
Number of clients in the pool.
no setter
- strategy → PoolStrategy
-
final
Methods
-
acquire(
) → WebSocketClient - Returns a client according to the pool strategy.
-
broadcast(
dynamic data) → Future< void> -
Sends
datato every connected client. -
broadcastMessage(
WebSocketMessage message) → Future< void> - Sends a WebSocketMessage to every connected client.
-
connectAll(
) → Future< void> - Connects all clients in parallel.
-
connectFirst(
) → Future< void> - Connects the first client only (lazy startup).
-
dispose(
) → Future< void> -
getStats(
) → List< Map< String, dynamic> > - Returns per-client statistics.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited