sendMessage method

  1. @override
void sendMessage(
  1. Object message
)
override

Sends message as a text frame when it is a String, or as a binary frame when it is a List<int>. Throws a WebSocketException when the session is no longer open, and an ArgumentError for any other type. It does not wait for the frame to leave: the message waits in memory until the network takes it. On dart:io a session whose other side takes nothing gives up past its limits (512 KB waiting, or 10 seconds) and drops the connection, and IoWebSocketSession.flush waits until what was sent has left; see IoWebSocketSession.

Implementation

@override
void sendMessage(Object message) {
  if (isClosed) {
    throw WebSocketException('the connection is closed', url: uri);
  }
  final value = switch (message) {
    String() => message,
    Uint8List() => message,
    List<int>() => Uint8List.fromList(message),
    _ => throw ArgumentError.value(
      message,
      'message',
      'a String or a List<int>',
    ),
  };
  _sent.add(value);
  _sentEvents.add(value);
}