PkWebSocketChannel class

WebSocket-based implementation of RealtimeChannel.

Features:

  • Automatic reconnection with exponential backoff (up to maxReconnectAttempts attempts)
  • Ping/pong keepalive via pingInterval
  • Outgoing message queue that buffers messages while disconnected and replays them on reconnect (backed by MessageBuffer)
final channel = PkWebSocketChannel(
  uri: Uri.parse('wss://example.com/socket'),
  channelId: 'room1',
);
await channel.connect();
channel.messages.listen((msg) => print(msg.payload));
await channel.send({'text': 'hello'}, type: 'chat');
Implemented types

Constructors

PkWebSocketChannel({required Uri uri, required String channelId, Map<String, String>? headers, Duration reconnectDelay = const Duration(seconds: 2), int maxReconnectAttempts = 10, Duration pingInterval = const Duration(seconds: 30), Duration connectTimeout = const Duration(seconds: 10), MessageBuffer? messageBuffer})
Creates a PkWebSocketChannel.

Properties

channelId String
The unique identifier for this channel.
final
hashCode int
The hash code for this object.
no setterinherited
isConnected bool
Whether the channel is currently connected.
no setteroverride
messages Stream<RealtimeMessage>
Stream of messages received on this channel.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
status Stream<ChannelStatus>
Stream of connection status changes.
no setteroverride

Methods

connect() Future<void>
Establishes the connection to the backend.
override
disconnect() Future<void>
Gracefully closes the connection.
override
dispose() Future<void>
Releases all resources. Call when the channel is no longer needed.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
send(Map<String, dynamic> payload, {String? type}) Future<void>
Sends payload to the channel.
override
toString() String
A string representation of this object.
inherited

Operators

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