browser_commander/playwright/protocol/
android_socket.rs1#![allow(clippy::all, missing_docs, unused_imports)]
5
6use serde::{Deserialize, Serialize};
7
8use super::*;
9use crate::playwright::connection::{
10 Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
11};
12
13#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct AndroidSocketInitializer {}
16
17#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
19pub struct AndroidSocketWriteParams {
20 #[serde(rename = "data")]
21 pub data: Binary,
22}
23
24#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
26pub struct AndroidSocketDataEventParams {
27 #[serde(rename = "data")]
28 pub data: Binary,
29}
30
31#[derive(Debug, Clone, PartialEq)]
33pub enum AndroidSocketEvent {
34 Data(AndroidSocketDataEventParams),
36 Close,
38 Unknown {
40 method: String,
42 params: serde_json::Value,
44 },
45}
46
47impl ProtocolEvent for AndroidSocketEvent {
48 fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
49 match method {
50 "data" => Ok(Self::Data(serde_json::from_value(params)?)),
51 "close" => Ok(Self::Close),
52 _ => Ok(Self::Unknown { method: method.to_string(), params }),
53 }
54 }
55}
56
57#[derive(Debug, Clone)]
59pub struct AndroidSocket {
60 channel: Channel,
61}
62
63impl ChannelType for AndroidSocket {
64 const INTERFACE: &'static str = "AndroidSocket";
65 type Initializer = AndroidSocketInitializer;
66 type Event = AndroidSocketEvent;
67
68 fn accepts(interface: &str) -> bool {
69 matches!(interface, "AndroidSocket")
70 }
71
72 fn from_channel(channel: Channel) -> Self {
73 Self { channel }
74 }
75
76 fn channel(&self) -> &Channel {
77 &self.channel
78 }
79}
80
81impl AndroidSocket {
82 pub async fn write(&self, params: AndroidSocketWriteParams) -> Result<(), ProtocolError> {
84 self.channel.send_no_result("write", ¶ms).await
85 }
86
87 pub async fn close(&self) -> Result<(), ProtocolError> {
89 self.channel.send_no_result("close", &serde_json::json!({})).await
90 }
91}