Exemplo n.º 1
0
 public void DelSession(MySipSession session)
 {
     try
     {
         if (this.sessions.Contains(session))
         {
             this.sessions.Remove(session);
         }
         this.dicSidIdx.Remove(session.Id);
         if (this.dicUidIdx.ContainsKey(session.RemotePartyUri))
         {
             this.dicSidIdx.Remove(session.Id);
             this.dicUidIdx[session.RemotePartyUri].Remove(session);
         }
     }
     catch (System.Exception e_7D)
     {
     }
 }
Exemplo n.º 2
0
 public void AddSession(long sessionId, MySipSession session)
 {
     try
     {
         this.sessions.Add(session);
         this.dicSidIdx.Add(sessionId, session);
         if (!this.dicUidIdx.ContainsKey(session.RemotePartyUri))
         {
             System.Collections.Generic.List <MySipSession> sessionList = new System.Collections.Generic.List <MySipSession>();
             sessionList.Add(session);
             this.dicUidIdx.Add(session.RemotePartyUri, sessionList);
         }
         else
         {
             this.dicUidIdx[session.RemotePartyUri].Add(session);
         }
     }
     catch (System.Exception e_74)
     {
     }
 }
Exemplo n.º 3
0
        public void OnAvSessionCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (object item in e.NewItems)
                {
                    MySipSession  hisSession = item as MySipSession;
                    AVCallHistory HisCall    = new AVCallHistory(false, hisSession.RemotePartyUri, hisSession.Id, hisSession.IsOutgoing, false);
                    HisCall.StartTime = System.DateTime.Now;
                    HisCall.EndTime   = System.DateTime.Now;
                    this.avHistories.Add(HisCall);
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (object item in e.OldItems)
                {
                    MySipSession  hisSession = item as MySipSession;
                    AVCallHistory cr         = new AVCallHistory(false, hisSession.Time, System.DateTime.Now, hisSession.RemotePartyUri, hisSession.Id, hisSession.IsOutgoing, hisSession.IsConnected);
                    for (int i = 0; i < this.avHistories.Count; i++)
                    {
                        if (this.avHistories[i].SipSessionId == hisSession.Id)
                        {
                            this.avHistories.Remove(this.avHistories[i]);
                            this.avHistories.Add(cr);
                        }
                    }
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                this.avHistories.Clear();
                break;
            }
        }
Exemplo n.º 4
0
            /// <summary>
            /// Dialog events (Common to all)
            /// </summary>
            /// <param name="e"></param>
            /// <returns></returns>
            public override int OnDialogEvent(DialogEvent e)
            {
                String     phrase  = e.getPhrase();
                short      code    = e.getCode();
                SipSession session = e.getBaseSession();

                if (session == null)
                {
                    return(0);
                }

                uint         sessionId = session.getId();
                MySipSession mySession = null;

                SipService.LOG.Info(String.Format("OnDialogEvent ({0})", phrase));

                if (code == tinyWRAP.tsip_event_code_dialog_connecting)
                {
                    // Registration
                    if (this.sipService.regSession != null && this.sipService.regSession.Id == sessionId)
                    {
                        EventHandlerTrigger.TriggerEvent <RegistrationEventArgs>(this.sipService.onRegistrationEvent, this.sipService,
                                                                                 new RegistrationEventArgs(RegistrationEventTypes.REGISTRATION_INPROGRESS, code, phrase));
                    }
                    // Audio/Video/MSRP
                    else if (((mySession = MyAVSession.GetSession(sessionId)) != null) || ((mySession = MyMsrpSession.GetSession(sessionId)) != null))
                    {
                        (mySession as MyInviteSession).State = MyInviteSession.InviteState.INPROGRESS;
                        InviteEventArgs eargs = new InviteEventArgs(sessionId, InviteEventTypes.INPROGRESS, phrase);
                        eargs.AddExtra(InviteEventArgs.EXTRA_SESSION, mySession);
                        EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, eargs);
                    }

                    // Subscription

                    // Publication
                }


                else if (code == tinyWRAP.tsip_event_code_dialog_connected)
                {
                    // Registration
                    if (this.sipService.regSession != null && this.sipService.regSession.Id == sessionId)
                    {
                        this.sipService.regSession.IsConnected = true;
                        // Update default identity (vs barred)
                        String _defaultIdentity = this.sipService.SipStack.getPreferredIdentity();
                        if (!String.IsNullOrEmpty(_defaultIdentity))
                        {
                            this.sipService.defaultIdentity = _defaultIdentity;
                        }
                        // Do PostRegistrationOp() in new thread to avoid blocking callbacks
                        new Thread(new ThreadStart(delegate
                        {
                            this.sipService.DoPostRegistrationOp();
                        }))
                        .Start();
                        EventHandlerTrigger.TriggerEvent <RegistrationEventArgs>(this.sipService.onRegistrationEvent, this.sipService,
                                                                                 new RegistrationEventArgs(RegistrationEventTypes.REGISTRATION_OK, code, phrase));
                    }

                    // Audio/Video/MSRP
                    else if (((mySession = MyAVSession.GetSession(sessionId)) != null) || ((mySession = MyMsrpSession.GetSession(sessionId)) != null))
                    {
                        (mySession as MyInviteSession).State = MyInviteSession.InviteState.INCALL;
                        mySession.IsConnected = true;
                        EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(sessionId, InviteEventTypes.CONNECTED, phrase));
                    }

                    // Subscription
                    else if ((mySession = this.sipService.subPresence.FirstOrDefault(x => x.Id == sessionId)) != null)
                    {
                        mySession.IsConnected = true;
                    }

                    // Publication
                    else if (this.sipService.pubPres != null && this.sipService.pubPres.Id == sessionId)
                    {
                        this.sipService.pubPres.IsConnected = true;
                    }
                }


                else if (code == tinyWRAP.tsip_event_code_dialog_terminating)
                {
                    // Registration
                    if (this.sipService.regSession != null && this.sipService.regSession.Id == sessionId)
                    {
                        EventHandlerTrigger.TriggerEvent <RegistrationEventArgs>(this.sipService.onRegistrationEvent, this.sipService,
                                                                                 new RegistrationEventArgs(RegistrationEventTypes.UNREGISTRATION_INPROGRESS, code, phrase));
                    }

                    // Audio/Video/MSRP
                    else if (((mySession = MyAVSession.GetSession(sessionId)) != null) || ((mySession = MyMsrpSession.GetSession(sessionId)) != null))
                    {
                        (mySession as MyInviteSession).State = MyInviteSession.InviteState.TERMINATING;
                        EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(sessionId, InviteEventTypes.TERMWAIT, phrase));
                    }

                    // Subscription

                    // Publication
                }


                else if (code == tinyWRAP.tsip_event_code_dialog_terminated)
                {
                    // Registration
                    if (this.sipService.regSession != null && this.sipService.regSession.Id == sessionId)
                    {
                        this.sipService.regSession.IsConnected = false;
                        // To PostRegistration() in new thread
                        EventHandlerTrigger.TriggerEvent <RegistrationEventArgs>(this.sipService.onRegistrationEvent, this.sipService,
                                                                                 new RegistrationEventArgs(RegistrationEventTypes.UNREGISTRATION_OK, code, phrase));
                        /* Stop the stack (as we are already in the stack-thread, then do it in a new thread) */
                        new Thread(new ThreadStart(delegate
                        {
                            if (this.sipService.sipStack.State == MySipStack.STACK_STATE.STARTED)
                            {
                                this.sipService.sipStack.stop();
                            }
                        })).Start();
                    }

                    // Audio/Video/MSRP
                    else if (((mySession = MyAVSession.GetSession(sessionId)) != null) || ((mySession = MyMsrpSession.GetSession(sessionId)) != null))
                    {
                        mySession.IsConnected = false;
                        (mySession as MyInviteSession).State = MyInviteSession.InviteState.TERMINATED;
                        EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(sessionId, InviteEventTypes.DISCONNECTED, phrase));
                    }

                    // Subscription
                    else if ((mySession = this.sipService.subPresence.FirstOrDefault(x => x.Id == sessionId)) != null)
                    {
                        mySession.IsConnected = false;
                        this.sipService.subPresence.Remove(mySession as MySubscriptionSession);
                    }

                    // Publication
                    else if (this.sipService.pubPres != null && this.sipService.pubPres.Id == sessionId)
                    {
                        this.sipService.pubPres.IsConnected = false;
                        if (this.sipService.hyperAvailabilityTimer != null)
                        {
                            if (this.sipService.hyperAvailabilityTimer.Enabled)
                            {
                                this.sipService.hyperAvailabilityTimer.Stop();
                            }
                            this.sipService.hyperAvailabilityTimer = null;
                        }
                    }
                }

                return(0);
            }