onHeartbeat method

  1. @override
void onHeartbeat(
  1. Connect heartbeat,
  2. SocketInfo source
)
inherited

Handles incoming heartbeats.

  1. If the heartbeat was meant for another device, log it and ignore it.
  2. If it came from our dashboard, respond to it with sendHeartbeatResponse.
  3. If it came from another dashboard, log it and ignore it.
  4. If we are not connected to any dashboard, call onConnect and respond to it.

Implementation

@override
void onHeartbeat(Connect heartbeat, SocketInfo source) {
  if (heartbeat.receiver != device) {  // (1)
    logger.warning("Received a misaddressed heartbeat for ${heartbeat.receiver}");
  } else if (isConnected) {
    if (destination == source) {  // (2)
      sendHeartbeatResponse();
    } else {  // (3)
      logger.warning("Port $port is connected to $destination but received a heartbeat from $source");
    }
  } else {  // (4)
    onConnect(source);
    sendHeartbeatResponse();
  }
}