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++; }
/// <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(); } }
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(); }
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(); }
/// <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(); } }