Skip to main content

WSTransportManager

WebSocket transport manager for working with a remote Duit server.

Implements TransportCapabilityDelegate and provides bidirectional communication with the server via WebSocket connection for fetching UI layouts and handling real-time events.

Constructor​

WSTransportManager({
required String url,
String baseUrl = "",
Map<String, String> defaultHeaders = const {},
Converter<Object?, String>? encoder,
Converter<Uint8List, Object?>? decoder,
});

Parameters​

ParameterTypeDefaultDescription
urlString—URL for WebSocket connection (required)
baseUrlString""Base URL (optional)
defaultHeadersMap<String, String>{}Headers for establishing connection
encoderConverter?nullCustom encoder for outgoing messages
decoderConverter?nullCustom decoder for incoming messages

Features​

  • Supports persistent bidirectional connection
  • Automatically processes incoming server events
  • Allows sending actions and receiving UI updates in real-time

Usage Examples​

Basic Usage​

final driver = XDriver.remote(
transportManager: WSTransportManager(
url: 'ws://api.example.com/ws',
),
);

With Authorization and Custom Decoder​

final driver = XDriver.remote(
transportManager: WSTransportManager(
url: 'wss://api.example.com/ws',
defaultHeaders: {
'Authorization': 'Bearer $token',
},
decoder: MyCustomDecoder(),
),
);

Message Format​

When executing actions, WSTransportManager sends messages in the following format:

{
"event": "<action_event_name>",
"payload": {
// action data
}
}
tip

WebSocket transport is ideal for applications requiring real-time UI updates, such as chats, dashboards, or collaborative tools.

warning

The URL for WebSocket connection must start with ws:// or wss:// (for secure connection).