Skip to content

Commit

Permalink
introduce get sid
Browse files Browse the repository at this point in the history
  • Loading branch information
keepingitneil committed Jul 15, 2024
1 parent b1138c0 commit b1f4828
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 76 deletions.
71 changes: 37 additions & 34 deletions livekit-ffi/protocol/ffi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
Expand All @@ -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;
}
}

Expand Down
18 changes: 17 additions & 1 deletion livekit-ffi/protocol/room.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -305,7 +321,7 @@ message RoomEvent {
}

message RoomInfo {
string sid = 1;
optional string sid = 1;
string name = 2;
string metadata = 3;
}
Expand Down
2 changes: 1 addition & 1 deletion livekit-ffi/src/conversion/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
106 changes: 68 additions & 38 deletions livekit-ffi/src/livekit.proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,30 @@ pub mod connect_callback {
pub publications: ::prost::alloc::vec::Vec<super::OwnedTrackPublication>,
}
}
// 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)]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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<ffi_request::Message>,
}
/// Nested message and enum types in `FfiRequest`.
Expand Down Expand Up @@ -3052,42 +3076,44 @@ 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),
}
}
/// This is the output of livekit_ffi_request function.
#[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<ffi_response::Message>,
}
/// Nested message and enum types in `FfiResponse`.
Expand Down Expand Up @@ -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")]
Expand All @@ -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<ffi_event::Message>,
}
/// Nested message and enum types in `FfiEvent`.
Expand All @@ -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),
}
}
Expand Down
26 changes: 24 additions & 2 deletions livekit-ffi/src/server/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<proto::GetRoomSidResponse> {
let async_id = server.next_id();
let handle = server.async_runtime.spawn(async move {
let ffi_room = server
.retrieve_handle::<FfiRoom>(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(
Expand Down Expand Up @@ -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)?)
}
Expand Down

0 comments on commit b1f4828

Please sign in to comment.