2
0

TimeProvider.cpp 597 B

123456789101112131415161718
  1. #include "TimeProvider.h"
  2. #include "Logger.h"
  3. using namespace cspot;
  4. TimeProvider::TimeProvider() {
  5. }
  6. void TimeProvider::syncWithPingPacket(const std::vector<uint8_t>& pongPacket) {
  7. CSPOT_LOG(debug, "Time synced with spotify servers");
  8. // Spotify's timestamp is in seconds since unix time - convert to millis.
  9. uint64_t remoteTimestamp = ((uint64_t) ntohl(extract<uint32_t>(pongPacket, 0))) * 1000;
  10. this->timestampDiff = remoteTimestamp - getCurrentTimestamp();
  11. }
  12. unsigned long long TimeProvider::getSyncedTimestamp() {
  13. return getCurrentTimestamp() + this->timestampDiff;
  14. }