CSpotContext.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <stdint.h>
  3. #include <memory>
  4. #include "LoginBlob.h"
  5. #include "MercurySession.h"
  6. #include "TimeProvider.h"
  7. #include "protobuf/metadata.pb.h"
  8. namespace cspot {
  9. struct Context {
  10. struct ConfigState {
  11. // Setup default bitrate to 160
  12. AudioFormat audioFormat = AudioFormat::AudioFormat_OGG_VORBIS_160;
  13. std::string deviceId;
  14. std::string deviceName;
  15. std::vector<uint8_t> authData;
  16. int volume;
  17. std::string username;
  18. std::string countryCode;
  19. };
  20. ConfigState config;
  21. std::shared_ptr<TimeProvider> timeProvider;
  22. std::shared_ptr<cspot::MercurySession> session;
  23. static std::shared_ptr<Context> createFromBlob(
  24. std::shared_ptr<LoginBlob> blob) {
  25. auto ctx = std::make_shared<Context>();
  26. ctx->timeProvider = std::make_shared<TimeProvider>();
  27. ctx->session = std::make_shared<MercurySession>(ctx->timeProvider);
  28. ctx->config.deviceId = blob->getDeviceId();
  29. ctx->config.deviceName = blob->getDeviceName();
  30. ctx->config.authData = blob->authData;
  31. ctx->config.volume = 0;
  32. ctx->config.username = blob->getUserName();
  33. return ctx;
  34. }
  35. };
  36. } // namespace cspot