@@ -109,6 +109,8 @@ std::optional<FfiClient::AsyncId> ExtractAsyncId(const proto::FfiEvent& event) {
109109 return event.chat_message ().async_id ();
110110 case E::kPerformRpc :
111111 return event.perform_rpc ().async_id ();
112+ case E::kNewCaptureSource :
113+ return event.new_capture_source ().async_id ();
112114
113115 // low-level data stream callbacks
114116 case E::kSendStreamHeader :
@@ -710,6 +712,49 @@ std::future<proto::OwnedTrackPublication> FfiClient::publishTrackAsync(std::uint
710712 return fut;
711713}
712714
715+ std::future<proto::OwnedCaptureSource> FfiClient::newCaptureSourceAsync (proto::NewCaptureSourceRequest request) {
716+ // Generate client-side async_id first
717+ const AsyncId async_id = generateAsyncId ();
718+
719+ // Register the async handler BEFORE sending the request
720+ auto fut = registerAsync<proto::OwnedCaptureSource>(
721+ async_id,
722+ [async_id](const proto::FfiEvent& event) {
723+ return event.has_new_capture_source () && event.new_capture_source ().async_id () == async_id;
724+ },
725+ [](const proto::FfiEvent& event, std::promise<proto::OwnedCaptureSource>& pr) {
726+ const auto & cb = event.new_capture_source ();
727+
728+ // Oneof message { string error = 2; OwnedCaptureSource source = 3; }
729+ if (cb.has_error () && !cb.error ().empty ()) {
730+ pr.set_exception (std::make_exception_ptr (std::runtime_error (cb.error ())));
731+ return ;
732+ }
733+ if (!cb.has_source ()) {
734+ pr.set_exception (std::make_exception_ptr (std::runtime_error (" NewCaptureSourceCallback missing source" )));
735+ return ;
736+ }
737+
738+ pr.set_value (cb.source ());
739+ });
740+
741+ request.set_request_async_id (async_id);
742+ proto::FfiRequest req;
743+ req.mutable_new_capture_source ()->CopyFrom (request);
744+
745+ try {
746+ const proto::FfiResponse resp = sendRequest (req);
747+ if (!resp.has_new_capture_source ()) {
748+ logAndThrow (" FfiResponse missing new_capture_source" );
749+ }
750+ } catch (...) {
751+ cancelPendingByAsyncId (async_id);
752+ throw ;
753+ }
754+
755+ return fut;
756+ }
757+
713758std::future<void > FfiClient::unpublishTrackAsync (std::uint64_t local_participant_handle, const std::string& track_sid,
714759 bool stop_on_unpublish) {
715760 // Generate client-side async_id first
0 commit comments