Skip to content

Commit 4b218a8

Browse files
authored
New FFI for data packets. Support receiving DTMF. (#319)
* New DataPacketReceived event for FFI. Pass DTMF events. * Deprecated DataReceived event.
1 parent 680870e commit 4b218a8

File tree

3 files changed

+92
-23
lines changed

3 files changed

+92
-23
lines changed

livekit-ffi/protocol/room.proto

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@ message RoomEvent {
252252
ParticipantMetadataChanged participant_metadata_changed = 15;
253253
ParticipantNameChanged participant_name_changed = 16;
254254
ConnectionQualityChanged connection_quality_changed = 17;
255-
DataReceived data_received = 18;
256255
ConnectionStateChanged connection_state_changed = 19;
257256
// Connected connected = 20;
258257
Disconnected disconnected = 21;
259258
Reconnecting reconnecting = 22;
260259
Reconnected reconnected = 23;
261260
E2eeStateChanged e2ee_state_changed = 24;
262261
RoomEOS eos = 25; // The stream of room events has ended
262+
DataPacketReceived data_packet_received = 26;
263263
}
264264
}
265265

@@ -355,11 +355,24 @@ message ConnectionQualityChanged {
355355
ConnectionQuality quality = 2;
356356
}
357357

358-
message DataReceived {
358+
message UserPacket {
359359
OwnedBuffer data = 1;
360-
optional string participant_sid = 2; // Can be empty if the data is sent a server SDK
361-
DataPacketKind kind = 3;
362-
optional string topic = 4;
360+
optional string topic = 2;
361+
}
362+
363+
message SipDTMF {
364+
uint32 code = 1;
365+
optional string digit = 2;
366+
}
367+
368+
message DataPacketReceived {
369+
DataPacketKind kind = 1;
370+
string participant_identity = 2; // Can be empty if the data is sent a server SDK
371+
optional string participant_sid = 3 [deprecated=true]; // Can be empty if the data is sent a server SDK
372+
oneof value {
373+
UserPacket user = 4;
374+
SipDTMF sip_dtmf = 5;
375+
}
363376
}
364377

365378
message ConnectionStateChanged { ConnectionState state = 1; }

livekit-ffi/src/livekit.proto.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ pub struct OwnedBuffer {
22152215
pub struct RoomEvent {
22162216
#[prost(uint64, tag="1")]
22172217
pub room_handle: u64,
2218-
#[prost(oneof="room_event::Message", tags="2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25")]
2218+
#[prost(oneof="room_event::Message", tags="2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 21, 22, 23, 24, 25, 26")]
22192219
pub message: ::core::option::Option<room_event::Message>,
22202220
}
22212221
/// Nested message and enum types in `RoomEvent`.
@@ -2255,8 +2255,6 @@ pub mod room_event {
22552255
ParticipantNameChanged(super::ParticipantNameChanged),
22562256
#[prost(message, tag="17")]
22572257
ConnectionQualityChanged(super::ConnectionQualityChanged),
2258-
#[prost(message, tag="18")]
2259-
DataReceived(super::DataReceived),
22602258
#[prost(message, tag="19")]
22612259
ConnectionStateChanged(super::ConnectionStateChanged),
22622260
/// Connected connected = 20;
@@ -2271,6 +2269,8 @@ pub mod room_event {
22712269
/// The stream of room events has ended
22722270
#[prost(message, tag="25")]
22732271
Eos(super::RoomEos),
2272+
#[prost(message, tag="26")]
2273+
DataPacketReceived(super::DataPacketReceived),
22742274
}
22752275
}
22762276
#[allow(clippy::derive_partial_eq_without_eq)]
@@ -2425,19 +2425,48 @@ pub struct ConnectionQualityChanged {
24252425
}
24262426
#[allow(clippy::derive_partial_eq_without_eq)]
24272427
#[derive(Clone, PartialEq, ::prost::Message)]
2428-
pub struct DataReceived {
2428+
pub struct UserPacket {
24292429
#[prost(message, optional, tag="1")]
24302430
pub data: ::core::option::Option<OwnedBuffer>,
2431-
/// Can be empty if the data is sent a server SDK
24322431
#[prost(string, optional, tag="2")]
2433-
pub participant_sid: ::core::option::Option<::prost::alloc::string::String>,
2434-
#[prost(enumeration="DataPacketKind", tag="3")]
2435-
pub kind: i32,
2436-
#[prost(string, optional, tag="4")]
24372432
pub topic: ::core::option::Option<::prost::alloc::string::String>,
24382433
}
24392434
#[allow(clippy::derive_partial_eq_without_eq)]
24402435
#[derive(Clone, PartialEq, ::prost::Message)]
2436+
pub struct SipDtmf {
2437+
#[prost(uint32, tag="1")]
2438+
pub code: u32,
2439+
#[prost(string, optional, tag="2")]
2440+
pub digit: ::core::option::Option<::prost::alloc::string::String>,
2441+
}
2442+
#[allow(clippy::derive_partial_eq_without_eq)]
2443+
#[derive(Clone, PartialEq, ::prost::Message)]
2444+
pub struct DataPacketReceived {
2445+
#[prost(enumeration="DataPacketKind", tag="1")]
2446+
pub kind: i32,
2447+
/// Can be empty if the data is sent a server SDK
2448+
#[prost(string, tag="2")]
2449+
pub participant_identity: ::prost::alloc::string::String,
2450+
/// Can be empty if the data is sent a server SDK
2451+
#[deprecated]
2452+
#[prost(string, optional, tag="3")]
2453+
pub participant_sid: ::core::option::Option<::prost::alloc::string::String>,
2454+
#[prost(oneof="data_packet_received::Value", tags="4, 5")]
2455+
pub value: ::core::option::Option<data_packet_received::Value>,
2456+
}
2457+
/// Nested message and enum types in `DataPacketReceived`.
2458+
pub mod data_packet_received {
2459+
#[allow(clippy::derive_partial_eq_without_eq)]
2460+
#[derive(Clone, PartialEq, ::prost::Oneof)]
2461+
pub enum Value {
2462+
#[prost(message, tag="4")]
2463+
User(super::UserPacket),
2464+
#[prost(message, tag="5")]
2465+
SipDtmf(super::SipDtmf),
2466+
}
2467+
}
2468+
#[allow(clippy::derive_partial_eq_without_eq)]
2469+
#[derive(Clone, PartialEq, ::prost::Message)]
24412470
pub struct ConnectionStateChanged {
24422471
#[prost(enumeration="ConnectionState", tag="1")]
24432472
pub state: i32,

livekit-ffi/src/server/room.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use std::{collections::HashSet, slice, sync::Arc, time::Duration};
1616

17+
use livekit::participant;
1718
use livekit::prelude::*;
1819
use parking_lot::Mutex;
1920
use tokio::sync::{broadcast, mpsc, oneshot, Mutex as AsyncMutex};
@@ -645,17 +646,43 @@ async fn forward_event(
645646
data_ptr: payload.as_ptr() as u64,
646647
data_len: payload.len() as u64,
647648
};
649+
let (sid, identity) = match participant {
650+
Some(p) => (Some(p.sid().to_string()), p.identity().to_string()),
651+
None => (None, String::new()),
652+
};
648653

649654
server.store_handle(handle_id, FfiDataBuffer { handle: handle_id, data: payload });
650-
let _ = send_event(proto::room_event::Message::DataReceived(proto::DataReceived {
651-
data: Some(proto::OwnedBuffer {
652-
handle: Some(proto::FfiOwnedHandle { id: handle_id }),
653-
data: Some(buffer_info),
654-
}),
655-
participant_sid: participant.map(|p| p.sid().to_string()),
656-
kind: proto::DataPacketKind::from(kind).into(),
657-
topic,
658-
}));
655+
let _ = send_event(proto::room_event::Message::DataPacketReceived(
656+
proto::DataPacketReceived {
657+
value: Some(proto::data_packet_received::Value::User(proto::UserPacket {
658+
data: Some(proto::OwnedBuffer {
659+
handle: Some(proto::FfiOwnedHandle { id: handle_id }),
660+
data: Some(buffer_info),
661+
}),
662+
topic,
663+
})),
664+
participant_identity: identity,
665+
participant_sid: sid,
666+
kind: proto::DataPacketKind::from(kind).into(),
667+
},
668+
));
669+
}
670+
RoomEvent::SipDTMFReceived { code, digit, participant } => {
671+
let (sid, identity) = match participant {
672+
Some(p) => (Some(p.sid().to_string()), p.identity().to_string()),
673+
None => (None, String::new()),
674+
};
675+
let _ = send_event(proto::room_event::Message::DataPacketReceived(
676+
proto::DataPacketReceived {
677+
value: Some(proto::data_packet_received::Value::SipDtmf(proto::SipDtmf {
678+
code,
679+
digit,
680+
})),
681+
participant_identity: identity,
682+
participant_sid: sid,
683+
kind: proto::DataPacketKind::KindReliable.into(),
684+
},
685+
));
659686
}
660687
RoomEvent::ConnectionStateChanged(state) => {
661688
let _ = send_event(proto::room_event::Message::ConnectionStateChanged(

0 commit comments

Comments
 (0)