Skip to content

Commit dce5aa7

Browse files
committed
Implement FFI bindings
1 parent d621a50 commit dce5aa7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

livekit-ffi/src/server/participant.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ impl FfiParticipant {
177177
Ok(proto::StreamSendTextResponse { async_id })
178178
}
179179

180+
pub fn send_bytes(
181+
&self,
182+
server: &'static FfiServer,
183+
request: proto::StreamSendBytesRequest,
184+
) -> FfiResult<proto::StreamSendBytesResponse> {
185+
let async_id = server.next_id();
186+
let local = self.guard_local_participant()?;
187+
188+
let handle = server.async_runtime.spawn(async move {
189+
let result = match local.send_bytes(&request.bytes, request.options.into()).await {
190+
Ok(info) => proto::stream_send_bytes_callback::Result::Info(info.into()),
191+
Err(err) => proto::stream_send_bytes_callback::Result::Error(err.into()),
192+
};
193+
let callback = proto::StreamSendBytesCallback { async_id, result: Some(result) };
194+
let _ = server.send_event(proto::ffi_event::Message::SendBytes(callback));
195+
});
196+
server.watch_panic(handle);
197+
Ok(proto::StreamSendBytesResponse { async_id })
198+
}
199+
180200
pub fn stream_bytes(
181201
&self,
182202
server: &'static FfiServer,

livekit-ffi/src/server/requests.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,15 @@ fn on_send_file(
11001100
ffi_participant.send_file(server, request)
11011101
}
11021102

1103+
fn on_send_bytes(
1104+
server: &'static FfiServer,
1105+
request: proto::StreamSendBytesRequest,
1106+
) -> FfiResult<proto::StreamSendBytesResponse> {
1107+
let ffi_participant =
1108+
server.retrieve_handle::<FfiParticipant>(request.local_participant_handle)?.clone();
1109+
ffi_participant.send_bytes(server, request)
1110+
}
1111+
11031112
fn on_send_text(
11041113
server: &'static FfiServer,
11051114
request: proto::StreamSendTextRequest,
@@ -1383,6 +1392,9 @@ pub fn handle_request(
13831392
proto::ffi_request::Message::SendFile(request) => {
13841393
proto::ffi_response::Message::SendFile(on_send_file(server, request)?)
13851394
}
1395+
proto::ffi_request::Message::SendBytes(request) => {
1396+
proto::ffi_response::Message::SendBytes(on_send_bytes(server, request)?)
1397+
}
13861398
proto::ffi_request::Message::SendText(request) => {
13871399
proto::ffi_response::Message::SendText(on_send_text(server, request)?)
13881400
}

0 commit comments

Comments
 (0)