lib.rs

  1use collections::HashMap;
  2
  3mod remote_video_track_view;
  4pub use remote_video_track_view::{RemoteVideoTrackView, RemoteVideoTrackViewEvent};
  5
  6#[cfg(not(any(test, feature = "test-support", target_os = "freebsd")))]
  7mod livekit_client;
  8#[cfg(not(any(test, feature = "test-support", target_os = "freebsd")))]
  9pub use livekit_client::*;
 10
 11#[cfg(any(test, feature = "test-support", target_os = "freebsd"))]
 12mod mock_client;
 13#[cfg(any(test, feature = "test-support", target_os = "freebsd"))]
 14pub mod test;
 15#[cfg(any(test, feature = "test-support", target_os = "freebsd"))]
 16pub use mock_client::*;
 17
 18#[derive(Debug, Clone)]
 19pub enum Participant {
 20    Local(LocalParticipant),
 21    Remote(RemoteParticipant),
 22}
 23
 24#[derive(Debug, Clone)]
 25pub enum TrackPublication {
 26    Local(LocalTrackPublication),
 27    Remote(RemoteTrackPublication),
 28}
 29
 30impl TrackPublication {
 31    pub fn sid(&self) -> TrackSid {
 32        match self {
 33            TrackPublication::Local(local) => local.sid(),
 34            TrackPublication::Remote(remote) => remote.sid(),
 35        }
 36    }
 37
 38    pub fn is_muted(&self) -> bool {
 39        match self {
 40            TrackPublication::Local(local) => local.is_muted(),
 41            TrackPublication::Remote(remote) => remote.is_muted(),
 42        }
 43    }
 44}
 45
 46#[derive(Clone, Debug)]
 47pub enum RemoteTrack {
 48    Audio(RemoteAudioTrack),
 49    Video(RemoteVideoTrack),
 50}
 51
 52impl RemoteTrack {
 53    pub fn sid(&self) -> TrackSid {
 54        match self {
 55            RemoteTrack::Audio(remote_audio_track) => remote_audio_track.sid(),
 56            RemoteTrack::Video(remote_video_track) => remote_video_track.sid(),
 57        }
 58    }
 59}
 60
 61#[derive(Clone, Debug)]
 62pub enum LocalTrack {
 63    Audio(LocalAudioTrack),
 64    Video(LocalVideoTrack),
 65}
 66
 67#[derive(Clone, Debug)]
 68#[non_exhaustive]
 69pub enum RoomEvent {
 70    ParticipantConnected(RemoteParticipant),
 71    ParticipantDisconnected(RemoteParticipant),
 72    LocalTrackPublished {
 73        publication: LocalTrackPublication,
 74        track: LocalTrack,
 75        participant: LocalParticipant,
 76    },
 77    LocalTrackUnpublished {
 78        publication: LocalTrackPublication,
 79        participant: LocalParticipant,
 80    },
 81    LocalTrackSubscribed {
 82        track: LocalTrack,
 83    },
 84    TrackSubscribed {
 85        track: RemoteTrack,
 86        publication: RemoteTrackPublication,
 87        participant: RemoteParticipant,
 88    },
 89    TrackUnsubscribed {
 90        track: RemoteTrack,
 91        publication: RemoteTrackPublication,
 92        participant: RemoteParticipant,
 93    },
 94    TrackSubscriptionFailed {
 95        participant: RemoteParticipant,
 96        // error: livekit::track::TrackError,
 97        track_sid: TrackSid,
 98    },
 99    TrackPublished {
100        publication: RemoteTrackPublication,
101        participant: RemoteParticipant,
102    },
103    TrackUnpublished {
104        publication: RemoteTrackPublication,
105        participant: RemoteParticipant,
106    },
107    TrackMuted {
108        participant: Participant,
109        publication: TrackPublication,
110    },
111    TrackUnmuted {
112        participant: Participant,
113        publication: TrackPublication,
114    },
115    RoomMetadataChanged {
116        old_metadata: String,
117        metadata: String,
118    },
119    ParticipantMetadataChanged {
120        participant: Participant,
121        old_metadata: String,
122        metadata: String,
123    },
124    ParticipantNameChanged {
125        participant: Participant,
126        old_name: String,
127        name: String,
128    },
129    ParticipantAttributesChanged {
130        participant: Participant,
131        changed_attributes: HashMap<String, String>,
132    },
133    ActiveSpeakersChanged {
134        speakers: Vec<Participant>,
135    },
136    ConnectionStateChanged(ConnectionState),
137    Connected {
138        participants_with_tracks: Vec<(RemoteParticipant, Vec<RemoteTrackPublication>)>,
139    },
140    Disconnected {
141        reason: &'static str,
142    },
143    Reconnecting,
144    Reconnected,
145}