use crate::errors::messaging_error::MessagingError;
use crate::errors::p2p_error::P2pError;
use crate::errors::sdk_error::SdkError;
use crate::event_handler::EventHandler;
use crate::{PlainText, Switchboard};
use std::sync::Arc;
use tokio::runtime::Runtime;
#[derive(uniffi::Object)]
pub struct SwitchboardWrapper {
inner: Arc<Switchboard>,
rt: Runtime,
}
#[uniffi::export]
impl SwitchboardWrapper {
#[uniffi::constructor]
pub fn new(switchboard: Arc<Switchboard>) -> Result<Self, SdkError> {
let rt = Runtime::new().or(Err(SdkError::CouldNotCreateRuntime))?;
Ok(Self {
inner: switchboard,
rt,
})
}
pub fn add_event_handler(&self, handler: Arc<dyn EventHandler>) {
self.rt
.block_on(async { self.inner.add_event_handler(handler) })
}
pub async fn invite(&self, email: &str) -> Result<(), SdkError> {
self.inner.invite(email).await
}
pub async fn get_session_id(&self) -> Result<String, MessagingError> {
self.inner.get_session_id().await
}
pub async fn send_text_message(&self, message: &PlainText) -> Result<(), MessagingError> {
self.inner.send_text_message(message).await
}
pub async fn send_nudge(&self) -> Result<(), MessagingError> {
self.inner.send_nudge().await
}
pub async fn send_typing_user(&self, email: &str) -> Result<(), MessagingError> {
self.inner.send_typing_user(email).await
}
pub async fn request_contact_display_picture(
&self,
email: &str,
msn_object: &str,
) -> Result<(), P2pError> {
self.rt.block_on(async {
self.inner
.request_contact_display_picture(email, msn_object)
.await
})
}
pub async fn disconnect(&self) -> Result<(), SdkError> {
self.inner.disconnect().await
}
}