void Engine::OnMessageReceivedCallback()

in NearbyConnectionsCpp/app/src/main/cpp/NearbyConnection.cpp [128:185]


void Engine::OnMessageReceivedCallback(int64_t receiver_id,
                                       std::string const &remote_endpoint,
                                       std::vector<uint8_t> const &payload,
                                       bool is_reliable) {
  std::string msg;
  for (auto ch : payload) msg += ch;

  switch (msg[0]) {
    case PAYLOAD_HEADER_NEW_CONNECTION: {
      LOGV("Adding relayed endpoint (%s, %d) to me",
           remote_endpoint.c_str(), static_cast<int>(remote_endpoint.length()));
      std::string other_endpoint = msg.substr(1);
      AddConnectionEndpoint(other_endpoint, false, false);
      EnableUI(true);
      return;
    }
    case PAYLOAD_HEADER_GUEST_READY: {
      // The link I am hosting is up, and the other end ( guest end )
      // is ready to accept all of my connected nodes
      LOGI("Received ready message from =%s", remote_endpoint.c_str());
      SendAllConnections(remote_endpoint);
      return;
    }
    case PAYLOAD_HEADER_INTERMEDIATE_SCORE: {
      int score;
      if (!DecodeScorePayload(payload, &score, remote_endpoint)) {
        LOGE("DecodeScorePayload return failed\n");
      } else {
        UpdatePlayerScore(remote_endpoint, score, false);
        UpdateScoreBoardUI(true);
      }
      return;
    }
    case PAYLOAD_HEADER_FINAL_SCORE: {
      int score;
      if (!DecodeScorePayload(payload, &score,remote_endpoint)) {
        LOGE("DecodeScorePayload return failed\n");
      } else {
        UpdatePlayerScore(remote_endpoint, score, true);
        UpdateScoreBoardUI(true);
      }
      return;
    }
    case PAYLOAD_HEADER_DISCONNECTED: {
      LOGV("Received Disconnect Notification for Endpoint ID %s",
           remote_endpoint.c_str());
      RemoveConnectionEndpoint(remote_endpoint, false);
      EnableUI(true);
      return;
    }
    default: {
      // Drop the message
      LOGE("Unknown payload type: from(%s) with payload(%s) in %s @ line %d",
           remote_endpoint.c_str(), msg.c_str(), __FILE__, __LINE__);
      return;
    }
  }
}