From 693333f6d29bd04f08570bb5674fa7c8c15a2e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?The=CC=81o=20Monnom?= Date: Fri, 29 Sep 2023 12:49:27 -0700 Subject: [PATCH] feat: ffi update metadata requests --- Cargo.lock | 2 +- livekit-ffi/protocol/ffi.proto | 66 ++++++++------- livekit-ffi/protocol/room.proto | 33 ++++++-- livekit-ffi/src/livekit.proto.rs | 126 ++++++++++++++++++++--------- livekit-ffi/src/server/requests.rs | 32 ++++++++ livekit-ffi/src/server/room.rs | 61 +++++++++++--- 6 files changed, 235 insertions(+), 85 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd2a47622..7b8ddd50c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1076,7 +1076,7 @@ dependencies = [ [[package]] name = "livekit-ffi" -version = "0.3.6" +version = "0.3.7" dependencies = [ "console-subscriber", "dashmap", diff --git a/livekit-ffi/protocol/ffi.proto b/livekit-ffi/protocol/ffi.proto index 62ba5d5c6..b5da4007c 100644 --- a/livekit-ffi/protocol/ffi.proto +++ b/livekit-ffi/protocol/ffi.proto @@ -64,27 +64,29 @@ message FfiRequest { UnpublishTrackRequest unpublish_track = 6; PublishDataRequest publish_data = 7; SetSubscribedRequest set_subscribed = 8; + UpdateLocalMetadataRequest update_local_metadata = 9; + UpdateLocalNameRequest update_local_name = 10; // Track - CreateVideoTrackRequest create_video_track = 9; - CreateAudioTrackRequest create_audio_track = 10; + CreateVideoTrackRequest create_video_track = 11; + CreateAudioTrackRequest create_audio_track = 12; // Video - AllocVideoBufferRequest alloc_video_buffer = 11; - NewVideoStreamRequest new_video_stream = 12; - NewVideoSourceRequest new_video_source = 13; - CaptureVideoFrameRequest capture_video_frame = 14; - ToI420Request to_i420 = 15; - ToArgbRequest to_argb = 16; + AllocVideoBufferRequest alloc_video_buffer = 13; + NewVideoStreamRequest new_video_stream = 14; + NewVideoSourceRequest new_video_source = 15; + CaptureVideoFrameRequest capture_video_frame = 16; + ToI420Request to_i420 = 17; + ToArgbRequest to_argb = 18; // Audio - AllocAudioBufferRequest alloc_audio_buffer = 17; - NewAudioStreamRequest new_audio_stream = 18; - NewAudioSourceRequest new_audio_source = 19; - CaptureAudioFrameRequest capture_audio_frame = 20; - NewAudioResamplerRequest new_audio_resampler = 21; - RemixAndResampleRequest remix_and_resample = 22; - E2eeRequest e2ee = 23; + AllocAudioBufferRequest alloc_audio_buffer = 19; + NewAudioStreamRequest new_audio_stream = 20; + NewAudioSourceRequest new_audio_source = 21; + CaptureAudioFrameRequest capture_audio_frame = 22; + NewAudioResamplerRequest new_audio_resampler = 23; + RemixAndResampleRequest remix_and_resample = 24; + E2eeRequest e2ee = 25; } } @@ -101,27 +103,29 @@ message FfiResponse { UnpublishTrackResponse unpublish_track = 6; PublishDataResponse publish_data = 7; SetSubscribedResponse set_subscribed = 8; + UpdateLocalMetadataResponse update_local_metadata = 9; + UpdateLocalNameResponse update_local_name = 10; // Track - CreateVideoTrackResponse create_video_track = 9; - CreateAudioTrackResponse create_audio_track = 10; + CreateVideoTrackResponse create_video_track = 11; + CreateAudioTrackResponse create_audio_track = 12; // Video - AllocVideoBufferResponse alloc_video_buffer = 11; - NewVideoStreamResponse new_video_stream = 12; - NewVideoSourceResponse new_video_source = 13; - CaptureVideoFrameResponse capture_video_frame = 14; - ToI420Response to_i420 = 15; - ToArgbResponse to_argb = 16; + AllocVideoBufferResponse alloc_video_buffer = 13; + NewVideoStreamResponse new_video_stream = 14; + NewVideoSourceResponse new_video_source = 15; + CaptureVideoFrameResponse capture_video_frame = 16; + ToI420Response to_i420 = 17; + ToArgbResponse to_argb = 18; // Audio - AllocAudioBufferResponse alloc_audio_buffer = 17; - NewAudioStreamResponse new_audio_stream = 18; - NewAudioSourceResponse new_audio_source = 19; - CaptureAudioFrameResponse capture_audio_frame = 20; - NewAudioResamplerResponse new_audio_resampler = 21; - RemixAndResampleResponse remix_and_resample = 22; - E2eeResponse e2ee = 23; + AllocAudioBufferResponse alloc_audio_buffer = 19; + NewAudioStreamResponse new_audio_stream = 20; + NewAudioSourceResponse new_audio_source = 21; + CaptureAudioFrameResponse capture_audio_frame = 22; + NewAudioResamplerResponse new_audio_resampler = 23; + RemixAndResampleResponse remix_and_resample = 24; + E2eeResponse e2ee = 25; } } @@ -141,6 +145,8 @@ message FfiEvent { UnpublishTrackCallback unpublish_track = 9; PublishDataCallback publish_data = 10; CaptureAudioFrameCallback capture_audio_frame = 11; + UpdateLocalMetadataCallback update_local_metadata = 12; + UpdateLocalNameCallback update_local_name = 13; } } diff --git a/livekit-ffi/protocol/room.proto b/livekit-ffi/protocol/room.proto index 5ab0672ae..4b3895d12 100644 --- a/livekit-ffi/protocol/room.proto +++ b/livekit-ffi/protocol/room.proto @@ -98,6 +98,30 @@ message PublishDataCallback { optional string error = 2; } +// Change the local participant's metadata +message UpdateLocalMetadataRequest { + uint64 local_participant_handle = 1; + string metadata = 2; +} +message UpdateLocalMetadataResponse { + uint64 async_id = 1; +} +message UpdateLocalMetadataCallback { + uint64 async_id = 1; +} + +// Change the local participant's name +message UpdateLocalNameRequest { + uint64 local_participant_handle = 1; + string name = 2; +} +message UpdateLocalNameResponse { + uint64 async_id = 1; +} +message UpdateLocalNameCallback { + uint64 async_id = 1; +} + // Change the "desire" to subs2ribe to a track message SetSubscribedRequest { bool subscribe = 1; @@ -296,20 +320,17 @@ message E2eeStateChanged { message ActiveSpeakersChanged { repeated string participant_sids = 1; } message RoomMetadataChanged { - string old_metadata = 1; - string metadata = 2; + string metadata = 1; } message ParticipantMetadataChanged { string participant_sid = 1; - string old_metadata = 2; - string metadata = 3; + string metadata = 2; } message ParticipantNameChanged { string participant_sid = 1; - string old_name = 2; - string name = 3; + string name = 2; } message ConnectionQualityChanged { diff --git a/livekit-ffi/src/livekit.proto.rs b/livekit-ffi/src/livekit.proto.rs index 229612bcb..a852d62b6 100644 --- a/livekit-ffi/src/livekit.proto.rs +++ b/livekit-ffi/src/livekit.proto.rs @@ -1165,6 +1165,48 @@ pub struct PublishDataCallback { #[prost(string, optional, tag="2")] pub error: ::core::option::Option<::prost::alloc::string::String>, } +/// Change the local participant's metadata +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct UpdateLocalMetadataRequest { + #[prost(uint64, tag="1")] + pub local_participant_handle: u64, + #[prost(string, tag="2")] + pub metadata: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct UpdateLocalMetadataResponse { + #[prost(uint64, tag="1")] + pub async_id: u64, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct UpdateLocalMetadataCallback { + #[prost(uint64, tag="1")] + pub async_id: u64, +} +/// Change the local participant's name +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct UpdateLocalNameRequest { + #[prost(uint64, tag="1")] + pub local_participant_handle: u64, + #[prost(string, tag="2")] + pub name: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct UpdateLocalNameResponse { + #[prost(uint64, tag="1")] + pub async_id: u64, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct UpdateLocalNameCallback { + #[prost(uint64, tag="1")] + pub async_id: u64, +} /// Change the "desire" to subs2ribe to a track #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -1454,8 +1496,6 @@ pub struct ActiveSpeakersChanged { #[derive(Clone, PartialEq, ::prost::Message)] pub struct RoomMetadataChanged { #[prost(string, tag="1")] - pub old_metadata: ::prost::alloc::string::String, - #[prost(string, tag="2")] pub metadata: ::prost::alloc::string::String, } #[allow(clippy::derive_partial_eq_without_eq)] @@ -1464,8 +1504,6 @@ pub struct ParticipantMetadataChanged { #[prost(string, tag="1")] pub participant_sid: ::prost::alloc::string::String, #[prost(string, tag="2")] - pub old_metadata: ::prost::alloc::string::String, - #[prost(string, tag="3")] pub metadata: ::prost::alloc::string::String, } #[allow(clippy::derive_partial_eq_without_eq)] @@ -1474,8 +1512,6 @@ pub struct ParticipantNameChanged { #[prost(string, tag="1")] pub participant_sid: ::prost::alloc::string::String, #[prost(string, tag="2")] - pub old_name: ::prost::alloc::string::String, - #[prost(string, tag="3")] pub name: ::prost::alloc::string::String, } #[allow(clippy::derive_partial_eq_without_eq)] @@ -1970,7 +2006,7 @@ impl AudioSourceType { #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct FfiRequest { - #[prost(oneof="ffi_request::Message", tags="1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23")] + #[prost(oneof="ffi_request::Message", tags="1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25")] pub message: ::core::option::Option, } /// Nested message and enum types in `FfiRequest`. @@ -1995,38 +2031,42 @@ pub mod ffi_request { PublishData(super::PublishDataRequest), #[prost(message, tag="8")] SetSubscribed(super::SetSubscribedRequest), - /// Track #[prost(message, tag="9")] - CreateVideoTrack(super::CreateVideoTrackRequest), + UpdateLocalMetadata(super::UpdateLocalMetadataRequest), #[prost(message, tag="10")] + UpdateLocalName(super::UpdateLocalNameRequest), + /// Track + #[prost(message, tag="11")] + CreateVideoTrack(super::CreateVideoTrackRequest), + #[prost(message, tag="12")] CreateAudioTrack(super::CreateAudioTrackRequest), /// Video - #[prost(message, tag="11")] + #[prost(message, tag="13")] AllocVideoBuffer(super::AllocVideoBufferRequest), - #[prost(message, tag="12")] + #[prost(message, tag="14")] NewVideoStream(super::NewVideoStreamRequest), - #[prost(message, tag="13")] + #[prost(message, tag="15")] NewVideoSource(super::NewVideoSourceRequest), - #[prost(message, tag="14")] + #[prost(message, tag="16")] CaptureVideoFrame(super::CaptureVideoFrameRequest), - #[prost(message, tag="15")] + #[prost(message, tag="17")] ToI420(super::ToI420Request), - #[prost(message, tag="16")] + #[prost(message, tag="18")] ToArgb(super::ToArgbRequest), /// Audio - #[prost(message, tag="17")] + #[prost(message, tag="19")] AllocAudioBuffer(super::AllocAudioBufferRequest), - #[prost(message, tag="18")] + #[prost(message, tag="20")] NewAudioStream(super::NewAudioStreamRequest), - #[prost(message, tag="19")] + #[prost(message, tag="21")] NewAudioSource(super::NewAudioSourceRequest), - #[prost(message, tag="20")] + #[prost(message, tag="22")] CaptureAudioFrame(super::CaptureAudioFrameRequest), - #[prost(message, tag="21")] + #[prost(message, tag="23")] NewAudioResampler(super::NewAudioResamplerRequest), - #[prost(message, tag="22")] + #[prost(message, tag="24")] RemixAndResample(super::RemixAndResampleRequest), - #[prost(message, tag="23")] + #[prost(message, tag="25")] E2ee(super::E2eeRequest), } } @@ -2034,7 +2074,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="1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23")] + #[prost(oneof="ffi_response::Message", tags="1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25")] pub message: ::core::option::Option, } /// Nested message and enum types in `FfiResponse`. @@ -2059,38 +2099,42 @@ pub mod ffi_response { PublishData(super::PublishDataResponse), #[prost(message, tag="8")] SetSubscribed(super::SetSubscribedResponse), - /// Track #[prost(message, tag="9")] - CreateVideoTrack(super::CreateVideoTrackResponse), + UpdateLocalMetadata(super::UpdateLocalMetadataResponse), #[prost(message, tag="10")] + UpdateLocalName(super::UpdateLocalNameResponse), + /// Track + #[prost(message, tag="11")] + CreateVideoTrack(super::CreateVideoTrackResponse), + #[prost(message, tag="12")] CreateAudioTrack(super::CreateAudioTrackResponse), /// Video - #[prost(message, tag="11")] + #[prost(message, tag="13")] AllocVideoBuffer(super::AllocVideoBufferResponse), - #[prost(message, tag="12")] + #[prost(message, tag="14")] NewVideoStream(super::NewVideoStreamResponse), - #[prost(message, tag="13")] + #[prost(message, tag="15")] NewVideoSource(super::NewVideoSourceResponse), - #[prost(message, tag="14")] + #[prost(message, tag="16")] CaptureVideoFrame(super::CaptureVideoFrameResponse), - #[prost(message, tag="15")] + #[prost(message, tag="17")] ToI420(super::ToI420Response), - #[prost(message, tag="16")] + #[prost(message, tag="18")] ToArgb(super::ToArgbResponse), /// Audio - #[prost(message, tag="17")] + #[prost(message, tag="19")] AllocAudioBuffer(super::AllocAudioBufferResponse), - #[prost(message, tag="18")] + #[prost(message, tag="20")] NewAudioStream(super::NewAudioStreamResponse), - #[prost(message, tag="19")] + #[prost(message, tag="21")] NewAudioSource(super::NewAudioSourceResponse), - #[prost(message, tag="20")] + #[prost(message, tag="22")] CaptureAudioFrame(super::CaptureAudioFrameResponse), - #[prost(message, tag="21")] + #[prost(message, tag="23")] NewAudioResampler(super::NewAudioResamplerResponse), - #[prost(message, tag="22")] + #[prost(message, tag="24")] RemixAndResample(super::RemixAndResampleResponse), - #[prost(message, tag="23")] + #[prost(message, tag="25")] E2ee(super::E2eeResponse), } } @@ -2100,7 +2144,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")] + #[prost(oneof="ffi_event::Message", tags="1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13")] pub message: ::core::option::Option, } /// Nested message and enum types in `FfiEvent`. @@ -2130,6 +2174,10 @@ pub mod ffi_event { PublishData(super::PublishDataCallback), #[prost(message, tag="11")] CaptureAudioFrame(super::CaptureAudioFrameCallback), + #[prost(message, tag="12")] + UpdateLocalMetadata(super::UpdateLocalMetadataCallback), + #[prost(message, tag="13")] + UpdateLocalName(super::UpdateLocalNameCallback), } } /// Setup the callback where the foreign language can receive events diff --git a/livekit-ffi/src/server/requests.rs b/livekit-ffi/src/server/requests.rs index a7be7728b..a4f710e15 100644 --- a/livekit-ffi/src/server/requests.rs +++ b/livekit-ffi/src/server/requests.rs @@ -151,6 +151,32 @@ fn on_set_subscribed( Ok(proto::SetSubscribedResponse {}) } +fn on_update_local_metadata( + server: &'static FfiServer, + update_local_metadata: proto::UpdateLocalMetadataRequest, +) -> FfiResult { + let ffi_participant = server + .retrieve_handle::(update_local_metadata.local_participant_handle)? + .clone(); + + Ok(ffi_participant + .room + .update_local_metadata(server, update_local_metadata)) +} + +fn on_update_local_name( + server: &'static FfiServer, + update_local_name: proto::UpdateLocalNameRequest, +) -> FfiResult { + let ffi_participant = server + .retrieve_handle::(update_local_name.local_participant_handle)? + .clone(); + + Ok(ffi_participant + .room + .update_local_name(server, update_local_name)) +} + /// Create a new video track from a source fn on_create_video_track( server: &'static FfiServer, @@ -622,6 +648,12 @@ pub fn handle_request( proto::ffi_request::Message::SetSubscribed(subscribed) => { proto::ffi_response::Message::SetSubscribed(on_set_subscribed(server, subscribed)?) } + proto::ffi_request::Message::UpdateLocalMetadata(u) => { + proto::ffi_response::Message::UpdateLocalMetadata(on_update_local_metadata(server, u)?) + } + proto::ffi_request::Message::UpdateLocalName(update) => { + proto::ffi_response::Message::UpdateLocalName(on_update_local_name(server, update)?) + } proto::ffi_request::Message::CreateVideoTrack(create) => { proto::ffi_response::Message::CreateVideoTrack(on_create_video_track(server, create)?) } diff --git a/livekit-ffi/src/server/room.rs b/livekit-ffi/src/server/room.rs index fb726e467..c96372f1a 100644 --- a/livekit-ffi/src/server/room.rs +++ b/livekit-ffi/src/server/room.rs @@ -330,6 +330,54 @@ impl RoomInner { proto::UnpublishTrackResponse { async_id } } + + pub fn update_local_metadata( + self: &Arc, + server: &'static FfiServer, + update_local_metadata: proto::UpdateLocalMetadataRequest, + ) -> proto::UpdateLocalMetadataResponse { + let async_id = server.next_id(); + let inner = self.clone(); + server.async_runtime.spawn(async move { + let _ = inner + .room + .local_participant() + .update_metadata(update_local_metadata.metadata) + .await; + + let _ = server + .send_event(proto::ffi_event::Message::UpdateLocalMetadata( + proto::UpdateLocalMetadataCallback { async_id }, + )) + .await; + }); + + proto::UpdateLocalMetadataResponse { async_id } + } + + pub fn update_local_name( + self: &Arc, + server: &'static FfiServer, + update_local_name: proto::UpdateLocalNameRequest, + ) -> proto::UpdateLocalNameResponse { + let async_id = server.next_id(); + let inner = self.clone(); + server.async_runtime.spawn(async move { + let _ = inner + .room + .local_participant() + .update_name(update_local_name.name) + .await; + + let _ = server + .send_event(proto::ffi_event::Message::UpdateLocalName( + proto::UpdateLocalNameCallback { async_id }, + )) + .await; + }); + + proto::UpdateLocalNameResponse { async_id } + } } // Task used to publish data without blocking the client thread @@ -618,26 +666,22 @@ async fn forward_event( .await; } RoomEvent::RoomMetadataChanged { - old_metadata, + old_metadata: _, metadata, } => { let _ = send_event(proto::room_event::Message::RoomMetadataChanged( - proto::RoomMetadataChanged { - old_metadata, - metadata, - }, + proto::RoomMetadataChanged { metadata }, )) .await; } RoomEvent::ParticipantMetadataChanged { participant, - old_metadata, + old_metadata: _, metadata, } => { let _ = send_event(proto::room_event::Message::ParticipantMetadataChanged( proto::ParticipantMetadataChanged { participant_sid: participant.sid().to_string(), - old_metadata, metadata, }, )) @@ -645,13 +689,12 @@ async fn forward_event( } RoomEvent::ParticipantNameChanged { participant, - old_name, + old_name: _, name, } => { let _ = send_event(proto::room_event::Message::ParticipantNameChanged( proto::ParticipantNameChanged { participant_sid: participant.sid().to_string(), - old_name, name, }, ))