コード例 #1
0
        /// <summary>
        /// Calling constructor.
        /// </summary>
        /// <param name="stack">Reference to SIP stack.</param>
        /// <param name="sender">Initial INVITE sender.</param>
        /// <param name="session">Call RTP multimedia session.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>stack</b>,<b>sender</b> or <b>session</b> is null reference.</exception>
        internal SIP_Call(SIP_Stack stack, SIP_RequestSender sender, RTP_MultimediaSession session)
        {
            if (stack == null)
            {
                throw new ArgumentNullException("stack");
            }
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            m_pStack = stack;
            m_pInitialInviteSender  = sender;
            m_pRtpMultimediaSession = session;

            m_pTags = new Dictionary <string, object>();

            m_pInitialInviteSender.Completed += new EventHandler(delegate(object s, EventArgs e){
                m_pInitialInviteSender = null;

                if (this.State == SIP_CallState.Terminating)
                {
                    SetState(SIP_CallState.Terminated);
                }
            });

            m_CallState = SIP_CallState.Calling;
        }
コード例 #2
0
 private void closeSender()
 {
     if (_sender != null)
     {
         _sender.ResponseReceived -= Send_ResponseReceived;
         _sender.Dispose();
         _sender = null;
     }
 }
コード例 #3
0
        private void Send_ResponseReceived(object sender, SIP_ResponseReceivedEventArgs e)
        {
            SIP_RequestSender send = sender as SIP_RequestSender;

            if (e.Response.StatusCodeType == SIP_StatusCodeType.Success)
            {
                _aliveCount--;
                send.ResponseReceived -= Send_ResponseReceived;
            }
        }
コード例 #4
0
        private void timerAlive_Callback(object state)
        {
            //资源已释放,停止心跳。
            if (_disposed || !_registered)
            {
                return;
            }
            if (_aliveCount >= 3)
            {
                //重新注册。
                _registered = false;
                _alive      = false;
                _timerAlive.Change(Timeout.Infinite, Timeout.Infinite); //关闭心跳定时器。
                SipProxyWrapper.Instance.RTPManager.RemoveTargets(Platform.Ip);
                closeSender();
                BeginRegister();
                return;
            }

            try
            {
                Gateway   gw    = _gateway;
                Platform  pf    = _platform;
                SIP_Stack stack = SipProxyWrapper.Instance.Stack;

                KeepAlive ka = new KeepAlive()
                {
                    DeviceID = gw.SipNumber
                };
                string body = SerializeHelper.Instance.Serialize(ka);

                SIP_t_NameAddress from = new SIP_t_NameAddress($"sip:{gw.SipNumber}@{_localIp}:{gw.Port}");
                SIP_t_NameAddress to   = new SIP_t_NameAddress($"sip:{pf.SipNumber}@{pf.Ip}:{pf.Port}");

                SIP_Request message = stack.CreateRequest(SIP_Methods.MESSAGE, to, from);
                message.ContentType = "Application/MANSCDP+xml";
                message.Data        = MyEncoder.Encoder.GetBytes(body);

                closeSender();
                _sender = stack.CreateRequestSender(message);
                _sender.ResponseReceived += Send_ResponseReceived;
                _sender.Start();
            }
            catch (Exception e)
            {
                Common.Log.Logger.Default.Error($"心跳指令发送失败,平台:{Platform.Name}:{Platform.SipNumber}", e);
            }
            _aliveCount++;
        }
コード例 #5
0
        /// <summary>
        /// Starts calling.
        /// </summary>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception>
        /// <exception cref="InvalidOperationException">Is raised when call is not in valid state.</exception>
        public void Start()
        {
            lock (m_pLock){
                if (m_State == SIP_UA_CallState.Disposed)
                {
                    throw new ObjectDisposedException(this.GetType().Name);
                }
                if (m_State != SIP_UA_CallState.WaitingForStart)
                {
                    throw new InvalidOperationException("Start method can be called only in 'SIP_UA_CallState.WaitingForStart' state.");
                }

                SetState(SIP_UA_CallState.Calling);

                m_pInitialInviteSender = m_pUA.Stack.CreateRequestSender(m_pInvite);
                m_pInitialInviteSender.ResponseReceived += new EventHandler <SIP_ResponseReceivedEventArgs>(m_pInitialInviteSender_ResponseReceived);
                m_pInitialInviteSender.Start();
            }
        }
コード例 #6
0
        public void ResponseToPlatform(Platform plat)
        {
            Gateway   gw      = InfoService.Instance.CurrentGateway;
            string    localIp = IPAddressHelper.GetLocalIp();
            SIP_Stack stack   = SipProxyWrapper.Instance.Stack;

            DeviceCatalogResp resp = createCatalogResp(gw, plat);
            string            body = SerializeHelper.Instance.Serialize(resp);

            SIP_t_NameAddress from = new SIP_t_NameAddress($"sip:{gw.SipNumber}@{localIp}:{gw.Port}");
            SIP_t_NameAddress to   = new SIP_t_NameAddress($"sip:{plat.SipNumber}@{plat.Ip}:{plat.Port}");

            SIP_Request message = stack.CreateRequest(SIP_Methods.MESSAGE, to, from);

            message.ContentType = "Application/MANSCDP+xml";
            message.Data        = MyEncoder.Encoder.GetBytes(body);
            SIP_RequestSender send = stack.CreateRequestSender(message);

            send.Start();
        }
コード例 #7
0
        public void NotifyToPlatform(string platId)
        {
            Gateway   gw      = InfoService.Instance.CurrentGateway;
            Platform  pf      = InfoService.Instance.GetPlatform(platId);
            string    localIp = IPAddressHelper.GetLocalIp();
            SIP_Stack stack   = SipProxyWrapper.Instance.Stack;

            DeviceCatalogNotify dcd = createCatalog(gw, pf);
            string body             = SerializeHelper.Instance.Serialize(dcd);

            SIP_t_NameAddress from = new SIP_t_NameAddress($"sip:{gw.SipNumber}@{localIp}:{gw.Port}");
            SIP_t_NameAddress to   = new SIP_t_NameAddress($"sip:{pf.SipNumber}@{pf.Ip}:{pf.Port}");

            SIP_Request message = stack.CreateRequest(SIP_Methods.NOTIFY, to, from);

            message.ContentType = "Application/MANSCDP+xml";
            message.Data        = MyEncoder.Encoder.GetBytes(body);
            SIP_RequestSender send = stack.CreateRequestSender(message);

            send.Start();
        }
コード例 #8
0
        /// <summary>
        /// Starts calling.
        /// </summary>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception>
        /// <exception cref="InvalidOperationException">Is raised when call is not in valid state.</exception>
        public void Start()
        {
            lock (m_pLock)
            {
                if (m_State == SIP_UA_CallState.Disposed)
                {
                    throw new ObjectDisposedException(GetType().Name);
                }
                if (m_State != SIP_UA_CallState.WaitingForStart)
                {
                    throw new InvalidOperationException(
                        "Start method can be called only in 'SIP_UA_CallState.WaitingForStart' state.");
                }

                SetState(SIP_UA_CallState.Calling);

                m_pInitialInviteSender = m_pUA.Stack.CreateRequestSender(m_pInvite);
                m_pInitialInviteSender.ResponseReceived += m_pInitialInviteSender_ResponseReceived;
                m_pInitialInviteSender.Start();
            }
        }