bitwarden_shared_unlock/wasm/
peer.rs1use bitwarden_core::UserId;
2use bitwarden_threading::cancellation_token::wasm::{AbortController, AbortControllerExt};
3
4use super::drivers::{JsSharedUnlockDriver, RawJsSharedUnlockDriver};
5use crate::{DeviceEvent, PeerStartError, SharedUnlockClient, SharedUnlockPeer as Peer};
6
7#[bitwarden_ffi::wasm_object]
9pub struct SharedUnlockPeer {
10 peer: Peer<JsSharedUnlockDriver>,
11}
12
13#[bitwarden_ffi::wasm_export]
14impl SharedUnlockPeer {
15 #[wasm_bindgen(constructor)]
17 pub fn new(
18 ipc_client: &bitwarden_ipc::wasm::JsIpcClient,
19 driver: RawJsSharedUnlockDriver,
20 ) -> Self {
21 let driver = JsSharedUnlockDriver::new(driver);
22 let peer = Peer::create(driver, ipc_client.client.clone());
23 Self { peer }
24 }
25
26 #[wasm_bindgen]
28 pub fn set_destinations(&self, user_id: UserId, destinations: Vec<SharedUnlockClient>) {
29 self.peer.set_destinations(user_id, destinations);
30 }
31
32 #[wasm_bindgen]
34 pub async fn start(
35 &self,
36 abort_controller: Option<AbortController>,
37 ) -> Result<(), PeerStartError> {
38 self.peer
39 .start(abort_controller.map(|abort| abort.to_cancellation_token()))
40 .await
41 }
42
43 #[wasm_bindgen]
45 pub async fn handle_device_event(&self, event: DeviceEvent) {
46 if let Err(error) = self.peer.handle_device_event(event).await {
47 tracing::error!(?error, "Failed to handle shared unlock device event");
48 }
49 }
50}