mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
adding callback for reusable credentials (#983)
This allows more control over how the credentials are saved to the cache
This commit is contained in:
parent
1efda79787
commit
6c2491b9a3
7 changed files with 17 additions and 8 deletions
|
@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- [playback] `Sink`: `write()` now receives ownership of the packet (breaking).
|
||||
- [playback] `pipe`: create file if it doesn't already exist
|
||||
- [playback] More robust dynamic limiter for very wide dynamic range (breaking)
|
||||
- [core] `Session`: `connect()` now returns the long-term credentials.
|
||||
- [core] `Session`: `connect()` now accespt a flag if the credentails should be stored via the cache.
|
||||
- [build] The MSRV is now 1.53.
|
||||
|
||||
### Added
|
||||
|
|
|
@ -66,7 +66,8 @@ impl Session {
|
|||
config: SessionConfig,
|
||||
credentials: Credentials,
|
||||
cache: Option<Cache>,
|
||||
) -> Result<Session, SessionError> {
|
||||
store_credentials: bool,
|
||||
) -> Result<(Session, Credentials), SessionError> {
|
||||
let ap = apresolve(config.proxy.as_ref(), config.ap_port).await;
|
||||
|
||||
info!("Connecting to AP \"{}\"", ap);
|
||||
|
@ -76,18 +77,20 @@ impl Session {
|
|||
connection::authenticate(&mut conn, credentials, &config.device_id).await?;
|
||||
info!("Authenticated as \"{}\" !", reusable_credentials.username);
|
||||
if let Some(cache) = &cache {
|
||||
if store_credentials {
|
||||
cache.save_credentials(&reusable_credentials);
|
||||
}
|
||||
}
|
||||
|
||||
let session = Session::create(
|
||||
conn,
|
||||
config,
|
||||
cache,
|
||||
reusable_credentials.username,
|
||||
reusable_credentials.username.clone(),
|
||||
tokio::runtime::Handle::current(),
|
||||
);
|
||||
|
||||
Ok(session)
|
||||
Ok((session, reusable_credentials))
|
||||
}
|
||||
|
||||
fn create(
|
||||
|
|
|
@ -13,6 +13,7 @@ async fn test_connection() {
|
|||
SessionConfig::default(),
|
||||
Credentials::with_password("test", "test"),
|
||||
None,
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ async fn main() {
|
|||
|
||||
println!("Connecting..");
|
||||
let credentials = Credentials::with_password(&args[1], &args[2]);
|
||||
let session = Session::connect(session_config, credentials, None)
|
||||
let (session, _) = Session::connect(session_config, credentials, None, false)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ async fn main() {
|
|||
let backend = audio_backend::find(None).unwrap();
|
||||
|
||||
println!("Connecting ..");
|
||||
let session = Session::connect(session_config, credentials, None)
|
||||
let (session, _) = Session::connect(session_config, credentials, None, false)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ async fn main() {
|
|||
process::exit(1);
|
||||
});
|
||||
|
||||
let session = Session::connect(session_config, credentials, None)
|
||||
let (session, _) = Session::connect(session_config, credentials, None, false)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -1599,6 +1599,7 @@ async fn main() {
|
|||
setup.session_config.clone(),
|
||||
credentials,
|
||||
setup.cache.clone(),
|
||||
true,
|
||||
)
|
||||
.fuse(),
|
||||
);
|
||||
|
@ -1634,6 +1635,7 @@ async fn main() {
|
|||
setup.session_config.clone(),
|
||||
credentials,
|
||||
setup.cache.clone(),
|
||||
true,
|
||||
).fuse());
|
||||
},
|
||||
None => {
|
||||
|
@ -1643,7 +1645,7 @@ async fn main() {
|
|||
}
|
||||
},
|
||||
session = &mut connecting, if !connecting.is_terminated() => match session {
|
||||
Ok(session) => {
|
||||
Ok((session,_)) => {
|
||||
let mixer_config = setup.mixer_config.clone();
|
||||
let mixer = (setup.mixer)(mixer_config);
|
||||
let player_config = setup.player_config.clone();
|
||||
|
@ -1711,6 +1713,7 @@ async fn main() {
|
|||
setup.session_config.clone(),
|
||||
credentials,
|
||||
setup.cache.clone(),
|
||||
true
|
||||
).fuse());
|
||||
},
|
||||
_ => {
|
||||
|
|
Loading…
Reference in a new issue