#![allow(clippy::all, missing_docs, unused_imports)]
use serde::{Deserialize, Serialize};
use super::*;
use crate::playwright::connection::{
Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
};
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportInitializer {}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksConnectedParams {
#[serde(rename = "uid")]
pub uid: String,
#[serde(rename = "host")]
pub host: String,
#[serde(rename = "port")]
pub port: i64,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksFailedParams {
#[serde(rename = "uid")]
pub uid: String,
#[serde(rename = "errorCode")]
pub error_code: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksDataParams {
#[serde(rename = "uid")]
pub uid: String,
#[serde(rename = "data")]
pub data: Binary,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksErrorParams {
#[serde(rename = "uid")]
pub uid: String,
#[serde(rename = "error")]
pub error: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksEndParams {
#[serde(rename = "uid")]
pub uid: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksRequestedEventParams {
#[serde(rename = "uid")]
pub uid: String,
#[serde(rename = "host")]
pub host: String,
#[serde(rename = "port")]
pub port: i64,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksDataEventParams {
#[serde(rename = "uid")]
pub uid: String,
#[serde(rename = "data")]
pub data: Binary,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksClosedEventParams {
#[serde(rename = "uid")]
pub uid: String,
}
#[derive(Debug, Clone, PartialEq)]
pub enum SocksSupportEvent {
SocksRequested(SocksSupportSocksRequestedEventParams),
SocksData(SocksSupportSocksDataEventParams),
SocksClosed(SocksSupportSocksClosedEventParams),
Unknown {
method: String,
params: serde_json::Value,
},
}
impl ProtocolEvent for SocksSupportEvent {
fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
match method {
"socksRequested" => Ok(Self::SocksRequested(serde_json::from_value(params)?)),
"socksData" => Ok(Self::SocksData(serde_json::from_value(params)?)),
"socksClosed" => Ok(Self::SocksClosed(serde_json::from_value(params)?)),
_ => Ok(Self::Unknown { method: method.to_string(), params }),
}
}
}
#[derive(Debug, Clone)]
pub struct SocksSupport {
channel: Channel,
}
impl ChannelType for SocksSupport {
const INTERFACE: &'static str = "SocksSupport";
type Initializer = SocksSupportInitializer;
type Event = SocksSupportEvent;
fn accepts(interface: &str) -> bool {
matches!(interface, "SocksSupport")
}
fn from_channel(channel: Channel) -> Self {
Self { channel }
}
fn channel(&self) -> &Channel {
&self.channel
}
}
impl SocksSupport {
pub async fn socks_connected(&self, params: SocksSupportSocksConnectedParams) -> Result<(), ProtocolError> {
self.channel.send_no_result("socksConnected", ¶ms).await
}
pub async fn socks_failed(&self, params: SocksSupportSocksFailedParams) -> Result<(), ProtocolError> {
self.channel.send_no_result("socksFailed", ¶ms).await
}
pub async fn socks_data(&self, params: SocksSupportSocksDataParams) -> Result<(), ProtocolError> {
self.channel.send_no_result("socksData", ¶ms).await
}
pub async fn socks_error(&self, params: SocksSupportSocksErrorParams) -> Result<(), ProtocolError> {
self.channel.send_no_result("socksError", ¶ms).await
}
pub async fn socks_end(&self, params: SocksSupportSocksEndParams) -> Result<(), ProtocolError> {
self.channel.send_no_result("socksEnd", ¶ms).await
}
}