Skip to content

Commit 1abf092

Browse files
authored
Update protocol to v15 (#394)
- add support for LocalTrackSubscribed - add support for RequestResponse - add support for new leave_request::Action - add support for sync_stream ID
1 parent 1689545 commit 1abf092

File tree

13 files changed

+1327
-429
lines changed

13 files changed

+1327
-429
lines changed

livekit-api/src/signal_client/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{
1616
borrow::Cow,
1717
fmt::Debug,
1818
sync::{
19-
atomic::{AtomicBool, Ordering},
19+
atomic::{AtomicBool, AtomicU32, Ordering},
2020
Arc,
2121
},
2222
time::{Duration, SystemTime, UNIX_EPOCH},
@@ -44,7 +44,7 @@ pub type SignalEvents = mpsc::UnboundedReceiver<SignalEvent>;
4444
pub type SignalResult<T> = Result<T, SignalError>;
4545

4646
pub const JOIN_RESPONSE_TIMEOUT: Duration = Duration::from_secs(5);
47-
pub const PROTOCOL_VERSION: u32 = 9;
47+
pub const PROTOCOL_VERSION: u32 = 15;
4848

4949
#[derive(Error, Debug)]
5050
pub enum SignalError {
@@ -92,6 +92,7 @@ struct SignalInner {
9292
url: String,
9393
options: SignalOptions,
9494
join_response: proto::JoinResponse,
95+
request_id: AtomicU32,
9596
}
9697

9798
pub struct SignalClient {
@@ -178,6 +179,11 @@ impl SignalClient {
178179
pub fn token(&self) -> String {
179180
self.inner.token.lock().clone()
180181
}
182+
183+
/// Increment request_id for user-initiated requests and [`RequestResponse`][`proto::RequestResponse`]s
184+
pub fn next_request_id(&self) -> u32 {
185+
self.inner.next_request_id().clone()
186+
}
181187
}
182188

183189
impl SignalInner {
@@ -213,6 +219,7 @@ impl SignalInner {
213219
options,
214220
url: url.to_string(),
215221
join_response: join_response.clone(),
222+
request_id: AtomicU32::new(1),
216223
});
217224

218225
Ok((inner, join_response, events))
@@ -315,6 +322,11 @@ impl SignalInner {
315322
}
316323
}
317324
}
325+
326+
/// Increment request_id for user-initiated requests and [`RequestResponse`][`proto::RequestResponse`]s
327+
pub fn next_request_id(&self) -> u32 {
328+
self.request_id.fetch_add(1, Ordering::SeqCst)
329+
}
318330
}
319331

320332
/// Middleware task to receive SignalStream events and handle SignalClient specific logic

livekit-ffi/protocol/room.proto

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ message TrackPublishOptions {
212212
bool red = 5;
213213
bool simulcast = 6;
214214
TrackSource source = 7;
215+
string stream = 8;
215216
}
216217

217218
enum IceTransportType {
@@ -318,21 +319,22 @@ message RoomEvent {
318319
ParticipantDisconnected participant_disconnected = 3;
319320
LocalTrackPublished local_track_published = 4;
320321
LocalTrackUnpublished local_track_unpublished = 5;
321-
TrackPublished track_published = 6;
322-
TrackUnpublished track_unpublished = 7;
323-
TrackSubscribed track_subscribed = 8;
324-
TrackUnsubscribed track_unsubscribed = 9;
325-
TrackSubscriptionFailed track_subscription_failed = 10;
326-
TrackMuted track_muted = 11;
327-
TrackUnmuted track_unmuted = 12;
328-
ActiveSpeakersChanged active_speakers_changed = 13;
329-
RoomMetadataChanged room_metadata_changed = 14;
330-
RoomSidChanged room_sid_changed = 15;
331-
ParticipantMetadataChanged participant_metadata_changed = 16;
332-
ParticipantNameChanged participant_name_changed = 17;
333-
ParticipantAttributesChanged participant_attributes_changed = 18;
334-
ConnectionQualityChanged connection_quality_changed = 19;
335-
ConnectionStateChanged connection_state_changed = 20;
322+
LocalTrackSubscribed local_track_subscribed = 6;
323+
TrackPublished track_published = 7;
324+
TrackUnpublished track_unpublished = 8;
325+
TrackSubscribed track_subscribed = 9;
326+
TrackUnsubscribed track_unsubscribed = 10;
327+
TrackSubscriptionFailed track_subscription_failed = 11;
328+
TrackMuted track_muted = 12;
329+
TrackUnmuted track_unmuted = 13;
330+
ActiveSpeakersChanged active_speakers_changed = 14;
331+
RoomMetadataChanged room_metadata_changed = 15;
332+
RoomSidChanged room_sid_changed = 16;
333+
ParticipantMetadataChanged participant_metadata_changed = 17;
334+
ParticipantNameChanged participant_name_changed = 18;
335+
ParticipantAttributesChanged participant_attributes_changed = 19;
336+
ConnectionQualityChanged connection_quality_changed = 20;
337+
ConnectionStateChanged connection_state_changed = 21;
336338
// Connected connected = 21;
337339
Disconnected disconnected = 22;
338340
Reconnecting reconnecting = 23;
@@ -371,6 +373,10 @@ message LocalTrackUnpublished {
371373
string publication_sid = 1;
372374
}
373375

376+
message LocalTrackSubscribed {
377+
string track_sid = 2;
378+
}
379+
374380
message TrackPublished {
375381
string participant_identity = 1;
376382
OwnedTrackPublication publication = 2;

livekit-ffi/src/conversion/room.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ impl From<proto::TrackPublishOptions> for TrackPublishOptions {
214214
dtx: opts.dtx,
215215
red: opts.red,
216216
simulcast: opts.simulcast,
217+
stream: opts.stream,
217218
}
218219
}
219220
}

livekit-ffi/src/livekit.proto.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,8 @@ pub struct TrackPublishOptions {
22402240
pub simulcast: bool,
22412241
#[prost(enumeration="TrackSource", tag="7")]
22422242
pub source: i32,
2243+
#[prost(string, tag="8")]
2244+
pub stream: ::prost::alloc::string::String,
22432245
}
22442246
#[allow(clippy::derive_partial_eq_without_eq)]
22452247
#[derive(Clone, PartialEq, ::prost::Message)]
@@ -2316,7 +2318,7 @@ pub struct OwnedBuffer {
23162318
pub struct RoomEvent {
23172319
#[prost(uint64, tag="1")]
23182320
pub room_handle: u64,
2319-
#[prost(oneof="room_event::Message", tags="2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28")]
2321+
#[prost(oneof="room_event::Message", tags="2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28")]
23202322
pub message: ::core::option::Option<room_event::Message>,
23212323
}
23222324
/// Nested message and enum types in `RoomEvent`.
@@ -2333,34 +2335,36 @@ pub mod room_event {
23332335
#[prost(message, tag="5")]
23342336
LocalTrackUnpublished(super::LocalTrackUnpublished),
23352337
#[prost(message, tag="6")]
2336-
TrackPublished(super::TrackPublished),
2338+
LocalTrackSubscribed(super::LocalTrackSubscribed),
23372339
#[prost(message, tag="7")]
2338-
TrackUnpublished(super::TrackUnpublished),
2340+
TrackPublished(super::TrackPublished),
23392341
#[prost(message, tag="8")]
2340-
TrackSubscribed(super::TrackSubscribed),
2342+
TrackUnpublished(super::TrackUnpublished),
23412343
#[prost(message, tag="9")]
2342-
TrackUnsubscribed(super::TrackUnsubscribed),
2344+
TrackSubscribed(super::TrackSubscribed),
23432345
#[prost(message, tag="10")]
2344-
TrackSubscriptionFailed(super::TrackSubscriptionFailed),
2346+
TrackUnsubscribed(super::TrackUnsubscribed),
23452347
#[prost(message, tag="11")]
2346-
TrackMuted(super::TrackMuted),
2348+
TrackSubscriptionFailed(super::TrackSubscriptionFailed),
23472349
#[prost(message, tag="12")]
2348-
TrackUnmuted(super::TrackUnmuted),
2350+
TrackMuted(super::TrackMuted),
23492351
#[prost(message, tag="13")]
2350-
ActiveSpeakersChanged(super::ActiveSpeakersChanged),
2352+
TrackUnmuted(super::TrackUnmuted),
23512353
#[prost(message, tag="14")]
2352-
RoomMetadataChanged(super::RoomMetadataChanged),
2354+
ActiveSpeakersChanged(super::ActiveSpeakersChanged),
23532355
#[prost(message, tag="15")]
2354-
RoomSidChanged(super::RoomSidChanged),
2356+
RoomMetadataChanged(super::RoomMetadataChanged),
23552357
#[prost(message, tag="16")]
2356-
ParticipantMetadataChanged(super::ParticipantMetadataChanged),
2358+
RoomSidChanged(super::RoomSidChanged),
23572359
#[prost(message, tag="17")]
2358-
ParticipantNameChanged(super::ParticipantNameChanged),
2360+
ParticipantMetadataChanged(super::ParticipantMetadataChanged),
23592361
#[prost(message, tag="18")]
2360-
ParticipantAttributesChanged(super::ParticipantAttributesChanged),
2362+
ParticipantNameChanged(super::ParticipantNameChanged),
23612363
#[prost(message, tag="19")]
2362-
ConnectionQualityChanged(super::ConnectionQualityChanged),
2364+
ParticipantAttributesChanged(super::ParticipantAttributesChanged),
23632365
#[prost(message, tag="20")]
2366+
ConnectionQualityChanged(super::ConnectionQualityChanged),
2367+
#[prost(message, tag="21")]
23642368
ConnectionStateChanged(super::ConnectionStateChanged),
23652369
/// Connected connected = 21;
23662370
#[prost(message, tag="22")]
@@ -2426,6 +2430,12 @@ pub struct LocalTrackUnpublished {
24262430
}
24272431
#[allow(clippy::derive_partial_eq_without_eq)]
24282432
#[derive(Clone, PartialEq, ::prost::Message)]
2433+
pub struct LocalTrackSubscribed {
2434+
#[prost(string, tag="2")]
2435+
pub track_sid: ::prost::alloc::string::String,
2436+
}
2437+
#[allow(clippy::derive_partial_eq_without_eq)]
2438+
#[derive(Clone, PartialEq, ::prost::Message)]
24292439
pub struct TrackPublished {
24302440
#[prost(string, tag="1")]
24312441
pub participant_identity: ::prost::alloc::string::String,

livekit-ffi/src/server/room.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,11 @@ async fn forward_event(
773773

774774
inner.pending_unpublished_tracks.lock().insert(publication.sid());
775775
}
776+
RoomEvent::LocalTrackSubscribed { track } => {
777+
let _ = send_event(proto::room_event::Message::LocalTrackSubscribed(
778+
proto::LocalTrackSubscribed { track_sid: track.sid().to_string() },
779+
));
780+
}
776781
RoomEvent::TrackPublished { publication, participant } => {
777782
let handle_id = server.next_id();
778783
let ffi_publication = FfiPublication {

livekit-protocol/src/livekit.rs

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ pub struct ParticipantInfo {
112112
pub kind: i32,
113113
#[prost(map="string, string", tag="15")]
114114
pub attributes: ::std::collections::HashMap<::prost::alloc::string::String, ::prost::alloc::string::String>,
115+
#[prost(enumeration="DisconnectReason", tag="16")]
116+
pub disconnect_reason: i32,
115117
}
116118
/// Nested message and enum types in `ParticipantInfo`.
117119
pub mod participant_info {
@@ -738,6 +740,67 @@ pub struct RtpStats {
738740
}
739741
#[allow(clippy::derive_partial_eq_without_eq)]
740742
#[derive(Clone, PartialEq, ::prost::Message)]
743+
pub struct RtpForwarderState {
744+
#[prost(bool, tag="1")]
745+
pub started: bool,
746+
#[prost(int32, tag="2")]
747+
pub reference_layer_spatial: i32,
748+
#[prost(int64, tag="3")]
749+
pub pre_start_time: i64,
750+
#[prost(uint64, tag="4")]
751+
pub ext_first_timestamp: u64,
752+
#[prost(uint64, tag="5")]
753+
pub dummy_start_timestamp_offset: u64,
754+
#[prost(message, optional, tag="6")]
755+
pub rtp_munger: ::core::option::Option<RtpMungerState>,
756+
#[prost(oneof="rtp_forwarder_state::CodecMunger", tags="7")]
757+
pub codec_munger: ::core::option::Option<rtp_forwarder_state::CodecMunger>,
758+
}
759+
/// Nested message and enum types in `RTPForwarderState`.
760+
pub mod rtp_forwarder_state {
761+
#[allow(clippy::derive_partial_eq_without_eq)]
762+
#[derive(Clone, PartialEq, ::prost::Oneof)]
763+
pub enum CodecMunger {
764+
#[prost(message, tag="7")]
765+
Vp8Munger(super::Vp8MungerState),
766+
}
767+
}
768+
#[allow(clippy::derive_partial_eq_without_eq)]
769+
#[derive(Clone, PartialEq, ::prost::Message)]
770+
pub struct RtpMungerState {
771+
#[prost(uint64, tag="1")]
772+
pub ext_last_sequence_number: u64,
773+
#[prost(uint64, tag="2")]
774+
pub ext_second_last_sequence_number: u64,
775+
#[prost(uint64, tag="3")]
776+
pub ext_last_timestamp: u64,
777+
#[prost(uint64, tag="4")]
778+
pub ext_second_last_timestamp: u64,
779+
#[prost(bool, tag="5")]
780+
pub last_marker: bool,
781+
#[prost(bool, tag="6")]
782+
pub second_last_marker: bool,
783+
}
784+
#[allow(clippy::derive_partial_eq_without_eq)]
785+
#[derive(Clone, PartialEq, ::prost::Message)]
786+
pub struct Vp8MungerState {
787+
#[prost(int32, tag="1")]
788+
pub ext_last_picture_id: i32,
789+
#[prost(bool, tag="2")]
790+
pub picture_id_used: bool,
791+
#[prost(uint32, tag="3")]
792+
pub last_tl0_pic_idx: u32,
793+
#[prost(bool, tag="4")]
794+
pub tl0_pic_idx_used: bool,
795+
#[prost(bool, tag="5")]
796+
pub tid_used: bool,
797+
#[prost(uint32, tag="6")]
798+
pub last_key_idx: u32,
799+
#[prost(bool, tag="7")]
800+
pub key_idx_used: bool,
801+
}
802+
#[allow(clippy::derive_partial_eq_without_eq)]
803+
#[derive(Clone, PartialEq, ::prost::Message)]
741804
pub struct TimedVersion {
742805
#[prost(int64, tag="1")]
743806
pub unix_micro: i64,
@@ -2274,9 +2337,9 @@ pub mod signal_response {
22742337
/// Subscription response, client should not expect any media from this subscription if it fails
22752338
#[prost(message, tag="21")]
22762339
SubscriptionResponse(super::SubscriptionResponse),
2277-
/// Errors relating to user inititated requests that carry a `request_id`
2340+
/// Response relating to user inititated requests that carry a `request_id`
22782341
#[prost(message, tag="22")]
2279-
ErrorResponse(super::ErrorResponse),
2342+
RequestResponse(super::RequestResponse),
22802343
/// notify to the publisher when a published track has been subscribed for the first time
22812344
#[prost(message, tag="23")]
22822345
TrackSubscribed(super::TrackSubscribed),
@@ -2778,20 +2841,20 @@ pub struct SubscriptionResponse {
27782841
}
27792842
#[allow(clippy::derive_partial_eq_without_eq)]
27802843
#[derive(Clone, PartialEq, ::prost::Message)]
2781-
pub struct ErrorResponse {
2844+
pub struct RequestResponse {
27822845
#[prost(uint32, tag="1")]
27832846
pub request_id: u32,
2784-
#[prost(enumeration="error_response::Reason", tag="2")]
2847+
#[prost(enumeration="request_response::Reason", tag="2")]
27852848
pub reason: i32,
27862849
#[prost(string, tag="3")]
27872850
pub message: ::prost::alloc::string::String,
27882851
}
2789-
/// Nested message and enum types in `ErrorResponse`.
2790-
pub mod error_response {
2852+
/// Nested message and enum types in `RequestResponse`.
2853+
pub mod request_response {
27912854
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
27922855
#[repr(i32)]
27932856
pub enum Reason {
2794-
Unknown = 0,
2857+
Ok = 0,
27952858
NotFound = 1,
27962859
NotAllowed = 2,
27972860
LimitExceeded = 3,
@@ -2803,7 +2866,7 @@ pub mod error_response {
28032866
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
28042867
pub fn as_str_name(&self) -> &'static str {
28052868
match self {
2806-
Reason::Unknown => "UNKNOWN",
2869+
Reason::Ok => "OK",
28072870
Reason::NotFound => "NOT_FOUND",
28082871
Reason::NotAllowed => "NOT_ALLOWED",
28092872
Reason::LimitExceeded => "LIMIT_EXCEEDED",
@@ -2812,7 +2875,7 @@ pub mod error_response {
28122875
/// Creates an enum from field names used in the ProtoBuf definition.
28132876
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
28142877
match value {
2815-
"UNKNOWN" => Some(Self::Unknown),
2878+
"OK" => Some(Self::Ok),
28162879
"NOT_FOUND" => Some(Self::NotFound),
28172880
"NOT_ALLOWED" => Some(Self::NotAllowed),
28182881
"LIMIT_EXCEEDED" => Some(Self::LimitExceeded),
@@ -2944,6 +3007,8 @@ pub struct JobState {
29443007
pub ended_at: i64,
29453008
#[prost(int64, tag="5")]
29463009
pub updated_at: i64,
3010+
#[prost(string, tag="6")]
3011+
pub participant_identity: ::prost::alloc::string::String,
29473012
}
29483013
/// from Worker to Server
29493014
#[allow(clippy::derive_partial_eq_without_eq)]
@@ -3234,10 +3299,12 @@ pub struct RoomAgentDispatch {
32343299
pub struct DeleteAgentDispatchRequest {
32353300
#[prost(string, tag="1")]
32363301
pub dispatch_id: ::prost::alloc::string::String,
3302+
#[prost(string, tag="2")]
3303+
pub room: ::prost::alloc::string::String,
32373304
}
32383305
#[allow(clippy::derive_partial_eq_without_eq)]
32393306
#[derive(Clone, PartialEq, ::prost::Message)]
3240-
pub struct ListAgentDispatchRequesst {
3307+
pub struct ListAgentDispatchRequest {
32413308
/// if set, only the dispatch whose id is given will be returned
32423309
#[prost(string, tag="1")]
32433310
pub dispatch_id: ::prost::alloc::string::String,

0 commit comments

Comments
 (0)