Skip to content

Commit 7044ba5

Browse files
Add chat API (#436)
* Add chat APIs - wip * generated protobuf * updates * fix types and build * Add conversion traits and update API * fix unwrapping * Populate timestamps and add edit support * fix default values * generated protobuf * fix match * remove explicit resolver * move conversion * error handling * no imports --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 9378fae commit 7044ba5

File tree

14 files changed

+452
-16
lines changed

14 files changed

+452
-16
lines changed

Cargo.lock

Lines changed: 55 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

livekit-ffi/protocol/ffi.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ message FfiRequest {
9696
NewSoxResamplerRequest new_sox_resampler = 33;
9797
PushSoxResamplerRequest push_sox_resampler = 34;
9898
FlushSoxResamplerRequest flush_sox_resampler = 35;
99+
100+
SendChatMessageRequest send_chat_message = 36;
101+
EditChatMessageRequest edit_chat_message = 37;
99102
}
100103
}
101104

@@ -144,6 +147,8 @@ message FfiResponse {
144147
NewSoxResamplerResponse new_sox_resampler = 33;
145148
PushSoxResamplerResponse push_sox_resampler = 34;
146149
FlushSoxResamplerResponse flush_sox_resampler = 35;
150+
151+
SendChatMessageResponse send_chat_message = 36;
147152
}
148153
}
149154

@@ -172,6 +177,7 @@ message FfiEvent {
172177
GetSessionStatsCallback get_session_stats = 19;
173178
Panic panic = 20;
174179
PublishSipDtmfCallback publish_sip_dtmf = 21;
180+
SendChatMessageCallback chat_message = 22;
175181
}
176182
}
177183

livekit-ffi/protocol/room.proto

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,28 @@ message SetLocalMetadataCallback {
144144
optional string error = 2;
145145
}
146146

147+
message SendChatMessageRequest {
148+
uint64 local_participant_handle = 1;
149+
string message = 2;
150+
repeated string destination_identities = 3;
151+
optional string sender_identity = 4;
152+
}
153+
message EditChatMessageRequest {
154+
uint64 local_participant_handle = 1;
155+
string edit_text = 2;
156+
ChatMessage original_message = 3;
157+
repeated string destination_identities = 4;
158+
optional string sender_identity = 5;
159+
}
160+
message SendChatMessageResponse {
161+
uint64 async_id = 1;
162+
}
163+
message SendChatMessageCallback {
164+
uint64 async_id = 1;
165+
optional string error = 2;
166+
optional ChatMessage chat_message = 3;
167+
}
168+
147169
// Change the local participant's attributes
148170
message SetLocalAttributesRequest {
149171
uint64 local_participant_handle = 1;
@@ -343,6 +365,7 @@ message RoomEvent {
343365
RoomEOS eos = 26; // The stream of room events has ended
344366
DataPacketReceived data_packet_received = 27;
345367
TranscriptionReceived transcription_received = 28;
368+
ChatMessageReceived chat_message = 29;
346369
}
347370
}
348371

@@ -457,6 +480,20 @@ message UserPacket {
457480
optional string topic = 2;
458481
}
459482

483+
message ChatMessage {
484+
string id = 1;
485+
int64 timestamp = 2;
486+
string message = 3;
487+
optional int64 edit_timestamp = 4;
488+
optional bool deleted = 5;
489+
optional bool generated = 6;
490+
}
491+
492+
message ChatMessageReceived {
493+
ChatMessage message = 1;
494+
string participant_identity = 2;
495+
}
496+
460497
message SipDTMF {
461498
uint32 code = 1;
462499
optional string digit = 2;

livekit-ffi/src/conversion/room.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use crate::{proto, server::room::FfiRoom};
1516
use livekit::{
1617
e2ee::{
1718
key_provider::{KeyProvider, KeyProviderOptions},
@@ -25,8 +26,6 @@ use livekit::{
2526
},
2627
};
2728

28-
use crate::{proto, server::room::FfiRoom};
29-
3029
impl From<EncryptionState> for proto::EncryptionState {
3130
fn from(value: EncryptionState) -> Self {
3231
match value {
@@ -241,3 +240,29 @@ impl From<&FfiRoom> for proto::RoomInfo {
241240
}
242241
}
243242
}
243+
244+
impl From<proto::ChatMessage> for livekit::ChatMessage {
245+
fn from(proto_msg: proto::ChatMessage) -> Self {
246+
livekit::ChatMessage {
247+
id: proto_msg.id,
248+
message: proto_msg.message,
249+
timestamp: proto_msg.timestamp,
250+
edit_timestamp: proto_msg.edit_timestamp,
251+
deleted: proto_msg.deleted,
252+
generated: proto_msg.generated,
253+
}
254+
}
255+
}
256+
257+
impl From<livekit::ChatMessage> for proto::ChatMessage {
258+
fn from(msg: livekit::ChatMessage) -> Self {
259+
proto::ChatMessage {
260+
id: msg.id,
261+
message: msg.message,
262+
timestamp: msg.timestamp,
263+
edit_timestamp: msg.edit_timestamp,
264+
deleted: msg.deleted.into(),
265+
generated: msg.generated.into(),
266+
}
267+
}
268+
}

livekit-ffi/src/livekit.proto.rs

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,48 @@ pub struct SetLocalMetadataCallback {
22102210
#[prost(string, optional, tag="2")]
22112211
pub error: ::core::option::Option<::prost::alloc::string::String>,
22122212
}
2213+
#[allow(clippy::derive_partial_eq_without_eq)]
2214+
#[derive(Clone, PartialEq, ::prost::Message)]
2215+
pub struct SendChatMessageRequest {
2216+
#[prost(uint64, tag="1")]
2217+
pub local_participant_handle: u64,
2218+
#[prost(string, tag="2")]
2219+
pub message: ::prost::alloc::string::String,
2220+
#[prost(string, repeated, tag="3")]
2221+
pub destination_identities: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
2222+
#[prost(string, optional, tag="4")]
2223+
pub sender_identity: ::core::option::Option<::prost::alloc::string::String>,
2224+
}
2225+
#[allow(clippy::derive_partial_eq_without_eq)]
2226+
#[derive(Clone, PartialEq, ::prost::Message)]
2227+
pub struct EditChatMessageRequest {
2228+
#[prost(uint64, tag="1")]
2229+
pub local_participant_handle: u64,
2230+
#[prost(string, tag="2")]
2231+
pub edit_text: ::prost::alloc::string::String,
2232+
#[prost(message, optional, tag="3")]
2233+
pub original_message: ::core::option::Option<ChatMessage>,
2234+
#[prost(string, repeated, tag="4")]
2235+
pub destination_identities: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
2236+
#[prost(string, optional, tag="5")]
2237+
pub sender_identity: ::core::option::Option<::prost::alloc::string::String>,
2238+
}
2239+
#[allow(clippy::derive_partial_eq_without_eq)]
2240+
#[derive(Clone, PartialEq, ::prost::Message)]
2241+
pub struct SendChatMessageResponse {
2242+
#[prost(uint64, tag="1")]
2243+
pub async_id: u64,
2244+
}
2245+
#[allow(clippy::derive_partial_eq_without_eq)]
2246+
#[derive(Clone, PartialEq, ::prost::Message)]
2247+
pub struct SendChatMessageCallback {
2248+
#[prost(uint64, tag="1")]
2249+
pub async_id: u64,
2250+
#[prost(string, optional, tag="2")]
2251+
pub error: ::core::option::Option<::prost::alloc::string::String>,
2252+
#[prost(message, optional, tag="3")]
2253+
pub chat_message: ::core::option::Option<ChatMessage>,
2254+
}
22132255
/// Change the local participant's attributes
22142256
#[allow(clippy::derive_partial_eq_without_eq)]
22152257
#[derive(Clone, PartialEq, ::prost::Message)]
@@ -2407,7 +2449,7 @@ pub struct OwnedBuffer {
24072449
pub struct RoomEvent {
24082450
#[prost(uint64, tag="1")]
24092451
pub room_handle: u64,
2410-
#[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")]
2452+
#[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")]
24112453
pub message: ::core::option::Option<room_event::Message>,
24122454
}
24132455
/// Nested message and enum types in `RoomEvent`.
@@ -2471,6 +2513,8 @@ pub mod room_event {
24712513
DataPacketReceived(super::DataPacketReceived),
24722514
#[prost(message, tag="28")]
24732515
TranscriptionReceived(super::TranscriptionReceived),
2516+
#[prost(message, tag="29")]
2517+
ChatMessage(super::ChatMessageReceived),
24742518
}
24752519
}
24762520
#[allow(clippy::derive_partial_eq_without_eq)]
@@ -2655,6 +2699,30 @@ pub struct UserPacket {
26552699
}
26562700
#[allow(clippy::derive_partial_eq_without_eq)]
26572701
#[derive(Clone, PartialEq, ::prost::Message)]
2702+
pub struct ChatMessage {
2703+
#[prost(string, tag="1")]
2704+
pub id: ::prost::alloc::string::String,
2705+
#[prost(int64, tag="2")]
2706+
pub timestamp: i64,
2707+
#[prost(string, tag="3")]
2708+
pub message: ::prost::alloc::string::String,
2709+
#[prost(int64, optional, tag="4")]
2710+
pub edit_timestamp: ::core::option::Option<i64>,
2711+
#[prost(bool, optional, tag="5")]
2712+
pub deleted: ::core::option::Option<bool>,
2713+
#[prost(bool, optional, tag="6")]
2714+
pub generated: ::core::option::Option<bool>,
2715+
}
2716+
#[allow(clippy::derive_partial_eq_without_eq)]
2717+
#[derive(Clone, PartialEq, ::prost::Message)]
2718+
pub struct ChatMessageReceived {
2719+
#[prost(message, optional, tag="1")]
2720+
pub message: ::core::option::Option<ChatMessage>,
2721+
#[prost(string, tag="2")]
2722+
pub participant_identity: ::prost::alloc::string::String,
2723+
}
2724+
#[allow(clippy::derive_partial_eq_without_eq)]
2725+
#[derive(Clone, PartialEq, ::prost::Message)]
26582726
pub struct SipDtmf {
26592727
#[prost(uint32, tag="1")]
26602728
pub code: u32,
@@ -3443,7 +3511,7 @@ impl AudioSourceType {
34433511
#[allow(clippy::derive_partial_eq_without_eq)]
34443512
#[derive(Clone, PartialEq, ::prost::Message)]
34453513
pub struct FfiRequest {
3446-
#[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, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35")]
3514+
#[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, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37")]
34473515
pub message: ::core::option::Option<ffi_request::Message>,
34483516
}
34493517
/// Nested message and enum types in `FfiRequest`.
@@ -3523,13 +3591,17 @@ pub mod ffi_request {
35233591
PushSoxResampler(super::PushSoxResamplerRequest),
35243592
#[prost(message, tag="35")]
35253593
FlushSoxResampler(super::FlushSoxResamplerRequest),
3594+
#[prost(message, tag="36")]
3595+
SendChatMessage(super::SendChatMessageRequest),
3596+
#[prost(message, tag="37")]
3597+
EditChatMessage(super::EditChatMessageRequest),
35263598
}
35273599
}
35283600
/// This is the output of livekit_ffi_request function.
35293601
#[allow(clippy::derive_partial_eq_without_eq)]
35303602
#[derive(Clone, PartialEq, ::prost::Message)]
35313603
pub struct FfiResponse {
3532-
#[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, 28, 29, 30, 31, 32, 33, 34, 35")]
3604+
#[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, 28, 29, 30, 31, 32, 33, 34, 35, 36")]
35333605
pub message: ::core::option::Option<ffi_response::Message>,
35343606
}
35353607
/// Nested message and enum types in `FfiResponse`.
@@ -3609,6 +3681,8 @@ pub mod ffi_response {
36093681
PushSoxResampler(super::PushSoxResamplerResponse),
36103682
#[prost(message, tag="35")]
36113683
FlushSoxResampler(super::FlushSoxResamplerResponse),
3684+
#[prost(message, tag="36")]
3685+
SendChatMessage(super::SendChatMessageResponse),
36123686
}
36133687
}
36143688
/// To minimize complexity, participant events are not included in the protocol.
@@ -3617,7 +3691,7 @@ pub mod ffi_response {
36173691
#[allow(clippy::derive_partial_eq_without_eq)]
36183692
#[derive(Clone, PartialEq, ::prost::Message)]
36193693
pub struct FfiEvent {
3620-
#[prost(oneof="ffi_event::Message", tags="1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21")]
3694+
#[prost(oneof="ffi_event::Message", tags="1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22")]
36213695
pub message: ::core::option::Option<ffi_event::Message>,
36223696
}
36233697
/// Nested message and enum types in `FfiEvent`.
@@ -3665,6 +3739,8 @@ pub mod ffi_event {
36653739
Panic(super::Panic),
36663740
#[prost(message, tag="21")]
36673741
PublishSipDtmf(super::PublishSipDtmfCallback),
3742+
#[prost(message, tag="22")]
3743+
ChatMessage(super::SendChatMessageCallback),
36683744
}
36693745
}
36703746
/// Stop all rooms synchronously (Do we need async here?).

0 commit comments

Comments
 (0)