sendMessage method
Sends a message to the broker through the current connection.
Implementation
@override
void sendMessage(MqttMessage message) {
MqttLogger.log(
'MqttConnectionHandlerBase::sendMessage - sending message started >>> -> ',
message);
// Check for validity
if (!message.isValid) {
throw ArgumentError(
'MqttConnectionHandlerBase::sendMessage - message cannot be sent, not valid');
}
if ((connectionStatus.state == MqttConnectionState.connected) ||
(connectionStatus.state == MqttConnectionState.connecting)) {
final buff = typed.Uint8Buffer();
final stream = MqttByteBuffer(buff);
message.writeTo(stream);
stream.seek(0);
connection.send(stream);
// Let any registered people know we're doing a message.
for (final callback in sentMessageCallbacks) {
callback(message);
}
} else {
MqttLogger.log('MqttConnectionHandler::sendMessage - not connected');
}
MqttLogger.log(
'MqttConnectionHandlerBase::sendMessage - sending message ended >>>');
}