MqttConnectionKeepAlive constructor
MqttConnectionKeepAlive(
- IMqttConnectionHandler connectionHandler,
- EventBus? eventBus,
- int keepAliveSeconds, [
- int disconnectOnNoResponsePeriod = 0,
Initializes a new instance of the MqttConnectionKeepAlive class.
Implementation
MqttConnectionKeepAlive(IMqttConnectionHandler connectionHandler,
events.EventBus? eventBus, int keepAliveSeconds,
[int disconnectOnNoResponsePeriod = 0]) {
_connectionHandler = connectionHandler;
_clientEventBus = eventBus;
this.disconnectOnNoResponsePeriod = disconnectOnNoResponsePeriod * 1000;
keepAlivePeriod = keepAliveSeconds * 1000;
// Register for message handling of ping request and response messages.
connectionHandler.registerForMessage(
MqttMessageType.pingRequest, pingRequestReceived);
connectionHandler.registerForMessage(
MqttMessageType.pingResponse, pingResponseReceived);
connectionHandler.registerForAllSentMessages(messageSent);
// Start the timer so we do a ping whenever required.
pingTimer = Timer(Duration(milliseconds: keepAlivePeriod), pingRequired);
MqttLogger.log(
'MqttConnectionKeepAlive:: Initialised with a keep alive value of $keepAliveSeconds seconds');
disconnectOnNoResponsePeriod == 0
? MqttLogger.log(
'MqttConnectionKeepAlive:: Disconnect on no ping response is disabled')
: MqttLogger.log(
'MqttConnectionKeepAlive:: Disconnect on no ping response is enabled with a value of $disconnectOnNoResponsePeriod seconds');
}