Include new Rust token source - #36
Conversation
104e7e0 to
86cc4b7
Compare
82dc6df to
c00f555
Compare
Sandbox id works, but no other fields possible yet Cargo changes for local dev Also have fields for all fetch options Some cleanup after CI complained Adapt to fetch options builder Using factory pattern Make cargo toml use real deps Needed for rebase Adapt to stream options builder API StreamTextOptions and StreamByteOptions no longer implement Default in the local rust-sdks checkout; construct them via new_with_topic and with_destination_identities instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Adapted to newest version Adjusted to basic factory constructor Working version matches Format check
344e61f to
9c3d871
Compare
1egoman
left a comment
There was a problem hiding this comment.
Generally looks good to me, called out a few nitpicks / small suggestions I think could make it a little more elegant!
| Auth::TokenSource { | ||
| token_server_id, | ||
| options, | ||
| } => { | ||
| let token_source = development_token_server(token_server_id); | ||
| let response = token_source | ||
| .fetch(options) | ||
| .await | ||
| .map_err(|e| e.to_string())?; | ||
| Ok((response.server_url, response.participant_token)) | ||
| } |
There was a problem hiding this comment.
nitpick: Maybe make it Auth::DevelopmentTokenServer or similar to line up with the token source type?
| token_server_id: String, | ||
| // Token-source fetch options (`ts_` to keep them apart from the API-key | ||
| // tab's identity/room). Empty means "omit, let the server default". | ||
| ts_room_name: String, | ||
| ts_participant_name: String, | ||
| ts_participant_identity: String, | ||
| ts_participant_metadata: String, | ||
| ts_agent_name: String, | ||
| ts_agent_metadata: String, | ||
| ts_agent_deployment: String, |
There was a problem hiding this comment.
suggestion: It might be good to refactor all these token source metadata fields into a nested struct rather than adding the ts_ prefix.
| method: AuthMethod::default(), | ||
| url: env_or("LIVEKIT_URL", "ws://localhost:7880"), | ||
| token: env_or("LIVEKIT_TOKEN", ""), | ||
| token_server_id: "token-server-id".to_string(), |
There was a problem hiding this comment.
question: Is this the right Default for this field? Or should it be an empty string?
| let mut options = TokenSourceFetchOptions::new(); | ||
| if let Some(v) = opt(&self.ts_room_name) { | ||
| options = options.with_room_name(v); | ||
| } | ||
| if let Some(v) = opt(&self.ts_participant_name) { | ||
| options = options.with_participant_name(v); | ||
| } | ||
| if let Some(v) = opt(&self.ts_participant_identity) { | ||
| options = options.with_participant_identity(v); | ||
| } | ||
| if let Some(v) = opt(&self.ts_participant_metadata) { | ||
| options = options.with_participant_metadata(v); | ||
| } | ||
| if let Some(v) = opt(&self.ts_agent_name) { | ||
| options = options.with_agent_name(v); | ||
| } | ||
| if let Some(v) = opt(&self.ts_agent_metadata) { |
There was a problem hiding this comment.
(note that if you namespaced all this ts_ stuff under a new struct type, then you could encapsulate all this code in a impl From<NewStruct> for TokenSourceFetchOptions which might be a little cleaner)
Co-authored-by: Ryan Gaus <rsg1egoman@gmail.com>
Adds a tab to the connection options: