send method
Sends data to the server. Returns Success when the data was handed
to the underlying sink, or an Error if the channel is not connected.
Implementation
Result<void> send(dynamic data) {
final channel = _channel;
if (channel == null || _closed) {
return const Error<void>(
Failure.network(message: 'WebSocket is not connected'),
);
}
try {
channel.sink.add(data);
return const Success<void>(null);
} catch (e, st) {
return Error<void>(
Failure.network(message: e.toString(), cause: e, stackTrace: st),
);
}
}