diff --git a/livekit-ffi/protocol/ffi.proto b/livekit-ffi/protocol/ffi.proto index b8f8b71f..cf820d41 100644 --- a/livekit-ffi/protocol/ffi.proto +++ b/livekit-ffi/protocol/ffi.proto @@ -68,25 +68,26 @@ message FfiRequest { SetLocalAttributesRequest update_local_attributes = 11; GetSessionStatsRequest get_session_stats = 12; PublishTranscriptionRequest publish_transcription = 13; + GetRoomSidRequest get_room_sid = 14; // Track - CreateVideoTrackRequest create_video_track = 14; - CreateAudioTrackRequest create_audio_track = 15; - GetStatsRequest get_stats = 16; + CreateVideoTrackRequest create_video_track = 15; + CreateAudioTrackRequest create_audio_track = 16; + GetStatsRequest get_stats = 17; // Video - NewVideoStreamRequest new_video_stream = 17; - NewVideoSourceRequest new_video_source = 18; - CaptureVideoFrameRequest capture_video_frame = 19; - VideoConvertRequest video_convert = 20; + NewVideoStreamRequest new_video_stream = 18; + NewVideoSourceRequest new_video_source = 19; + CaptureVideoFrameRequest capture_video_frame = 20; + VideoConvertRequest video_convert = 21; // Audio - NewAudioStreamRequest new_audio_stream = 22; - NewAudioSourceRequest new_audio_source = 23; - CaptureAudioFrameRequest capture_audio_frame = 24; - NewAudioResamplerRequest new_audio_resampler = 25; - RemixAndResampleRequest remix_and_resample = 26; - E2eeRequest e2ee = 27; + NewAudioStreamRequest new_audio_stream = 23; + NewAudioSourceRequest new_audio_source = 24; + CaptureAudioFrameRequest capture_audio_frame = 25; + NewAudioResamplerRequest new_audio_resampler = 26; + RemixAndResampleRequest remix_and_resample = 27; + E2eeRequest e2ee = 28; } } @@ -107,17 +108,18 @@ message FfiResponse { SetLocalAttributesResponse update_local_attributes = 11; GetSessionStatsResponse get_session_stats = 12; PublishTranscriptionResponse publish_transcription = 13; + GetRoomSidResponse get_room_sid = 14; // Track - CreateVideoTrackResponse create_video_track = 14; - CreateAudioTrackResponse create_audio_track = 15; - GetStatsResponse get_stats = 16; + CreateVideoTrackResponse create_video_track = 15; + CreateAudioTrackResponse create_audio_track = 16; + GetStatsResponse get_stats = 17; // Video - NewVideoStreamResponse new_video_stream = 17; - NewVideoSourceResponse new_video_source = 18; - CaptureVideoFrameResponse capture_video_frame = 19; - VideoConvertResponse video_convert = 20; + NewVideoStreamResponse new_video_stream = 18; + NewVideoSourceResponse new_video_source = 19; + CaptureVideoFrameResponse capture_video_frame = 20; + VideoConvertResponse video_convert = 21; // Audio NewAudioStreamResponse new_audio_stream = 22; @@ -139,20 +141,21 @@ message FfiEvent { VideoStreamEvent video_stream_event = 3; AudioStreamEvent audio_stream_event = 4; ConnectCallback connect = 5; - DisconnectCallback disconnect = 6; - DisposeCallback dispose = 7; - PublishTrackCallback publish_track = 8; - UnpublishTrackCallback unpublish_track = 9; - PublishDataCallback publish_data = 10; - PublishTranscriptionCallback publish_transcription = 11; - CaptureAudioFrameCallback capture_audio_frame = 12; - SetLocalMetadataCallback update_local_metadata = 13; - SetLocalNameCallback update_local_name = 14; - SetLocalAttributesCallback update_local_attributes = 15; - GetStatsCallback get_stats = 16; - LogBatch logs = 17; - GetSessionStatsCallback get_session_stats = 18; - Panic panic = 19; + GetRoomSidCallback get_room_sid = 6; + DisconnectCallback disconnect = 7; + DisposeCallback dispose = 8; + PublishTrackCallback publish_track = 9; + UnpublishTrackCallback unpublish_track = 10; + PublishDataCallback publish_data = 11; + PublishTranscriptionCallback publish_transcription = 12; + CaptureAudioFrameCallback capture_audio_frame = 13; + SetLocalMetadataCallback update_local_metadata = 14; + SetLocalNameCallback update_local_name = 15; + SetLocalAttributesCallback update_local_attributes = 16; + GetStatsCallback get_stats = 17; + LogBatch logs = 18; + GetSessionStatsCallback get_session_stats = 19; + Panic panic = 20; } } diff --git a/livekit-ffi/protocol/room.proto b/livekit-ffi/protocol/room.proto index bb4141c7..a7adcc57 100644 --- a/livekit-ffi/protocol/room.proto +++ b/livekit-ffi/protocol/room.proto @@ -49,6 +49,22 @@ message ConnectCallback { repeated ParticipantWithTracks participants = 5; } +// Get Room Sid + +message GetRoomSidRequest { + uint64 room_handle = 1; +} + +message GetRoomSidResponse { + uint64 async_id = 1; +} + +message GetRoomSidCallback { + uint64 async_id = 1; + string sid = 2; + optional string error = 3; +} + // Disconnect from the a room message DisconnectRequest { uint64 room_handle = 1; } message DisconnectResponse { uint64 async_id = 1; } @@ -305,7 +321,7 @@ message RoomEvent { } message RoomInfo { - string sid = 1; + optional string sid = 1; string name = 2; string metadata = 3; } diff --git a/livekit-ffi/src/conversion/room.rs b/livekit-ffi/src/conversion/room.rs index cee4e44f..e8ce14bf 100644 --- a/livekit-ffi/src/conversion/room.rs +++ b/livekit-ffi/src/conversion/room.rs @@ -216,7 +216,7 @@ impl From<&FfiRoom> for proto::RoomInfo { fn from(value: &FfiRoom) -> Self { let room = &value.inner.room; Self { - sid: room.maybe_sid().unwrap_or_default().into(), + sid: room.maybe_sid().map(|x| x.to_string()), name: room.name(), metadata: room.metadata(), } diff --git a/livekit-ffi/src/livekit.proto.rs b/livekit-ffi/src/livekit.proto.rs index 3a698726..e5ef6086 100644 --- a/livekit-ffi/src/livekit.proto.rs +++ b/livekit-ffi/src/livekit.proto.rs @@ -1940,6 +1940,30 @@ pub mod connect_callback { pub publications: ::prost::alloc::vec::Vec, } } +// Get Room Sid + +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetRoomSidRequest { + #[prost(uint64, tag="1")] + pub room_handle: u64, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetRoomSidResponse { + #[prost(uint64, tag="1")] + pub async_id: u64, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetRoomSidCallback { + #[prost(uint64, tag="1")] + pub async_id: u64, + #[prost(string, tag="2")] + pub sid: ::prost::alloc::string::String, + #[prost(string, optional, tag="3")] + pub error: ::core::option::Option<::prost::alloc::string::String>, +} /// Disconnect from the a room #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -2355,8 +2379,8 @@ pub mod room_event { #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct RoomInfo { - #[prost(string, tag="1")] - pub sid: ::prost::alloc::string::String, + #[prost(string, optional, tag="1")] + pub sid: ::core::option::Option<::prost::alloc::string::String>, #[prost(string, tag="2")] pub name: ::prost::alloc::string::String, #[prost(string, tag="3")] @@ -3019,7 +3043,7 @@ impl AudioSourceType { #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct FfiRequest { - #[prost(oneof="ffi_request::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")] + #[prost(oneof="ffi_request::Message", tags="2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28")] pub message: ::core::option::Option, } /// Nested message and enum types in `FfiRequest`. @@ -3052,34 +3076,36 @@ pub mod ffi_request { GetSessionStats(super::GetSessionStatsRequest), #[prost(message, tag="13")] PublishTranscription(super::PublishTranscriptionRequest), - /// Track #[prost(message, tag="14")] - CreateVideoTrack(super::CreateVideoTrackRequest), + GetRoomSid(super::GetRoomSidRequest), + /// Track #[prost(message, tag="15")] - CreateAudioTrack(super::CreateAudioTrackRequest), + CreateVideoTrack(super::CreateVideoTrackRequest), #[prost(message, tag="16")] + CreateAudioTrack(super::CreateAudioTrackRequest), + #[prost(message, tag="17")] GetStats(super::GetStatsRequest), /// Video - #[prost(message, tag="17")] - NewVideoStream(super::NewVideoStreamRequest), #[prost(message, tag="18")] - NewVideoSource(super::NewVideoSourceRequest), + NewVideoStream(super::NewVideoStreamRequest), #[prost(message, tag="19")] - CaptureVideoFrame(super::CaptureVideoFrameRequest), + NewVideoSource(super::NewVideoSourceRequest), #[prost(message, tag="20")] + CaptureVideoFrame(super::CaptureVideoFrameRequest), + #[prost(message, tag="21")] VideoConvert(super::VideoConvertRequest), /// Audio - #[prost(message, tag="22")] - NewAudioStream(super::NewAudioStreamRequest), #[prost(message, tag="23")] - NewAudioSource(super::NewAudioSourceRequest), + NewAudioStream(super::NewAudioStreamRequest), #[prost(message, tag="24")] - CaptureAudioFrame(super::CaptureAudioFrameRequest), + NewAudioSource(super::NewAudioSourceRequest), #[prost(message, tag="25")] - NewAudioResampler(super::NewAudioResamplerRequest), + CaptureAudioFrame(super::CaptureAudioFrameRequest), #[prost(message, tag="26")] - RemixAndResample(super::RemixAndResampleRequest), + NewAudioResampler(super::NewAudioResamplerRequest), #[prost(message, tag="27")] + RemixAndResample(super::RemixAndResampleRequest), + #[prost(message, tag="28")] E2ee(super::E2eeRequest), } } @@ -3087,7 +3113,7 @@ pub mod ffi_request { #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct FfiResponse { - #[prost(oneof="ffi_response::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")] + #[prost(oneof="ffi_response::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")] pub message: ::core::option::Option, } /// Nested message and enum types in `FfiResponse`. @@ -3120,21 +3146,23 @@ pub mod ffi_response { GetSessionStats(super::GetSessionStatsResponse), #[prost(message, tag="13")] PublishTranscription(super::PublishTranscriptionResponse), - /// Track #[prost(message, tag="14")] - CreateVideoTrack(super::CreateVideoTrackResponse), + GetRoomSid(super::GetRoomSidResponse), + /// Track #[prost(message, tag="15")] - CreateAudioTrack(super::CreateAudioTrackResponse), + CreateVideoTrack(super::CreateVideoTrackResponse), #[prost(message, tag="16")] + CreateAudioTrack(super::CreateAudioTrackResponse), + #[prost(message, tag="17")] GetStats(super::GetStatsResponse), /// Video - #[prost(message, tag="17")] - NewVideoStream(super::NewVideoStreamResponse), #[prost(message, tag="18")] - NewVideoSource(super::NewVideoSourceResponse), + NewVideoStream(super::NewVideoStreamResponse), #[prost(message, tag="19")] - CaptureVideoFrame(super::CaptureVideoFrameResponse), + NewVideoSource(super::NewVideoSourceResponse), #[prost(message, tag="20")] + CaptureVideoFrame(super::CaptureVideoFrameResponse), + #[prost(message, tag="21")] VideoConvert(super::VideoConvertResponse), /// Audio #[prost(message, tag="22")] @@ -3157,7 +3185,7 @@ pub mod ffi_response { #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct FfiEvent { - #[prost(oneof="ffi_event::Message", tags="1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19")] + #[prost(oneof="ffi_event::Message", tags="1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20")] pub message: ::core::option::Option, } /// Nested message and enum types in `FfiEvent`. @@ -3176,32 +3204,34 @@ pub mod ffi_event { #[prost(message, tag="5")] Connect(super::ConnectCallback), #[prost(message, tag="6")] - Disconnect(super::DisconnectCallback), + GetRoomSid(super::GetRoomSidCallback), #[prost(message, tag="7")] - Dispose(super::DisposeCallback), + Disconnect(super::DisconnectCallback), #[prost(message, tag="8")] - PublishTrack(super::PublishTrackCallback), + Dispose(super::DisposeCallback), #[prost(message, tag="9")] - UnpublishTrack(super::UnpublishTrackCallback), + PublishTrack(super::PublishTrackCallback), #[prost(message, tag="10")] - PublishData(super::PublishDataCallback), + UnpublishTrack(super::UnpublishTrackCallback), #[prost(message, tag="11")] - PublishTranscription(super::PublishTranscriptionCallback), + PublishData(super::PublishDataCallback), #[prost(message, tag="12")] - CaptureAudioFrame(super::CaptureAudioFrameCallback), + PublishTranscription(super::PublishTranscriptionCallback), #[prost(message, tag="13")] - UpdateLocalMetadata(super::SetLocalMetadataCallback), + CaptureAudioFrame(super::CaptureAudioFrameCallback), #[prost(message, tag="14")] - UpdateLocalName(super::SetLocalNameCallback), + UpdateLocalMetadata(super::SetLocalMetadataCallback), #[prost(message, tag="15")] - UpdateLocalAttributes(super::SetLocalAttributesCallback), + UpdateLocalName(super::SetLocalNameCallback), #[prost(message, tag="16")] - GetStats(super::GetStatsCallback), + UpdateLocalAttributes(super::SetLocalAttributesCallback), #[prost(message, tag="17")] - Logs(super::LogBatch), + GetStats(super::GetStatsCallback), #[prost(message, tag="18")] - GetSessionStats(super::GetSessionStatsCallback), + Logs(super::LogBatch), #[prost(message, tag="19")] + GetSessionStats(super::GetSessionStatsCallback), + #[prost(message, tag="20")] Panic(super::Panic), } } diff --git a/livekit-ffi/src/server/requests.rs b/livekit-ffi/src/server/requests.rs index 5db7947b..378ff2a0 100644 --- a/livekit-ffi/src/server/requests.rs +++ b/livekit-ffi/src/server/requests.rs @@ -22,8 +22,7 @@ use livekit::{ use parking_lot::Mutex; use super::{ - audio_source, audio_stream, colorcvt, room, - room::{FfiParticipant, FfiPublication, FfiTrack}, + audio_source, audio_stream, colorcvt, room::{self, FfiParticipant, FfiPublication, FfiRoom, FfiTrack}, video_source, video_stream, FfiError, FfiResult, FfiServer, }; use crate::proto; @@ -54,6 +53,26 @@ fn on_connect( Ok(room::FfiRoom::connect(server, connect)) } +/// Retrieve the room sid +fn on_room_sid( + server: &'static FfiServer, + req: proto::GetRoomSidRequest, +) -> FfiResult { + let async_id = server.next_id(); + let handle = server.async_runtime.spawn(async move { + let ffi_room = server + .retrieve_handle::(req.room_handle) + .unwrap() + .clone(); + let sid = ffi_room.inner.room.sid().await; + let _ = server.send_event(proto::ffi_event::Message::GetRoomSid( + proto::GetRoomSidCallback { async_id, sid: sid.to_string(), error: None }, + )); + }); + + Ok(proto::GetRoomSidResponse { async_id }) +} + /// Disconnect to a room /// This is an async function, the FfiClient must wait for the DisconnectCallback fn on_disconnect( @@ -576,6 +595,9 @@ pub fn handle_request( proto::ffi_request::Message::Connect(connect) => { proto::ffi_response::Message::Connect(on_connect(server, connect)?) } + proto::ffi_request::Message::GetRoomSid(req) => { + proto::ffi_response::Message::GetRoomSid(on_room_sid(server, req)?) + } proto::ffi_request::Message::Disconnect(disconnect) => { proto::ffi_response::Message::Disconnect(on_disconnect(server, disconnect)?) }