mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 13:07:03 +03:00
new cspot/bell
This commit is contained in:
@@ -3,29 +3,41 @@
|
||||
#include <functional> // for function
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include <atomic>
|
||||
|
||||
namespace bell {
|
||||
class WrappedSemaphore;
|
||||
};
|
||||
namespace cspot {
|
||||
struct Context;
|
||||
|
||||
class AccessKeyFetcher {
|
||||
public:
|
||||
AccessKeyFetcher(std::shared_ptr<cspot::Context> ctx);
|
||||
~AccessKeyFetcher();
|
||||
|
||||
typedef std::function<void(std::string)> Callback;
|
||||
/**
|
||||
* @brief Checks if key is expired
|
||||
* @returns true when currently held access key is not valid
|
||||
*/
|
||||
bool isExpired();
|
||||
|
||||
void getAccessKey(Callback callback);
|
||||
/**
|
||||
* @brief Fetches a new access key
|
||||
* @remark In case the key is expired, this function blocks until a refresh is done.
|
||||
* @returns access key
|
||||
*/
|
||||
std::string getAccessKey();
|
||||
|
||||
/**
|
||||
* @brief Forces a refresh of the access key
|
||||
*/
|
||||
void updateAccessKey();
|
||||
|
||||
private:
|
||||
const std::string CLIENT_ID =
|
||||
"65b708073fc0480ea92a077233ca87bd"; // Spotify web client's client id
|
||||
const std::string SCOPES =
|
||||
"streaming,user-library-read,user-library-modify,user-top-read,user-read-"
|
||||
"recently-played"; // Required access scopes
|
||||
|
||||
std::shared_ptr<cspot::Context> ctx;
|
||||
std::shared_ptr<bell::WrappedSemaphore> updateSemaphore;
|
||||
|
||||
bool isExpired();
|
||||
std::atomic<bool> keyPending = false;
|
||||
std::string accessKey;
|
||||
long long int expiresAt;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user