cdp-driver 0.5.0

Chrome DevTools Protocol (CDP) client for Rust: every command, event and type generated from the schema, with sessions, for browser automation and AI agents
Documentation
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! This domain allows detailed inspection of media elements.
//!
//! Types, command parameters and event payloads for the `Media`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].
//!
//! This domain is experimental and may change without notice.

use serde::{Deserialize, Serialize};

/// Players will get an ID that is unique within the agent context.
pub type PlayerId = String;

pub type Timestamp = f64;

/// Have one type per entry in MediaLogRecord::Type Corresponds to kMessage
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlayerMessage {
    /// Keep in sync with MediaLogMessageLevel We are currently keeping the
    /// message level 'error' separate from the PlayerError type because right now
    /// they represent different things, this one being a DVLOG(ERROR) style log
    /// message that gets printed based on what log level is selected in the UI,
    /// and the other is a representation of a media::PipelineStatus object. Soon
    /// however we're going to be moving away from using PipelineStatus for errors
    /// and introducing a new error type which should hopefully let us integrate
    /// the error log level into the PlayerError type.
    pub level: PlayerMessageLevel,
    pub message: String,
}

/// The values `level` accepts on `PlayerMessage`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum PlayerMessageLevel {
    /// `error`
    #[serde(rename = "error")]
    Error,
    /// `warning`
    #[serde(rename = "warning")]
    Warning,
    /// `info`
    #[serde(rename = "info")]
    Info,
    /// `debug`
    #[serde(rename = "debug")]
    Debug,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// Corresponds to kMediaPropertyChange
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PlayerProperty {
    pub name: String,
    pub value: String,
}

/// Corresponds to kMediaEventTriggered
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PlayerEvent {
    pub timestamp: Timestamp,
    pub value: String,
}

/// Represents logged source line numbers reported in an error. NOTE: file and
/// line are from chromium c++ implementation code, not js.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PlayerErrorSourceLocation {
    pub file: String,
    pub line: i64,
}

/// Corresponds to kMediaError
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PlayerError {
    #[serde(rename = "errorType")]
    pub error_type: String,
    /// Code is the numeric enum entry for a specific set of error codes, such as
    /// PipelineStatusCodes in media/base/pipeline_status.h
    pub code: i64,
    /// A trace of where this error was caused / where it passed through.
    pub stack: Vec<PlayerErrorSourceLocation>,
    /// Errors potentially have a root cause error, ie, a DecoderError might be
    /// caused by an WindowsError
    pub cause: Vec<PlayerError>,
    /// Extra data attached to an error, such as an HRESULT, Video Codec, etc.
    pub data: serde_json::Value,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Player {
    #[serde(rename = "playerId")]
    pub player_id: PlayerId,
    #[serde(rename = "domNodeId", default, skip_serializing_if = "Option::is_none")]
    pub dom_node_id: Option<crate::protocol::dom::BackendNodeId>,
}

/// Enables the Media domain
///
/// Parameters of `Media.enable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EnableParams {}

impl crate::typed::Command for EnableParams {
    const METHOD: &'static str = "Media.enable";
    type Returns = crate::typed::NoReturns;
}

/// Disables the Media domain.
///
/// Parameters of `Media.disable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DisableParams {}

impl crate::typed::Command for DisableParams {
    const METHOD: &'static str = "Media.disable";
    type Returns = crate::typed::NoReturns;
}

/// This can be called multiple times, and can be used to set / override /
/// remove player properties. A null propValue indicates removal.
///
/// Payload of the `Media.playerPropertiesChanged` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PlayerPropertiesChangedEvent {
    #[serde(rename = "playerId")]
    pub player_id: PlayerId,
    pub properties: Vec<PlayerProperty>,
}

impl crate::typed::Event for PlayerPropertiesChangedEvent {
    const METHOD: &'static str = "Media.playerPropertiesChanged";
}

/// Send events as a list, allowing them to be batched on the browser for less
/// congestion. If batched, events must ALWAYS be in chronological order.
///
/// Payload of the `Media.playerEventsAdded` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PlayerEventsAddedEvent {
    #[serde(rename = "playerId")]
    pub player_id: PlayerId,
    pub events: Vec<PlayerEvent>,
}

impl crate::typed::Event for PlayerEventsAddedEvent {
    const METHOD: &'static str = "Media.playerEventsAdded";
}

/// Send a list of any messages that need to be delivered.
///
/// Payload of the `Media.playerMessagesLogged` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PlayerMessagesLoggedEvent {
    #[serde(rename = "playerId")]
    pub player_id: PlayerId,
    pub messages: Vec<PlayerMessage>,
}

impl crate::typed::Event for PlayerMessagesLoggedEvent {
    const METHOD: &'static str = "Media.playerMessagesLogged";
}

/// Send a list of any errors that need to be delivered.
///
/// Payload of the `Media.playerErrorsRaised` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PlayerErrorsRaisedEvent {
    #[serde(rename = "playerId")]
    pub player_id: PlayerId,
    pub errors: Vec<PlayerError>,
}

impl crate::typed::Event for PlayerErrorsRaisedEvent {
    const METHOD: &'static str = "Media.playerErrorsRaised";
}

/// Called whenever a player is created, or when a new agent joins and
/// receives a list of active players. If an agent is restored, it will
/// receive one event for each active player.
///
/// Payload of the `Media.playerCreated` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PlayerCreatedEvent {
    pub player: Player,
}

impl crate::typed::Event for PlayerCreatedEvent {
    const METHOD: &'static str = "Media.playerCreated";
}