lib.rs

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