public void DiscardCallAsync(TLInputPhoneCall peer, int duration, TLPhoneCallDiscardReasonBase reason, long connectionId, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null) { var obj = new TLPhoneDiscardCall { Peer = peer, Duration = duration, Reason = reason, ConnectionId = connectionId }; const string caption = "phone.discardCall"; SendInformativeMessage <TLUpdatesBase>(caption, obj, result => { var multiPts = result as ITLMultiPts; if (multiPts != null) { _updatesService.SetState(multiPts, caption); } else { _updatesService.ProcessUpdates(result, true); } callback?.Invoke(result); }, faultCallback); }
private async void OnRejectRequested(VoipPhoneCall sender, CallRejectEventArgs args) { if (_phoneCall is TLPhoneCallRequested requested) { var req = new TLPhoneDiscardCall { Peer = new TLInputPhoneCall { Id = requested.Id, AccessHash = requested.AccessHash }, Reason = new TLPhoneCallDiscardReasonBusy() }; const string caption = "phone.discardCall"; var response = await SendRequestAsync <TLUpdatesBase>(caption, req); if (response.IsSucceeded) { if (response.Result is TLUpdates updates) { var update = updates.Updates.FirstOrDefault(x => x is TLUpdatePhoneCall) as TLUpdatePhoneCall; if (update != null) { Handle(update); } } } _systemCall.NotifyCallEnded(); } }
private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) { var deferral = args.GetDeferral(); var message = args.Request.Message; if (message.ContainsKey("update")) { var buffer = message["update"] as string; var update = TLSerializationService.Current.Deserialize(buffer) as TLUpdatePhoneCall; if (update != null) { Handle(update); } } else if (message.ContainsKey("caption")) { var caption = message["caption"] as string; if (caption.Equals("phone.discardCall")) { if (_phoneCall != null) { var buffer = message["request"] as string; var payload = TLSerializationService.Current.Deserialize <byte[]>(buffer); var reader = new TLBinaryReader(payload); var req = new TLTuple <double>(reader); reader.Dispose(); var missed = _state == TLPhoneCallState.Ringing || (_state == TLPhoneCallState.Waiting && _outgoing); var declined = _state == TLPhoneCallState.WaitingIncoming; TLPhoneCallDiscardReasonBase reason = missed ? new TLPhoneCallDiscardReasonMissed() : declined ? (TLPhoneCallDiscardReasonBase) new TLPhoneCallDiscardReasonBusy() : new TLPhoneCallDiscardReasonHangup(); var req2 = new TLPhoneDiscardCall { Peer = _phoneCall.ToInputPhoneCall(), Reason = reason, Duration = (int)req.Item1 }; const string caption2 = "phone.discardCall"; var response = await SendRequestAsync <TLUpdatesBase>(caption2, req2); if (response.IsSucceeded) { if (response.Result is TLUpdates updates) { var update = updates.Updates.FirstOrDefault(x => x is TLUpdatePhoneCall) as TLUpdatePhoneCall; if (update != null) { Handle(update); } } } } else if (_systemCall != null) { _systemCall.AnswerRequested -= OnAnswerRequested; _systemCall.RejectRequested -= OnRejectRequested; _systemCall.NotifyCallEnded(); _systemCall = null; } else if (_deferral != null) { _deferral.Complete(); } } else if (caption.Equals("phone.mute") || caption.Equals("phone.unmute")) { if (_controller != null) { _controller.SetMicMute(caption.Equals("phone.mute")); var coordinator = VoipCallCoordinator.GetDefault(); if (caption.Equals("phone.mute")) { coordinator.NotifyMuted(); } else { coordinator.NotifyUnmuted(); } } } else if (caption.Equals("voip.startCall")) { var buffer = message["request"] as string; var req = TLSerializationService.Current.Deserialize <TLUser>(buffer); _user = req; OutgoingCall(req.Id, req.AccessHash.Value); } else if (caption.Equals("voip.debugString")) { if (_controller != null) { await args.Request.SendResponseAsync(new ValueSet { { "result", _controller.GetDebugString() }, { "version", VoIPControllerWrapper.GetVersion() } }); } } } else if (message.ContainsKey("voip.callInfo")) { if (_phoneCall != null) { await args.Request.SendResponseAsync(new ValueSet { { "result", TLSerializationService.Current.Serialize(_phoneCall) } }); } else { await args.Request.SendResponseAsync(new ValueSet { { "error", false } }); } } deferral.Complete(); }
public async void Handle(TLUpdatePhoneCall update) { await VoIPConnection.Current.SendUpdateAsync(update); await Task.Delay(2000); //if (update.PhoneCall is TLPhoneCallDiscarded discarded) //{ // if (discarded.IsNeedRating) // { // Debugger.Break(); // } // if (discarded.IsNeedDebug) // { // Debugger.Break(); // } //} return; if (update.PhoneCall is TLPhoneCallRequested callRequested) { var reqReceived = new TLPhoneReceivedCall(); reqReceived.Peer = new TLInputPhoneCall(); reqReceived.Peer.Id = callRequested.Id; reqReceived.Peer.AccessHash = callRequested.AccessHash; ProtoService.SendRequestAsync <bool>("phone.receivedCall", reqReceived, null, null); var user = CacheService.GetUser(callRequested.AdminId) as TLUser; Execute.BeginOnUIThread(async() => { var dialog = await TLMessageDialog.ShowAsync(user.DisplayName, "CAAAALLL", "OK", "Cancel"); if (dialog == Windows.UI.Xaml.Controls.ContentDialogResult.Primary) { var config = await ProtoService.GetDHConfigAsync(0, 256); if (config.IsSucceeded) { var dh = config.Result; if (!TLUtils.CheckPrime(dh.P, dh.G)) { return; } secretP = dh.P; var salt = new byte[256]; var secureRandom = new SecureRandom(); secureRandom.NextBytes(salt); a_or_b = salt; var g_b = MTProtoService.GetGB(salt, dh.G, dh.P); var request = new TLPhoneAcceptCall { GB = g_b, Peer = new TLInputPhoneCall { Id = callRequested.Id, AccessHash = callRequested.AccessHash }, Protocol = new TLPhoneCallProtocol { IsUdpP2p = true, IsUdpReflector = true, MinLayer = 65, MaxLayer = 65, } }; var response = await ProtoService.SendRequestAsync <TLPhonePhoneCall>("phone.acceptCall", request); if (response.IsSucceeded) { } } } else { var req = new TLPhoneDiscardCall(); req.Peer = new TLInputPhoneCall(); req.Peer.Id = callRequested.Id; req.Peer.AccessHash = callRequested.AccessHash; req.Reason = new TLPhoneCallDiscardReasonHangup(); ProtoService.SendRequestAsync <TLPhonePhoneCall>("phone.acceptCall", req, null, null); } }); } else if (update.PhoneCall is TLPhoneCall call) { var auth_key = computeAuthKey(call); var g_a = call.GAOrB; var buffer = TLUtils.Combine(auth_key, g_a); var sha256 = Utils.ComputeSHA256(buffer); var emoji = EncryptionKeyEmojifier.EmojifyForCall(sha256); var user = CacheService.GetUser(call.AdminId) as TLUser; Execute.BeginOnUIThread(async() => { var dialog = await TLMessageDialog.ShowAsync(user.DisplayName, string.Join(" ", emoji), "OK"); }); } }