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