1+ use async_trait:: async_trait;
12use livekit_token_source:: {
2- TokenSourceConfigurable , TokenSourceFetchOptions , TokenSourceFixed , TokenSourceResponse , TokenSourceResult
3+ TokenSourceConfigurable , TokenSourceFetchOptions , TokenSourceFixed , TokenSourceResponse ,
4+ TokenSourceResult ,
35} ;
4- use async_trait:: async_trait;
56
67/// An example for a custom token source that reads credentials from a JSON file, e.g.
78/// `{"server_url": "wss://...", "participant_token": "..."}`.
@@ -11,9 +12,7 @@ struct FileTokenSource {
1112
1213#[ async_trait]
1314impl TokenSourceFixed for FileTokenSource {
14- async fn fetch (
15- & self
16- ) -> TokenSourceResult < TokenSourceResponse > {
15+ async fn fetch ( & self ) -> TokenSourceResult < TokenSourceResponse > {
1716 let contents = std:: fs:: read_to_string ( & self . path ) . map_err ( serde_json:: Error :: io) ?;
1817 let response = serde_json:: from_str ( & contents) ?;
1918 Ok ( response)
@@ -23,10 +22,8 @@ impl TokenSourceFixed for FileTokenSource {
2322#[ tokio:: main]
2423async fn main ( ) {
2524 // A literal token source returns a fixed set of pre-provisioned credentials.
26- let literal = livekit_token_source:: literal (
27- "wss://example.livekit.cloud" ,
28- "<a pre-generated token>"
29- ) ;
25+ let literal =
26+ livekit_token_source:: literal ( "wss://example.livekit.cloud" , "<a pre-generated token>" ) ;
3027 match literal. fetch ( ) . await {
3128 Ok ( response) => println ! (
3229 "literal: server_url={} participant_token={}" ,
@@ -37,9 +34,8 @@ async fn main() {
3734
3835 // A custom token source can procure credentials from anywhere; this one
3936 // reads them from a JSON file next to this example's Cargo.toml.
40- let file_source = FileTokenSource {
41- path : concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/token.txt" ) . into ( ) ,
42- } ;
37+ let file_source =
38+ FileTokenSource { path : concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/token.txt" ) . into ( ) } ;
4339 match file_source. fetch ( ) . await {
4440 Ok ( response) => println ! (
4541 "file: server_url={} participant_token={}" ,
@@ -57,7 +53,8 @@ async fn main() {
5753 . with_participant_identity ( "example-user" ) ;
5854
5955 // Development token server: for prototyping only, NOT for production use.
60- let development_token_server = livekit_token_source:: development_token_server ( sandbox_id. clone ( ) ) ;
56+ let development_token_server =
57+ livekit_token_source:: development_token_server ( sandbox_id. clone ( ) ) ;
6158 match development_token_server. fetch ( & options) . await {
6259 Ok ( response) => println ! (
6360 "development token server: server_url={} participant_token={}" ,
@@ -69,8 +66,9 @@ async fn main() {
6966 // Endpoint: POSTs the fetch options to a token endpoint using the standard
7067 // format; here pointed at the same development token server.
7168 let endpoint = livekit_token_source:: endpoint (
72- "https://cloud-api.livekit.io/api/v2/sandbox/connection-details"
73- ) . with_header ( "X-Sandbox-ID" , sandbox_id) ;
69+ "https://cloud-api.livekit.io/api/v2/sandbox/connection-details" ,
70+ )
71+ . with_header ( "X-Sandbox-ID" , sandbox_id) ;
7472 match endpoint. fetch ( & options) . await {
7573 Ok ( response) => println ! (
7674 "endpoint: server_url={} participant_token={}" ,
0 commit comments