From 1b962af925fad6fa04745ecc13ab00ff919182bc Mon Sep 17 00:00:00 2001 From: Neil Dwyer Date: Fri, 6 Sep 2024 10:33:38 -0700 Subject: [PATCH] Introduce participant kind --- livekit-ffi/protocol/participant.proto | 9 ++++++ livekit-ffi/src/conversion/participant.rs | 14 +++++++++ livekit-ffi/src/livekit.proto.rs | 37 +++++++++++++++++++++++ livekit/src/room/mod.rs | 2 +- livekit/src/room/participant/mod.rs | 1 + 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/livekit-ffi/protocol/participant.proto b/livekit-ffi/protocol/participant.proto index 2b8be7a86..a089d86e8 100644 --- a/livekit-ffi/protocol/participant.proto +++ b/livekit-ffi/protocol/participant.proto @@ -25,9 +25,18 @@ message ParticipantInfo { string identity = 3; string metadata = 4; map attributes = 5; + ParticipantKind kind = 6; } message OwnedParticipant { FfiOwnedHandle handle = 1; ParticipantInfo info = 2; +} + +enum ParticipantKind { + PARTICIPANT_KIND_STANDARD = 0; + PARTICIPANT_KIND_INGRESS = 1; + PARTICIPANT_KIND_EGRESS = 2; + PARTICIPANT_KIND_SIP = 3; + PARTICIPANT_KIND_AGENT = 4; } \ No newline at end of file diff --git a/livekit-ffi/src/conversion/participant.rs b/livekit-ffi/src/conversion/participant.rs index 4b1c04b86..f8041f8d7 100644 --- a/livekit-ffi/src/conversion/participant.rs +++ b/livekit-ffi/src/conversion/participant.rs @@ -13,6 +13,7 @@ // limitations under the License. use crate::{proto, server::room::FfiParticipant}; +use livekit::ParticipantKind; impl From<&FfiParticipant> for proto::ParticipantInfo { fn from(value: &FfiParticipant) -> Self { @@ -23,6 +24,19 @@ impl From<&FfiParticipant> for proto::ParticipantInfo { identity: participant.identity().into(), metadata: participant.metadata(), attributes: participant.attributes(), + kind: proto::ParticipantKind::from(participant.kind()).into(), + } + } +} + +impl From for proto::ParticipantKind { + fn from(kind: ParticipantKind) -> Self { + match kind { + ParticipantKind::Standard => proto::ParticipantKind::Standard, + ParticipantKind::Sip => proto::ParticipantKind::Sip, + ParticipantKind::Ingress => proto::ParticipantKind::Ingress, + ParticipantKind::Egress => proto::ParticipantKind::Egress, + ParticipantKind::Agent => proto::ParticipantKind::Agent, } } } diff --git a/livekit-ffi/src/livekit.proto.rs b/livekit-ffi/src/livekit.proto.rs index 38351d72a..18d3eb385 100644 --- a/livekit-ffi/src/livekit.proto.rs +++ b/livekit-ffi/src/livekit.proto.rs @@ -1542,6 +1542,8 @@ pub struct ParticipantInfo { pub metadata: ::prost::alloc::string::String, #[prost(map="string, string", tag="5")] pub attributes: ::std::collections::HashMap<::prost::alloc::string::String, ::prost::alloc::string::String>, + #[prost(enumeration="ParticipantKind", tag="6")] + pub kind: i32, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -1551,6 +1553,41 @@ pub struct OwnedParticipant { #[prost(message, optional, tag="2")] pub info: ::core::option::Option, } +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum ParticipantKind { + Standard = 0, + Ingress = 1, + Egress = 2, + Sip = 3, + Agent = 4, +} +impl ParticipantKind { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + ParticipantKind::Standard => "PARTICIPANT_KIND_STANDARD", + ParticipantKind::Ingress => "PARTICIPANT_KIND_INGRESS", + ParticipantKind::Egress => "PARTICIPANT_KIND_EGRESS", + ParticipantKind::Sip => "PARTICIPANT_KIND_SIP", + ParticipantKind::Agent => "PARTICIPANT_KIND_AGENT", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "PARTICIPANT_KIND_STANDARD" => Some(Self::Standard), + "PARTICIPANT_KIND_INGRESS" => Some(Self::Ingress), + "PARTICIPANT_KIND_EGRESS" => Some(Self::Egress), + "PARTICIPANT_KIND_SIP" => Some(Self::Sip), + "PARTICIPANT_KIND_AGENT" => Some(Self::Agent), + _ => None, + } + } +} /// Create a new VideoStream /// VideoStream is used to receive video frames from a track #[allow(clippy::derive_partial_eq_without_eq)] diff --git a/livekit/src/room/mod.rs b/livekit/src/room/mod.rs index a9bcb24d0..9b3e1bdc5 100644 --- a/livekit/src/room/mod.rs +++ b/livekit/src/room/mod.rs @@ -33,7 +33,7 @@ use proto::{promise::Promise, SignalTarget}; use thiserror::Error; use tokio::sync::{mpsc, oneshot, Mutex as AsyncMutex}; -use self::{ +pub use self::{ e2ee::{manager::E2eeManager, E2eeOptions}, participant::ParticipantKind, }; diff --git a/livekit/src/room/participant/mod.rs b/livekit/src/room/participant/mod.rs index d423ea295..c535111cf 100644 --- a/livekit/src/room/participant/mod.rs +++ b/livekit/src/room/participant/mod.rs @@ -61,6 +61,7 @@ impl Participant { pub fn is_speaking(self: &Self) -> bool; pub fn audio_level(self: &Self) -> f32; pub fn connection_quality(self: &Self) -> ConnectionQuality; + pub fn kind(self: &Self) -> ParticipantKind; pub(crate) fn update_info(self: &Self, info: proto::ParticipantInfo) -> ();