Skip to main content

bitwarden_ipc/wasm/
discover.rs

1use bitwarden_threading::cancellation_token::wasm::{AbortSignal, AbortSignalExt};
2
3use super::JsIpcClient;
4use crate::{
5    IpcClientExt, RequestError,
6    discover::{DiscoverHandler, DiscoverRequest, DiscoverResponse},
7    endpoint::Endpoint,
8};
9
10#[bitwarden_ffi::wasm_export(js_name = ipcRegisterDiscoverHandler)]
11/// Registers a DiscoverHandler so that the client can respond to DiscoverRequests.
12pub async fn ipc_register_discover_handler(ipc_client: &JsIpcClient, response: DiscoverResponse) {
13    ipc_client
14        .client
15        .register_rpc_handler(DiscoverHandler::new(response))
16        .await;
17}
18
19#[bitwarden_ffi::wasm_export(js_name = ipcRequestDiscover)]
20/// Sends a DiscoverRequest to the specified destination and returns the response.
21pub async fn ipc_request_discover(
22    ipc_client: &JsIpcClient,
23    destination: Endpoint,
24    abort_signal: Option<AbortSignal>,
25) -> Result<DiscoverResponse, RequestError> {
26    ipc_client
27        .client
28        .request(
29            DiscoverRequest,
30            destination,
31            abort_signal.map(|c| c.to_cancellation_token()),
32        )
33        .await
34}