browser_commander/puppeteer/api/
common_event_emitter.rs1#![allow(clippy::all, missing_docs, unused_imports, non_snake_case)]
5
6use serde_json::Value;
7
8use super::*;
9use crate::puppeteer::bridge::{binary, remote_type, BridgeError, JsFunction, Remote};
10
11remote_type!(
12 CommonEventEmitter
15);
16
17impl CommonEventEmitter {
18 pub async fn on(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<CommonEventEmitter, BridgeError> {
24 self.remote.call("on", vec![Some(type_), Some(handler.into().to_wire())]).await
25 }
26
27 pub async fn off(&self, type_: Value, handler: Option<JsFunction>) -> Result<CommonEventEmitter, BridgeError> {
33 self.remote.call("off", vec![Some(type_), handler.map(|x| x.to_wire())]).await
34 }
35
36 pub async fn emit(&self, type_: Value, event: Value) -> Result<bool, BridgeError> {
42 self.remote.call("emit", vec![Some(type_), Some(event)]).await
43 }
44
45 pub async fn once(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<CommonEventEmitter, BridgeError> {
51 self.remote.call("once", vec![Some(type_), Some(handler.into().to_wire())]).await
52 }
53
54 pub async fn listener_count(&self, event: Value) -> Result<f64, BridgeError> {
60 self.remote.call("listenerCount", vec![Some(event)]).await
61 }
62
63 pub async fn remove_all_listeners(&self, event: Option<Value>) -> Result<CommonEventEmitter, BridgeError> {
69 self.remote.call("removeAllListeners", vec![event]).await
70 }
71}