public void GetDHConfigAsync(int version, int randomLength, Action <TLMessagesDHConfig> callback, Action <TLRPCError> faultCallback = null) { var obj = new TLMessagesGetDHConfig { Version = version, RandomLength = randomLength }; const string caption = "messages.getDhConfig"; SendInformativeMessage(caption, obj, callback, faultCallback); }
private async void OnAnswerRequested(VoipPhoneCall sender, CallAnswerEventArgs args) { if (_phoneCall != null) { await UpdateStateAsync(TLPhoneCallState.ExchangingKeys); var reqConfig = new TLMessagesGetDHConfig { Version = 0, RandomLength = 256 }; var config = await SendRequestAsync <TLMessagesDHConfig>("messages.getDhConfig", reqConfig); if (config.IsSucceeded) { var dh = config.Result; if (!TLUtils.CheckPrime(dh.P, dh.G)) { return; } var salt = new byte[256]; var secureRandom = new SecureRandom(); secureRandom.NextBytes(salt); secretP = dh.P; a_or_b = salt; var g_b = MTProtoService.GetGB(salt, dh.G, dh.P); var request = new TLPhoneAcceptCall { GB = g_b, Peer = _phoneCall.ToInputPhoneCall(), Protocol = new TLPhoneCallProtocol { IsUdpP2p = true, IsUdpReflector = true, MinLayer = Telegram.Api.Constants.CallsMinLayer, MaxLayer = Telegram.Api.Constants.CallsMaxLayer, } }; var response = await SendRequestAsync <TLPhonePhoneCall>("phone.acceptCall", request); if (response.IsSucceeded) { _systemCall.NotifyCallActive(); Handle(new TLUpdatePhoneCall { PhoneCall = response.Result.PhoneCall }); } } } }
internal async void OutgoingCall(int userId, long accessHash) { await UpdateStateAsync(TLPhoneCallState.Requesting); var coordinator = VoipCallCoordinator.GetDefault(); var call = coordinator.RequestNewOutgoingCall("Unigram", _user.FullName, "Unigram", VoipPhoneCallMedia.Audio); _outgoing = true; _systemCall = call; _systemCall.AnswerRequested += OnAnswerRequested; _systemCall.RejectRequested += OnRejectRequested; var reqConfig = new TLMessagesGetDHConfig { Version = 0, RandomLength = 256 }; var config = await SendRequestAsync <TLMessagesDHConfig>("messages.getDhConfig", reqConfig); if (config.IsSucceeded) { var dh = config.Result; if (!TLUtils.CheckPrime(dh.P, dh.G)) { return; } var salt = new byte[256]; var secureRandom = new SecureRandom(); secureRandom.NextBytes(salt); secretP = dh.P; a_or_b = salt; g_a = MTProtoService.GetGB(salt, dh.G, dh.P); var request = new TLPhoneRequestCall { UserId = new TLInputUser { UserId = userId, AccessHash = accessHash }, RandomId = TLInt.Random(), GAHash = Utils.ComputeSHA256(g_a), Protocol = new TLPhoneCallProtocol { IsUdpP2p = true, IsUdpReflector = true, MinLayer = Telegram.Api.Constants.CallsMinLayer, MaxLayer = Telegram.Api.Constants.CallsMaxLayer, } }; var response = await SendRequestAsync <TLPhonePhoneCall>("phone.requestCall", request); if (response.IsSucceeded) { var update = new TLUpdatePhoneCall { PhoneCall = response.Result.PhoneCall }; Handle(update); await UpdateStateAsync(TLPhoneCallState.Waiting); } else { Debugger.Break(); } } }