bitwarden_ipc/wasm/
discover.rs

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