activate method
Activates the communicator and begins trying to connect to and communicate with the backend server.
Implementation
Future<void> activate() async {
if (deactivated == true) {
throw Exception('Communicator has already been deactivated');
}
_active = true;
_commandTimer?.cancel();
_commandTimer = null;
_pingTimer?.cancel();
_pingTimer = Timer.periodic(pingTime, (timer) {
if (_online == true) {
sendCommand(PingCommand());
}
});
_reconnectTimer?.cancel();
_reconnectTimer = null;
await _channelSubscription?.cancel();
_channelSubscription = null;
await _commandStreamController?.close();
_commandQueue.clear();
_commandStreamController = StreamController<DeviceCommand>.broadcast();
_connect();
}