codemp/src/ffi/js/client.rs

37 lines
1.1 KiB
Rust
Raw Normal View History

2024-03-10 12:42:56 +01:00
use napi_derive::napi;
use crate::prelude::*;
2024-03-10 12:42:56 +01:00
#[napi]
/// connect to codemp servers and return a client session
pub async fn connect(addr: Option<String>, username: String, password: String) -> napi::Result<CodempClient>{
let client = crate::Client::new(addr.as_deref().unwrap_or("http://codemp.alemi.dev:50053"), username, password)
.await?;
2024-03-10 12:42:56 +01:00
Ok(client)
2024-03-10 12:42:56 +01:00
}
#[napi]
impl CodempClient {
#[napi(js_name = "join_workspace")]
2024-03-10 12:42:56 +01:00
/// join workspace with given id (will start its cursor controller)
pub async fn js_join_workspace(&self, workspace: String) -> napi::Result<CodempWorkspace> {
Ok(self.join_workspace(workspace).await?)
2024-03-10 12:42:56 +01:00
}
#[napi(js_name = "get_workspace")]
2024-03-10 12:42:56 +01:00
/// get workspace with given id, if it exists
pub fn js_get_workspace(&self, workspace: String) -> Option<CodempWorkspace> {
self.get_workspace(&workspace)
2024-03-10 12:42:56 +01:00
}
#[napi(js_name = "user_id")]
2024-03-10 12:42:56 +01:00
/// return current sessions's user id
pub fn js_user_id(&self) -> String {
self.user_id().to_string()
}
#[napi(js_name = "active_workspaces")]
pub fn js_active_workspaces(&self) -> Vec<String> {
self.active_workspaces()
2024-03-10 12:42:56 +01:00
}
}