bitwarden_shared_unlock/wasm/
follower.rs1use bitwarden_threading::cancellation_token::wasm::{AbortController, AbortControllerExt};
2use wasm_bindgen::prelude::wasm_bindgen;
3
4use super::drivers::{JsSharedUnlockDriver, RawJsSharedUnlockDriver};
5use crate::{DeviceEvent, Follower, FollowerStartError};
6
7#[wasm_bindgen]
9pub struct SharedUnlockFollower {
10 follower: Follower<JsSharedUnlockDriver>,
11}
12
13#[wasm_bindgen]
14impl SharedUnlockFollower {
15 #[wasm_bindgen]
17 pub fn try_new(
18 ipc_client: &bitwarden_ipc::wasm::JsIpcClient,
19 driver: RawJsSharedUnlockDriver,
20 ) -> Result<Self, bitwarden_ipc::SubscribeError> {
21 let driver = JsSharedUnlockDriver::new(driver);
22 let follower = Follower::create(driver, ipc_client.client.clone());
23 Ok(Self { follower })
24 }
25
26 #[wasm_bindgen]
30 pub async fn start(
31 &self,
32 abort_controller: Option<AbortController>,
33 ) -> Result<(), FollowerStartError> {
34 self.follower
35 .start(abort_controller.map(|abort| abort.to_cancellation_token()))
36 .await
37 }
38
39 #[wasm_bindgen]
41 pub async fn handle_device_event(&self, event: DeviceEvent) {
42 if let Err(error) = self.follower.handle_device_event(event).await {
43 tracing::error!(
44 ?error,
45 "Failed to handle shared unlock follower device event"
46 );
47 }
48 }
49}