send method
Send a message to the server
Implementation
@override
Future<void> send(Map<String, dynamic> message) async {
_logger.info('HTTP: Sending message: $message');
_logger.info('HTTP: Connected state: $connected');
if (!connected) {
_logger.severe('HTTP: Cannot send message - not connected');
throw FayeError.network('Not connected');
}
try {
_logger.info('HTTP: Sending request...');
final response = await _sendRequest(message);
// Handle response for immediate requests (handshake, subscribe, unsubscribe, publish)
if (response is List) {
for (final responseMessage in response) {
emitMessage(responseMessage);
}
} else if (response is Map<String, dynamic>) {
emitMessage(response);
}
recordMessageSent(message);
_logger.info('HTTP: Message sent successfully');
} catch (e) {
_logger.severe('HTTP: Failed to send message: $e');
emitError(FayeError.network('Failed to send message: $e'));
rethrow;
}
}