Skip to content

Commit

Permalink
livekit: expose ParticipantKind
Browse files Browse the repository at this point in the history
  • Loading branch information
nbsp authored Aug 2, 2024
1 parent 8045919 commit 21c98c5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
12 changes: 12 additions & 0 deletions livekit/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,15 @@ impl From<EncryptionType> for encryption::Type {
}
}
}

impl From<participant_info::Kind> for participant::ParticipantKind {
fn from(value: participant_info::Kind) -> Self {
match value {
participant_info::Kind::Standard => participant::ParticipantKind::Standard,
participant_info::Kind::Ingress => participant::ParticipantKind::Ingress,
participant_info::Kind::Egress => participant::ParticipantKind::Egress,
participant_info::Kind::Sip => participant::ParticipantKind::Sip,
participant_info::Kind::Agent => participant::ParticipantKind::Agent,
}
}
}
10 changes: 9 additions & 1 deletion livekit/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ use proto::{promise::Promise, SignalTarget};
use thiserror::Error;
use tokio::sync::{mpsc, oneshot, Mutex as AsyncMutex};

use self::e2ee::{manager::E2eeManager, E2eeOptions};
use self::{
e2ee::{manager::E2eeManager, E2eeOptions},
participant::ParticipantKind,
};
pub use crate::rtc_engine::SimulateScenario;
use crate::{
participant::ConnectionQuality,
Expand Down Expand Up @@ -331,6 +334,7 @@ impl Room {
let pi = join_response.participant.unwrap();
let local_participant = LocalParticipant::new(
rtc_engine.clone(),
pi.kind().into(),
pi.sid.try_into().unwrap(),
pi.identity.into(),
pi.name,
Expand Down Expand Up @@ -458,6 +462,7 @@ impl Room {
let participant = {
let pi = pi.clone();
inner.create_participant(
pi.kind().into(),
pi.sid.try_into().unwrap(),
pi.identity.into(),
pi.name,
Expand Down Expand Up @@ -680,6 +685,7 @@ impl RoomSession {
let remote_participant = {
let pi = pi.clone();
self.create_participant(
pi.kind().into(),
pi.sid.try_into().unwrap(),
pi.identity.into(),
pi.name,
Expand Down Expand Up @@ -1087,6 +1093,7 @@ impl RoomSession {
/// Also add it to the participants list
fn create_participant(
self: &Arc<Self>,
kind: ParticipantKind,
sid: ParticipantSid,
identity: ParticipantIdentity,
name: String,
Expand All @@ -1095,6 +1102,7 @@ impl RoomSession {
) -> RemoteParticipant {
let participant = RemoteParticipant::new(
self.rtc_engine.clone(),
kind,
sid.clone(),
identity.clone(),
name,
Expand Down
9 changes: 7 additions & 2 deletions livekit/src/room/participant/local_participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use libwebrtc::rtp_parameters::RtpEncodingParameters;
use livekit_protocol as proto;
use parking_lot::Mutex;

use super::{ConnectionQuality, ParticipantInner};
use super::{ConnectionQuality, ParticipantInner, ParticipantKind};
use crate::{
e2ee::EncryptionType,
options,
Expand Down Expand Up @@ -65,6 +65,7 @@ impl Debug for LocalParticipant {
impl LocalParticipant {
pub(crate) fn new(
rtc_engine: Arc<RtcEngine>,
kind: ParticipantKind,
sid: ParticipantSid,
identity: ParticipantIdentity,
name: String,
Expand All @@ -73,7 +74,7 @@ impl LocalParticipant {
encryption_type: EncryptionType,
) -> Self {
Self {
inner: super::new_inner(rtc_engine, sid, identity, name, metadata, attributes),
inner: super::new_inner(rtc_engine, sid, identity, name, metadata, attributes, kind),
local: Arc::new(LocalInfo { events: LocalEvents::default(), encryption_type }),
}
}
Expand Down Expand Up @@ -434,4 +435,8 @@ impl LocalParticipant {
pub fn connection_quality(&self) -> ConnectionQuality {
self.inner.info.read().connection_quality
}

pub fn kind(&self) -> ParticipantKind {
self.inner.info.read().kind
}
}
13 changes: 13 additions & 0 deletions livekit/src/room/participant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ pub enum ConnectionQuality {
Lost,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum ParticipantKind {
Standard,
Ingress,
Egress,
Sip,
Agent,
}

#[derive(Debug, Clone)]
pub enum Participant {
Local(LocalParticipant),
Expand Down Expand Up @@ -80,6 +89,7 @@ struct ParticipantInfo {
pub speaking: bool,
pub audio_level: f32,
pub connection_quality: ConnectionQuality,
pub kind: ParticipantKind,
}

type TrackMutedHandler = Box<dyn Fn(Participant, TrackPublication) + Send>;
Expand Down Expand Up @@ -111,6 +121,7 @@ pub(super) fn new_inner(
name: String,
metadata: String,
attributes: HashMap<String, String>,
kind: ParticipantKind,
) -> Arc<ParticipantInner> {
Arc::new(ParticipantInner {
rtc_engine,
Expand All @@ -120,6 +131,7 @@ pub(super) fn new_inner(
name,
metadata,
attributes,
kind,
speaking: false,
audio_level: 0.0,
connection_quality: ConnectionQuality::Excellent,
Expand All @@ -135,6 +147,7 @@ pub(super) fn update_info(
new_info: proto::ParticipantInfo,
) {
let mut info = inner.info.write();
info.kind = new_info.kind().into();
info.sid = new_info.sid.try_into().unwrap();
info.identity = new_info.identity.into();

Expand Down
9 changes: 7 additions & 2 deletions livekit/src/room/participant/remote_participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use livekit_protocol as proto;
use livekit_runtime::timeout;
use parking_lot::Mutex;

use super::{ConnectionQuality, ParticipantInner, TrackKind};
use super::{ConnectionQuality, ParticipantInner, ParticipantKind, TrackKind};
use crate::{prelude::*, rtc_engine::RtcEngine, track::TrackError};

const ADD_TRACK_TIMEOUT: Duration = Duration::from_secs(5);
Expand Down Expand Up @@ -70,6 +70,7 @@ impl Debug for RemoteParticipant {
impl RemoteParticipant {
pub(crate) fn new(
rtc_engine: Arc<RtcEngine>,
kind: ParticipantKind,
sid: ParticipantSid,
identity: ParticipantIdentity,
name: String,
Expand All @@ -78,7 +79,7 @@ impl RemoteParticipant {
auto_subscribe: bool,
) -> Self {
Self {
inner: super::new_inner(rtc_engine, sid, identity, name, metadata, attributes),
inner: super::new_inner(rtc_engine, sid, identity, name, metadata, attributes, kind),
remote: Arc::new(RemoteInfo { events: Default::default(), auto_subscribe }),
}
}
Expand Down Expand Up @@ -458,4 +459,8 @@ impl RemoteParticipant {
pub fn connection_quality(&self) -> ConnectionQuality {
self.inner.info.read().connection_quality
}

pub fn kind(&self) -> ParticipantKind {
self.inner.info.read().kind
}
}

0 comments on commit 21c98c5

Please sign in to comment.