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] `Sink`: `write()` now receives ownership of the packet (breaking).
|
||||||
- [playback] `pipe`: create file if it doesn't already exist
|
- [playback] `pipe`: create file if it doesn't already exist
|
||||||
- [playback] More robust dynamic limiter for very wide dynamic range (breaking)
|
- [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.
|
- [build] The MSRV is now 1.53.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -66,7 +66,8 @@ impl Session {
|
||||||
config: SessionConfig,
|
config: SessionConfig,
|
||||||
credentials: Credentials,
|
credentials: Credentials,
|
||||||
cache: Option<Cache>,
|
cache: Option<Cache>,
|
||||||
) -> Result<Session, SessionError> {
|
store_credentials: bool,
|
||||||
|
) -> Result<(Session, Credentials), SessionError> {
|
||||||
let ap = apresolve(config.proxy.as_ref(), config.ap_port).await;
|
let ap = apresolve(config.proxy.as_ref(), config.ap_port).await;
|
||||||
|
|
||||||
info!("Connecting to AP \"{}\"", ap);
|
info!("Connecting to AP \"{}\"", ap);
|
||||||
|
@ -76,18 +77,20 @@ impl Session {
|
||||||
connection::authenticate(&mut conn, credentials, &config.device_id).await?;
|
connection::authenticate(&mut conn, credentials, &config.device_id).await?;
|
||||||
info!("Authenticated as \"{}\" !", reusable_credentials.username);
|
info!("Authenticated as \"{}\" !", reusable_credentials.username);
|
||||||
if let Some(cache) = &cache {
|
if let Some(cache) = &cache {
|
||||||
cache.save_credentials(&reusable_credentials);
|
if store_credentials {
|
||||||
|
cache.save_credentials(&reusable_credentials);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let session = Session::create(
|
let session = Session::create(
|
||||||
conn,
|
conn,
|
||||||
config,
|
config,
|
||||||
cache,
|
cache,
|
||||||
reusable_credentials.username,
|
reusable_credentials.username.clone(),
|
||||||
tokio::runtime::Handle::current(),
|
tokio::runtime::Handle::current(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(session)
|
Ok((session, reusable_credentials))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create(
|
fn create(
|
||||||
|
|
|
@ -13,6 +13,7 @@ async fn test_connection() {
|
||||||
SessionConfig::default(),
|
SessionConfig::default(),
|
||||||
Credentials::with_password("test", "test"),
|
Credentials::with_password("test", "test"),
|
||||||
None,
|
None,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ async fn main() {
|
||||||
|
|
||||||
println!("Connecting..");
|
println!("Connecting..");
|
||||||
let credentials = Credentials::with_password(&args[1], &args[2]);
|
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
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ async fn main() {
|
||||||
let backend = audio_backend::find(None).unwrap();
|
let backend = audio_backend::find(None).unwrap();
|
||||||
|
|
||||||
println!("Connecting ..");
|
println!("Connecting ..");
|
||||||
let session = Session::connect(session_config, credentials, None)
|
let (session, _) = Session::connect(session_config, credentials, None, false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ async fn main() {
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
let session = Session::connect(session_config, credentials, None)
|
let (session, _) = Session::connect(session_config, credentials, None, false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -1599,6 +1599,7 @@ async fn main() {
|
||||||
setup.session_config.clone(),
|
setup.session_config.clone(),
|
||||||
credentials,
|
credentials,
|
||||||
setup.cache.clone(),
|
setup.cache.clone(),
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
.fuse(),
|
.fuse(),
|
||||||
);
|
);
|
||||||
|
@ -1634,6 +1635,7 @@ async fn main() {
|
||||||
setup.session_config.clone(),
|
setup.session_config.clone(),
|
||||||
credentials,
|
credentials,
|
||||||
setup.cache.clone(),
|
setup.cache.clone(),
|
||||||
|
true,
|
||||||
).fuse());
|
).fuse());
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
|
@ -1643,7 +1645,7 @@ async fn main() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
session = &mut connecting, if !connecting.is_terminated() => match session {
|
session = &mut connecting, if !connecting.is_terminated() => match session {
|
||||||
Ok(session) => {
|
Ok((session,_)) => {
|
||||||
let mixer_config = setup.mixer_config.clone();
|
let mixer_config = setup.mixer_config.clone();
|
||||||
let mixer = (setup.mixer)(mixer_config);
|
let mixer = (setup.mixer)(mixer_config);
|
||||||
let player_config = setup.player_config.clone();
|
let player_config = setup.player_config.clone();
|
||||||
|
@ -1711,6 +1713,7 @@ async fn main() {
|
||||||
setup.session_config.clone(),
|
setup.session_config.clone(),
|
||||||
credentials,
|
credentials,
|
||||||
setup.cache.clone(),
|
setup.cache.clone(),
|
||||||
|
true
|
||||||
).fuse());
|
).fuse());
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
|
Loading…
Reference in a new issue