summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/app.rs2
-rw-r--r--src/chat.rs24
-rw-r--r--src/main.rs4
3 files changed, 20 insertions, 10 deletions
diff --git a/src/app.rs b/src/app.rs
index e221a5d..8d694ef 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -37,7 +37,7 @@ impl History {
pub async fn run<T: ratatui::backend::Backend>(term: &mut Terminal<T>, args: crate::Args) -> Result<(), Box<dyn std::error::Error>> {
- let mut chat = Chat::register(&args.server).await?;
+ let mut chat = Chat::register(&args.server, args.token).await?;
let mut stream = crossterm::event::EventStream::new();
let mut input = String::new();
diff --git a/src/chat.rs b/src/chat.rs
index 7780b28..8a11ab4 100644
--- a/src/chat.rs
+++ b/src/chat.rs
@@ -55,15 +55,21 @@ pub struct Chat {
}
impl Chat {
- pub async fn register(server: &str) -> Result<Chat, ChatError> {
- let registration : RegisterResponse = reqwest::Client::new()
- .post(format!("https://{server}/api/chat/register"))
- .send()
- .await?
- .json()
- .await?;
-
- let ws_url = format!("wss://{server}/ws?accessToken={}", registration.access_token);
+ pub async fn register(server: &str, token: Option<String>) -> Result<Chat, ChatError> {
+ let token = match token {
+ Some(t) => t,
+ None => {
+ let registration : RegisterResponse = reqwest::Client::new()
+ .post(format!("https://{server}/api/chat/register"))
+ .send()
+ .await?
+ .json()
+ .await?;
+ registration.access_token
+ },
+ };
+
+ let ws_url = format!("wss://{server}/ws?accessToken={token}");
let (ws, _response) = tokio_tungstenite::connect_async(ws_url).await?;
diff --git a/src/main.rs b/src/main.rs
index d6d6039..226c214 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,6 +9,10 @@ mod proto;
struct Args {
/// owncast server to connect to
server: String,
+
+ /// access token to use for login
+ #[arg(long)]
+ token: Option<String>,
}
#[tokio::main(flavor = "current_thread")]