push method
Sends the client a text (String) or binary (List<int>) message,
as the server would. Throws a StateError once the connection is
closed.
A message larger than the limit the client asked for
(maxTextMessageSize, maxBinaryMessageSize) is not delivered: the
connection closes with 1009 (message too big), as on dart:io.
Implementation
void push(Object message) {
if (isClosed) {
throw StateError('The connection is closed');
}
final (size, limit) = switch (message) {
String() => (utf8.encode(message).length, maxTextMessageSize),
List<int>() => (message.length, maxBinaryMessageSize),
_ => (0, null),
};
if (limit != null && limit >= 0 && size > limit) {
unawaited(
_end(CloseStatus.tooBigToProcess.withReason('Message too big')),
);
return;
}
_incoming.add(
message is List<int> && message is! Uint8List
? Uint8List.fromList(message)
: message,
);
}