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);
        }
Пример #2
0
        public override TLObject FromStream(Stream input)
        {
            Flags     = GetObject <TLInt>(input);
            CallId    = GetObject <TLLong>(input);
            _reason   = GetObject <TLPhoneCallDiscardReasonBase>(Flags, (int)MessageActionPhoneCallFlags.Reason, null, input);
            _duration = GetObject <TLInt>(Flags, (int)MessageActionPhoneCallFlags.Duration, null, input);

            return(this);
        }
Пример #3
0
        public override TLObject FromBytes(byte[] bytes, ref int position)
        {
            bytes.ThrowExceptionIfIncorrect(ref position, Signature);

            Flags     = GetObject <TLInt>(bytes, ref position);
            CallId    = GetObject <TLLong>(bytes, ref position);
            _reason   = GetObject <TLPhoneCallDiscardReasonBase>(Flags, (int)MessageActionPhoneCallFlags.Reason, null, bytes, ref position);
            _duration = GetObject <TLInt>(Flags, (int)MessageActionPhoneCallFlags.Duration, null, bytes, ref position);

            return(this);
        }
Пример #4
0
        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();
        }