Skip to content

Commit bdc0ffb

Browse files
authored
Expose room updates, support MoveParticipant (protocol 15) (#662)
* Expose room updates, support MoveParticipant (protocol 15) giving clients other information about the room so they could receive * also fix sid updates * remove dead var
1 parent dcb8919 commit bdc0ffb

File tree

17 files changed

+618
-28
lines changed

17 files changed

+618
-28
lines changed

livekit-api/src/services/sip.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ impl SIPClient {
236236
// TODO: support these attributes
237237
include_headers: Default::default(),
238238
media_encryption: Default::default(),
239+
destination_country: Default::default(),
239240
}),
240241
},
241242
self.base.auth_header(

livekit-api/src/signal_client/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub type SignalEvents = mpsc::UnboundedReceiver<SignalEvent>;
4747
pub type SignalResult<T> = Result<T, SignalError>;
4848

4949
pub const JOIN_RESPONSE_TIMEOUT: Duration = Duration::from_secs(5);
50-
pub const PROTOCOL_VERSION: u32 = 15;
50+
pub const PROTOCOL_VERSION: u32 = 16;
5151

5252
#[derive(Error, Debug)]
5353
pub enum SignalError {

livekit-ffi/protocol/participant.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@ enum DisconnectReason {
7171
// SIP protocol failure or unexpected response
7272
SIP_TRUNK_FAILURE = 13;
7373
CONNECTION_TIMEOUT = 14;
74+
MEDIA_FAILURE = 15;
7475
}

livekit-ffi/protocol/room.proto

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ message RoomEvent {
376376
// Data stream (high level)
377377
ByteStreamOpened byte_stream_opened = 34;
378378
TextStreamOpened text_stream_opened = 35;
379+
// Room info updated
380+
RoomInfo room_updated = 36;
381+
// Participant moved to new room
382+
RoomInfo moved = 37;
383+
// carry over all participant info updates, including sid
384+
ParticipantsUpdated participants_updated = 38;
379385
}
380386
}
381387

@@ -385,13 +391,24 @@ message RoomInfo {
385391
required string metadata = 3;
386392
required uint64 lossy_dc_buffered_amount_low_threshold = 4;
387393
required uint64 reliable_dc_buffered_amount_low_threshold = 5;
394+
required uint32 empty_timeout = 6;
395+
required uint32 departure_timeout = 7;
396+
required uint32 max_participants = 8;
397+
required int64 creation_time = 9;
398+
required uint32 num_participants = 10;
399+
required uint32 num_publishers = 11;
400+
required bool active_recording = 12;
388401
}
389402

390403
message OwnedRoom {
391404
required FfiOwnedHandle handle = 1;
392405
required RoomInfo info = 2;
393406
}
394407

408+
message ParticipantsUpdated {
409+
repeated ParticipantInfo participants = 1;
410+
}
411+
395412
message ParticipantConnected { required OwnedParticipant info = 1; }
396413

397414
message ParticipantDisconnected {

livekit-ffi/src/conversion/participant.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@
1313
// limitations under the License.
1414

1515
use crate::{proto, server::participant::FfiParticipant};
16+
use livekit::prelude::*;
1617
use livekit::DisconnectReason;
1718
use livekit::ParticipantKind;
1819

1920
impl From<&FfiParticipant> for proto::ParticipantInfo {
2021
fn from(value: &FfiParticipant) -> Self {
21-
let participant = &value.participant;
22+
From::<&Participant>::from(&value.participant)
23+
}
24+
}
25+
26+
impl From<&Participant> for proto::ParticipantInfo {
27+
fn from(participant: &Participant) -> Self {
2228
Self {
2329
sid: participant.sid().into(),
2430
name: participant.name(),
@@ -62,6 +68,7 @@ impl From<DisconnectReason> for proto::DisconnectReason {
6268
DisconnectReason::UserRejected => proto::DisconnectReason::UserRejected,
6369
DisconnectReason::SipTrunkFailure => proto::DisconnectReason::SipTrunkFailure,
6470
DisconnectReason::ConnectionTimeout => proto::DisconnectReason::ConnectionTimeout,
71+
DisconnectReason::MediaFailure => proto::DisconnectReason::MediaFailure,
6572
}
6673
}
6774
}

livekit-ffi/src/conversion/room.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use livekit::{
2424
native::frame_cryptor::EncryptionState,
2525
prelude::{ContinualGatheringPolicy, IceServer, IceTransportsType, RtcConfiguration},
2626
},
27+
RoomInfo,
2728
};
2829

2930
impl From<EncryptionState> for proto::EncryptionState {
@@ -99,6 +100,7 @@ impl From<DisconnectReason> for proto::DisconnectReason {
99100
DisconnectReason::UserRejected => Self::UserRejected,
100101
DisconnectReason::SipTrunkFailure => Self::SipTrunkFailure,
101102
DisconnectReason::ConnectionTimeout => Self::ConnectionTimeout,
103+
DisconnectReason::MediaFailure => Self::MediaFailure,
102104
}
103105
}
104106
}
@@ -249,7 +251,7 @@ impl From<proto::AudioEncoding> for AudioEncoding {
249251
impl From<&FfiRoom> for proto::RoomInfo {
250252
fn from(value: &FfiRoom) -> Self {
251253
let room = &value.inner.room;
252-
Self {
254+
proto::RoomInfo {
253255
sid: room.maybe_sid().map(|x| x.to_string()),
254256
name: room.name(),
255257
metadata: room.metadata(),
@@ -259,6 +261,36 @@ impl From<&FfiRoom> for proto::RoomInfo {
259261
reliable_dc_buffered_amount_low_threshold: room
260262
.data_channel_options(DataPacketKind::Reliable)
261263
.buffered_amount_low_threshold,
264+
empty_timeout: room.empty_timeout(),
265+
departure_timeout: room.departure_timeout(),
266+
max_participants: room.max_participants(),
267+
creation_time: room.creation_time(),
268+
num_participants: room.num_participants(),
269+
num_publishers: room.num_publishers(),
270+
active_recording: room.active_recording(),
271+
}
272+
}
273+
}
274+
275+
impl From<RoomInfo> for proto::RoomInfo {
276+
fn from(room: RoomInfo) -> Self {
277+
proto::RoomInfo {
278+
sid: room.sid.map(|x| x.to_string()),
279+
name: room.name,
280+
metadata: room.metadata,
281+
lossy_dc_buffered_amount_low_threshold: room
282+
.lossy_dc_options
283+
.buffered_amount_low_threshold,
284+
reliable_dc_buffered_amount_low_threshold: room
285+
.reliable_dc_options
286+
.buffered_amount_low_threshold,
287+
empty_timeout: room.empty_timeout,
288+
departure_timeout: room.departure_timeout,
289+
max_participants: room.max_participants,
290+
creation_time: room.creation_time,
291+
num_participants: room.num_participants,
292+
num_publishers: room.num_publishers,
293+
active_recording: room.active_recording,
262294
}
263295
}
264296
}

livekit-ffi/src/livekit.proto.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,7 @@ pub enum DisconnectReason {
17391739
/// SIP protocol failure or unexpected response
17401740
SipTrunkFailure = 13,
17411741
ConnectionTimeout = 14,
1742+
MediaFailure = 15,
17421743
}
17431744
impl DisconnectReason {
17441745
/// String value of the enum field names used in the ProtoBuf definition.
@@ -1762,6 +1763,7 @@ impl DisconnectReason {
17621763
DisconnectReason::UserRejected => "USER_REJECTED",
17631764
DisconnectReason::SipTrunkFailure => "SIP_TRUNK_FAILURE",
17641765
DisconnectReason::ConnectionTimeout => "CONNECTION_TIMEOUT",
1766+
DisconnectReason::MediaFailure => "MEDIA_FAILURE",
17651767
}
17661768
}
17671769
/// Creates an enum from field names used in the ProtoBuf definition.
@@ -1782,6 +1784,7 @@ impl DisconnectReason {
17821784
"USER_REJECTED" => Some(Self::UserRejected),
17831785
"SIP_TRUNK_FAILURE" => Some(Self::SipTrunkFailure),
17841786
"CONNECTION_TIMEOUT" => Some(Self::ConnectionTimeout),
1787+
"MEDIA_FAILURE" => Some(Self::MediaFailure),
17851788
_ => None,
17861789
}
17871790
}
@@ -3329,7 +3332,7 @@ pub struct OwnedBuffer {
33293332
pub struct RoomEvent {
33303333
#[prost(uint64, required, tag="1")]
33313334
pub room_handle: u64,
3332-
#[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, 29, 30, 31, 32, 33, 34, 35")]
3335+
#[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, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38")]
33333336
pub message: ::core::option::Option<room_event::Message>,
33343337
}
33353338
/// Nested message and enum types in `RoomEvent`.
@@ -3409,6 +3412,15 @@ pub mod room_event {
34093412
ByteStreamOpened(super::ByteStreamOpened),
34103413
#[prost(message, tag="35")]
34113414
TextStreamOpened(super::TextStreamOpened),
3415+
/// Room info updated
3416+
#[prost(message, tag="36")]
3417+
RoomUpdated(super::RoomInfo),
3418+
/// Participant moved to new room
3419+
#[prost(message, tag="37")]
3420+
Moved(super::RoomInfo),
3421+
/// carry over all participant info updates, including sid
3422+
#[prost(message, tag="38")]
3423+
ParticipantsUpdated(super::ParticipantsUpdated),
34123424
}
34133425
}
34143426
#[allow(clippy::derive_partial_eq_without_eq)]
@@ -3424,6 +3436,20 @@ pub struct RoomInfo {
34243436
pub lossy_dc_buffered_amount_low_threshold: u64,
34253437
#[prost(uint64, required, tag="5")]
34263438
pub reliable_dc_buffered_amount_low_threshold: u64,
3439+
#[prost(uint32, required, tag="6")]
3440+
pub empty_timeout: u32,
3441+
#[prost(uint32, required, tag="7")]
3442+
pub departure_timeout: u32,
3443+
#[prost(uint32, required, tag="8")]
3444+
pub max_participants: u32,
3445+
#[prost(int64, required, tag="9")]
3446+
pub creation_time: i64,
3447+
#[prost(uint32, required, tag="10")]
3448+
pub num_participants: u32,
3449+
#[prost(uint32, required, tag="11")]
3450+
pub num_publishers: u32,
3451+
#[prost(bool, required, tag="12")]
3452+
pub active_recording: bool,
34273453
}
34283454
#[allow(clippy::derive_partial_eq_without_eq)]
34293455
#[derive(Clone, PartialEq, ::prost::Message)]
@@ -3435,6 +3461,12 @@ pub struct OwnedRoom {
34353461
}
34363462
#[allow(clippy::derive_partial_eq_without_eq)]
34373463
#[derive(Clone, PartialEq, ::prost::Message)]
3464+
pub struct ParticipantsUpdated {
3465+
#[prost(message, repeated, tag="1")]
3466+
pub participants: ::prost::alloc::vec::Vec<ParticipantInfo>,
3467+
}
3468+
#[allow(clippy::derive_partial_eq_without_eq)]
3469+
#[derive(Clone, PartialEq, ::prost::Message)]
34383470
pub struct ParticipantConnected {
34393471
#[prost(message, required, tag="1")]
34403472
pub info: OwnedParticipant,

livekit-ffi/src/server/room.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,6 @@ impl RoomInner {
629629
send_chat_message.sender_identity,
630630
)
631631
.await;
632-
let sent_message = res.as_ref().unwrap().clone();
633632
match res {
634633
Ok(message) => {
635634
let _ = server.send_event(proto::ffi_event::Message::ChatMessage(
@@ -652,7 +651,6 @@ impl RoomInner {
652651
));
653652
}
654653
}
655-
sent_message;
656654
});
657655
server.watch_panic(handle);
658656
proto::SendChatMessageResponse { async_id }
@@ -676,7 +674,6 @@ impl RoomInner {
676674
edit_chat_message.sender_identity,
677675
)
678676
.await;
679-
let sent_message: ChatMessage = res.as_ref().unwrap().clone();
680677
match res {
681678
Ok(message) => {
682679
let _ = server.send_event(proto::ffi_event::Message::ChatMessage(
@@ -699,7 +696,6 @@ impl RoomInner {
699696
));
700697
}
701698
}
702-
sent_message;
703699
});
704700
server.watch_panic(handle);
705701
proto::SendChatMessageResponse { async_id }
@@ -720,6 +716,7 @@ impl RoomInner {
720716
send_stream_header.header.into(),
721717
)
722718
.into(),
719+
..Default::default()
723720
};
724721
let async_id = server.next_id();
725722
let inner = self.clone();
@@ -748,6 +745,7 @@ impl RoomInner {
748745
send_stream_chunk.chunk.into(),
749746
)
750747
.into(),
748+
..Default::default()
751749
};
752750
let async_id = server.next_id();
753751
let inner = self.clone();
@@ -777,6 +775,7 @@ impl RoomInner {
777775
send_stream_trailer.trailer.into(),
778776
)
779777
.into(),
778+
..Default::default()
780779
};
781780
let async_id = server.next_id();
782781
let inner = self.clone();
@@ -1248,7 +1247,7 @@ async fn forward_event(
12481247
));
12491248
}
12501249
RoomEvent::SipDTMFReceived { code, digit, participant } => {
1251-
let (sid, identity) = match participant {
1250+
let (_sid, identity) = match participant {
12521251
Some(p) => (Some(p.sid().to_string()), p.identity().to_string()),
12531252
None => (None, String::new()),
12541253
};
@@ -1265,7 +1264,7 @@ async fn forward_event(
12651264
}
12661265

12671266
RoomEvent::ChatMessage { message, participant } => {
1268-
let (sid, identity) = match participant {
1267+
let (_sid, identity) = match participant {
12691268
Some(p) => (Some(p.sid().to_string()), p.identity().to_string()),
12701269
None => (None, String::new()),
12711270
};
@@ -1359,6 +1358,22 @@ async fn forward_event(
13591358
},
13601359
));
13611360
}
1361+
RoomEvent::RoomUpdated { room } => {
1362+
let _ = send_event(proto::room_event::Message::RoomUpdated(room.into()));
1363+
}
1364+
RoomEvent::Moved { room } => {
1365+
let _ = send_event(proto::room_event::Message::Moved(room.into()));
1366+
}
1367+
RoomEvent::ParticipantsUpdated { participants } => {
1368+
let _ = send_event(proto::room_event::Message::ParticipantsUpdated(
1369+
proto::ParticipantsUpdated {
1370+
participants: participants
1371+
.into_iter()
1372+
.map(|p| proto::ParticipantInfo::from(&p))
1373+
.collect(),
1374+
},
1375+
));
1376+
}
13621377
_ => {
13631378
log::warn!("unhandled room event: {:?}", event);
13641379
}

livekit-protocol/protocol

Submodule protocol updated 64 files

0 commit comments

Comments
 (0)