browser-commander 0.18.0

Universal browser automation library that supports multiple browser engines with a unified API
Documentation
// @generated by scripts/generate-playwright-protocol.mjs from
// rust/protocol/playwright/*.yml. Do not edit by hand.

#![allow(clippy::all, missing_docs, unused_imports)]

use serde::{Deserialize, Serialize};

use super::*;
use crate::playwright::connection::{
    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
};

/// Initializer the driver sends when it creates a `SocksSupport`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportInitializer {}

/// Parameters of `SocksSupport.socksConnected`.
#[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,
}

/// Parameters of `SocksSupport.socksFailed`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksFailedParams {
    #[serde(rename = "uid")]
    pub uid: String,
    #[serde(rename = "errorCode")]
    pub error_code: String,
}

/// Parameters of `SocksSupport.socksData`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksDataParams {
    #[serde(rename = "uid")]
    pub uid: String,
    #[serde(rename = "data")]
    pub data: Binary,
}

/// Parameters of `SocksSupport.socksError`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksErrorParams {
    #[serde(rename = "uid")]
    pub uid: String,
    #[serde(rename = "error")]
    pub error: String,
}

/// Parameters of `SocksSupport.socksEnd`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksEndParams {
    #[serde(rename = "uid")]
    pub uid: String,
}

/// Payload of the `SocksSupport.socksRequested` event.
#[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,
}

/// Payload of the `SocksSupport.socksData` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksDataEventParams {
    #[serde(rename = "uid")]
    pub uid: String,
    #[serde(rename = "data")]
    pub data: Binary,
}

/// Payload of the `SocksSupport.socksClosed` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SocksSupportSocksClosedEventParams {
    #[serde(rename = "uid")]
    pub uid: String,
}

/// Events a `SocksSupport` channel can emit.
#[derive(Debug, Clone, PartialEq)]
pub enum SocksSupportEvent {
    /// `SocksSupport.socksRequested`
    SocksRequested(SocksSupportSocksRequestedEventParams),
    /// `SocksSupport.socksData`
    SocksData(SocksSupportSocksDataEventParams),
    /// `SocksSupport.socksClosed`
    SocksClosed(SocksSupportSocksClosedEventParams),
    /// An event this binding does not know (a newer driver).
    Unknown {
        /// Event name.
        method: String,
        /// Raw event parameters.
        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 }),
        }
    }
}

/// Channel for the `SocksSupport` interface (`playwright.yml`).
#[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 {
    /// `SocksSupport.socksConnected` (internal).
    pub async fn socks_connected(&self, params: SocksSupportSocksConnectedParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("socksConnected", &params).await
    }

    /// `SocksSupport.socksFailed` (internal).
    pub async fn socks_failed(&self, params: SocksSupportSocksFailedParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("socksFailed", &params).await
    }

    /// `SocksSupport.socksData` (internal).
    pub async fn socks_data(&self, params: SocksSupportSocksDataParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("socksData", &params).await
    }

    /// `SocksSupport.socksError` (internal).
    pub async fn socks_error(&self, params: SocksSupportSocksErrorParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("socksError", &params).await
    }

    /// `SocksSupport.socksEnd` (internal).
    pub async fn socks_end(&self, params: SocksSupportSocksEndParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("socksEnd", &params).await
    }
}