publish method
Send publish message
Implementation
Future<Map<String, dynamic>> publish(String channel, dynamic data) async {
_logger.info('Dispatcher: Publishing to channel: $channel');
_logger.info('Dispatcher: Current state: $_state, clientId: $_clientId');
if (_state != 3 || _clientId == null) {
// connected
_logger.severe(
'Dispatcher: Cannot publish - not connected or no clientId. State: $_state, clientId: $_clientId');
throw FayeError.network('Not connected');
}
final message = {
'channel': channel,
'data': data,
'clientId': _clientId,
'id': _generateMessageId(),
'ext': <String, dynamic>{}, // Required for session maintenance
};
// Apply extension if available
Map<String, dynamic> processedMessage = message;
if (_extension != null) {
try {
_logger.info('Dispatcher: Original message: $message');
processedMessage = _extension.outgoing(message);
_logger.info('Dispatcher: Extension returned: $processedMessage');
_logger.info('Dispatcher: Applied extension to message');
} catch (e) {
_logger.warning('Dispatcher: Extension processing failed: $e');
}
}
_logger.info('Dispatcher: Publishing message: $processedMessage');
return await _sendMessage(processedMessage);
}