1use crate::{proto, token};
2use anyhow::{anyhow, Result};
3use hyper::{client::HttpConnector, header::AUTHORIZATION, Method, Request, Uri};
4use std::future::Future;
5
6pub struct Client {
7 http: hyper::Client<HttpConnector>,
8 uri: Uri,
9 key: String,
10 secret: String,
11}
12
13impl Client {
14 pub fn new(uri: Uri, key: String, secret: String) -> Self {
15 assert!(uri.scheme().is_some(), "base uri must have a scheme");
16 assert!(uri.authority().is_some(), "base uri must have an authority");
17 Self {
18 http: hyper::Client::new(),
19 uri,
20 key,
21 secret,
22 }
23 }
24
25 pub fn create_room(&self, name: String) -> impl Future<Output = Result<proto::Room>> {
26 let token = token::create(
27 &self.key,
28 &self.secret,
29 None,
30 token::VideoGrant {
31 room_create: Some(true),
32 ..Default::default()
33 },
34 );
35
36 let client = self.http.clone();
37 let uri = Uri::builder()
38 .scheme(self.uri.scheme().unwrap().clone())
39 .authority(self.uri.authority().unwrap().clone())
40 .path_and_query("twirp/livekit.RoomService/CreateRoom")
41 .build();
42 async move {
43 let token = token?;
44 let uri = uri?;
45 let body = proto::CreateRoomRequest {
46 name: todo!(),
47 empty_timeout: todo!(),
48 max_participants: todo!(),
49 node_id: todo!(),
50 metadata: todo!(),
51 egress: todo!(),
52 };
53 let mut request = Request::builder()
54 .uri(uri)
55 .method(Method::POST)
56 .header(AUTHORIZATION, format!("Bearer {}", token))
57 .body(body);
58 Err(anyhow!("yeah"))
59 }
60 }
61}