diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 092bfa069..19e6f291c 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4066,6 +4066,9 @@ createCall user_id:int32 protocol:callProtocol is_video:Bool = CallId; //@description Accepts an incoming call @call_id Call identifier @protocol Description of the call protocols supported by the application acceptCall call_id:int32 protocol:callProtocol = Ok; +//@description Sends call signaling data @call_id Call identifier @data The data +sendCallSignalingData call_id:int32 data:bytes = Ok; + //@description Discards a call @call_id Call identifier @is_disconnected True, if the user was disconnected @duration The call duration, in seconds @is_video True, if the call was a video call @connection_id Identifier of the connection used during the call discardCall call_id:int32 is_disconnected:Bool duration:int32 is_video:Bool connection_id:int64 = Ok; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 4b4cffa7f..2f6476222 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/CallActor.cpp b/td/telegram/CallActor.cpp index c3bd5523f..a05e80c8d 100644 --- a/td/telegram/CallActor.cpp +++ b/td/telegram/CallActor.cpp @@ -131,6 +131,16 @@ void CallActor::create_call(UserId user_id, tl_object_ptr promise) { + if (state_ != State::SendAcceptQuery) { + return promise.set_error(Status::Error(400, "Unexpected acceptCall")); + } + is_accepted_ = true; + call_state_.protocol = std::move(protocol); + promise.set_value(Unit()); + loop(); +} + void CallActor::update_call_signaling_data(string data) { if (call_state_.type != CallState::Type::Ready) { return; @@ -142,6 +152,24 @@ void CallActor::update_call_signaling_data(string data) { send_closure(G()->td(), &Td::send_update, std::move(update)); } +void CallActor::send_call_signaling_data(string &&data, Promise<> promise) { + if (call_state_.type != CallState::Type::Ready) { + return promise.set_error(Status::Error(400, "Call is not active")); + } + + auto query = G()->net_query_creator().create( + telegram_api::phone_sendSignalingData(get_input_phone_call("send_call_signaling_data"), BufferSlice(data))); + send_with_promise(std::move(query), + PromiseCreator::lambda([promise = std::move(promise)](NetQueryPtr net_query) mutable { + auto res = fetch_result(std::move(net_query)); + if (res.is_error()) { + promise.set_error(res.move_as_error()); + } else { + promise.set_value(Unit()); + } + })); +} + void CallActor::discard_call(bool is_disconnected, int32 duration, bool is_video, int64 connection_id, Promise<> promise) { promise.set_value(Unit()); @@ -187,16 +215,6 @@ void CallActor::discard_call(bool is_disconnected, int32 duration, bool is_video loop(); } -void CallActor::accept_call(CallProtocol &&protocol, Promise<> promise) { - if (state_ != State::SendAcceptQuery) { - return promise.set_error(Status::Error(400, "Unexpected acceptCall")); - } - is_accepted_ = true; - call_state_.protocol = std::move(protocol); - promise.set_value(Unit()); - loop(); -} - void CallActor::rate_call(int32 rating, string comment, vector> &&problems, Promise<> promise) { if (!call_state_.need_rating) { diff --git a/td/telegram/CallActor.h b/td/telegram/CallActor.h index 589696561..d6ffdfc00 100644 --- a/td/telegram/CallActor.h +++ b/td/telegram/CallActor.h @@ -87,9 +87,10 @@ class CallActor : public NetQueryCallback { void create_call(UserId user_id, tl_object_ptr &&input_user, CallProtocol &&protocol, bool is_video, Promise &&promise); - void update_call_signaling_data(string data); - void discard_call(bool is_disconnected, int32 duration, bool is_video, int64 connection_id, Promise<> promise); void accept_call(CallProtocol &&protocol, Promise<> promise); + void update_call_signaling_data(string data); + void send_call_signaling_data(string &&data, Promise<> promise); + void discard_call(bool is_disconnected, int32 duration, bool is_video, int64 connection_id, Promise<> promise); void rate_call(int32 rating, string comment, vector> &&problems, Promise<> promise); void send_call_debug_information(string data, Promise<> promise); diff --git a/td/telegram/CallManager.cpp b/td/telegram/CallManager.cpp index 8e0dafe42..1900b2c01 100644 --- a/td/telegram/CallManager.cpp +++ b/td/telegram/CallManager.cpp @@ -68,6 +68,22 @@ void CallManager::create_call(UserId user_id, tl_object_ptr promise) { + auto actor = get_call_actor(call_id); + if (actor.empty()) { + return promise.set_error(Status::Error(400, "Call not found")); + } + send_closure(actor, &CallActor::accept_call, std::move(protocol), std::move(promise)); +} + +void CallManager::send_call_signaling_data(CallId call_id, string &&data, Promise<> promise) { + auto actor = get_call_actor(call_id); + if (actor.empty()) { + return promise.set_error(Status::Error(400, "Call not found")); + } + send_closure(actor, &CallActor::send_call_signaling_data, std::move(data), std::move(promise)); +} + void CallManager::discard_call(CallId call_id, bool is_disconnected, int32 duration, bool is_video, int64 connection_id, Promise<> promise) { auto actor = get_call_actor(call_id); @@ -77,14 +93,6 @@ void CallManager::discard_call(CallId call_id, bool is_disconnected, int32 durat send_closure(actor, &CallActor::discard_call, is_disconnected, duration, is_video, connection_id, std::move(promise)); } -void CallManager::accept_call(CallId call_id, CallProtocol &&protocol, Promise<> promise) { - auto actor = get_call_actor(call_id); - if (actor.empty()) { - return promise.set_error(Status::Error(400, "Call not found")); - } - send_closure(actor, &CallActor::accept_call, std::move(protocol), std::move(promise)); -} - void CallManager::rate_call(CallId call_id, int32 rating, string comment, vector> &&problems, Promise<> promise) { auto actor = get_call_actor(call_id); diff --git a/td/telegram/CallManager.h b/td/telegram/CallManager.h index 3a261967b..a4cfe50f3 100644 --- a/td/telegram/CallManager.h +++ b/td/telegram/CallManager.h @@ -31,9 +31,10 @@ class CallManager : public Actor { void create_call(UserId user_id, tl_object_ptr &&input_user, CallProtocol &&protocol, bool is_video, Promise promise); + void accept_call(CallId call_id, CallProtocol &&protocol, Promise<> promise); + void send_call_signaling_data(CallId call_id, string &&data, Promise<> promise); void discard_call(CallId call_id, bool is_disconnected, int32 duration, bool is_video, int64 connection_id, Promise<> promise); - void accept_call(CallId call_id, CallProtocol &&protocol, Promise<> promise); void rate_call(CallId call_id, int32 rating, string comment, vector> &&problems, Promise<> promise); void send_call_debug_information(CallId call_id, string data, Promise<> promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index f631cfb98..4df5c772a 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5817,7 +5817,7 @@ void Td::on_request(uint64 id, td_api::createNewSecretChat &request) { CREATE_REQUEST(CreateNewSecretChatRequest, request.user_id_); } -void Td::on_request(uint64 id, td_api::createCall &request) { +void Td::on_request(uint64 id, const td_api::createCall &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result result) mutable { @@ -5846,14 +5846,7 @@ void Td::on_request(uint64 id, td_api::createCall &request) { CallProtocol(*request.protocol_), request.is_video_, std::move(query_promise)); } -void Td::on_request(uint64 id, td_api::discardCall &request) { - CHECK_IS_USER(); - CREATE_OK_REQUEST_PROMISE(); - send_closure(G()->call_manager(), &CallManager::discard_call, CallId(request.call_id_), request.is_disconnected_, - request.duration_, request.is_video_, request.connection_id_, std::move(promise)); -} - -void Td::on_request(uint64 id, td_api::acceptCall &request) { +void Td::on_request(uint64 id, const td_api::acceptCall &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); if (!request.protocol_) { @@ -5863,6 +5856,20 @@ void Td::on_request(uint64 id, td_api::acceptCall &request) { CallProtocol(*request.protocol_), std::move(promise)); } +void Td::on_request(uint64 id, td_api::sendCallSignalingData &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + send_closure(G()->call_manager(), &CallManager::send_call_signaling_data, CallId(request.call_id_), + std::move(request.data_), std::move(promise)); +} + +void Td::on_request(uint64 id, const td_api::discardCall &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + send_closure(G()->call_manager(), &CallManager::discard_call, CallId(request.call_id_), request.is_disconnected_, + request.duration_, request.is_video_, request.connection_id_, std::move(promise)); +} + void Td::on_request(uint64 id, td_api::sendCallRating &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.comment_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 9d75302aa..e87d2a14f 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -663,11 +663,13 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::createNewSecretChat &request); - void on_request(uint64 id, td_api::createCall &request); + void on_request(uint64 id, const td_api::createCall &request); - void on_request(uint64 id, td_api::discardCall &request); + void on_request(uint64 id, const td_api::acceptCall &request); - void on_request(uint64 id, td_api::acceptCall &request); + void on_request(uint64 id, td_api::sendCallSignalingData &request); + + void on_request(uint64 id, const td_api::discardCall &request); void on_request(uint64 id, td_api::sendCallRating &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 419ad7724..bc91bad7b 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2732,6 +2732,11 @@ class CliClient final : public Actor { send_request(td_api::make_object( as_user_id(args), td_api::make_object(true, true, 65, 65, vector{"2.6"}), Random::fast(0, 1) == 1)); + } else if (op == "ac" || op == "AcceptCall") { + send_request(td_api::make_object( + as_call_id(args), td_api::make_object(true, true, 65, 65, vector{"2.6"}))); + } else if (op == "scsd") { + send_request(td_api::make_object(as_call_id(args), "abacaba")); } else if (op == "dc" || op == "DiscardCall") { string call_id; string is_disconnected; @@ -2739,9 +2744,6 @@ class CliClient final : public Actor { send_request(td_api::make_object(as_call_id(call_id), as_bool(is_disconnected), 0, Random::fast(0, 1) == 1, 0)); - } else if (op == "ac" || op == "AcceptCall") { - send_request(td_api::make_object( - as_call_id(args), td_api::make_object(true, true, 65, 65, vector{"2.6"}))); } else if (op == "scr" || op == "SendCallRating") { string call_id; string rating;