コード例 #1
0
        /// <summary>
        /// sip请求消息
        /// </summary>
        /// <param name="localSIPEndPoint">本地终结点</param>
        /// <param name="remoteEndPoint">远程终结点</param>
        /// <param name="request">sip请求</param>
        public void AddMessageRequest(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest request)
        {
            //注册请求
            if (request.Method == SIPMethodsEnum.REGISTER)
            {
                m_registrarCore.AddRegisterRequest(localSIPEndPoint, remoteEndPoint, request);
            }
            //消息请求
            else if (request.Method == SIPMethodsEnum.MESSAGE)
            {
                KeepAlive keepAlive = KeepAlive.Instance.Read(request.Body);
                if (keepAlive != null)  //心跳
                {
                    if (!_initSIP)
                    {
                        LocalEndPoint  = request.Header.To.ToURI.ToSIPEndPoint();
                        RemoteEndPoint = request.Header.From.FromURI.ToSIPEndPoint();
                        LocalSIPId     = request.Header.To.ToURI.User;
                        RemoteSIPId    = request.Header.From.FromURI.User;
                    }

                    _initSIP = true;

                    OnSIPServiceChange(RemoteSIPId, SipServiceStatus.Complete);
                }
                else   //目录检索
                {
                    Catalog catalog = Catalog.Instance.Read(request.Body);
                    if (catalog != null)
                    {
                        foreach (var cata in catalog.DeviceList.Items)
                        {
                            lock (MonitorService)
                            {
                                if (!MonitorService.ContainsKey(cata.DeviceID))
                                {
                                    ISIPMonitorService monitor = new SIPMonitorCore(this, cata.DeviceID, cata.Name);
                                    monitor.OnSIPServiceChanged += monitor_OnSIPServiceChanged;
                                    MonitorService.Add(cata.DeviceID, monitor);
                                }
                            }
                        }
                        OnCatalogReceive(catalog);
                    }
                }
                SIPResponse msgRes = GetResponse(localSIPEndPoint, remoteEndPoint, SIPResponseStatusCodesEnum.Ok, "", request);
                Transport.SendResponse(msgRes);
            }
            //停止播放请求
            else if (request.Method == SIPMethodsEnum.BYE)
            {
                SIPResponse byeRes = GetResponse(localSIPEndPoint, remoteEndPoint, SIPResponseStatusCodesEnum.Ok, "", request);
                Transport.SendResponse(byeRes);
            }
        }
コード例 #2
0
 /// <summary>
 /// 注册消息处理
 /// </summary>
 /// <param name="localEP">本地终结点</param>
 /// <param name="remoteEP">远程终结点</param>
 /// <param name="request">sip请求</param>
 private void RegisterHandle(SIPEndPoint localEP, SIPEndPoint remoteEP, SIPRequest request)
 {
     OnSIPServiceChange(remoteEP.ToHost(), ServiceStatus.Complete);
     lock (Trans)
     {
         if (!Trans.ContainsKey(remoteEP.ToHost()))
         {
             Trans.Add(remoteEP.ToHost(), request.Header.From.FromURI.User);
         }
     }
     m_registrarCore.AddRegisterRequest(localEP, remoteEP, request);
 }
コード例 #3
0
        /// <summary>
        /// sip请求消息
        /// </summary>
        /// <param name="localEndPoint">本地终结点</param>
        /// <param name="remoteEndPoint"b>远程终结点</param>
        /// <param name="request">sip请求</param>
        public void AddMessageRequest(SIPEndPoint localEndPoint, SIPEndPoint remoteEndPoint, SIPRequest request)
        {
            //注册请求
            if (request.Method == SIPMethodsEnum.REGISTER)
            {
                m_registrarCore.AddRegisterRequest(localEndPoint, remoteEndPoint, request);
                SIPTransportInit(localEndPoint, remoteEndPoint, request);
            }
            //消息请求
            else if (request.Method == SIPMethodsEnum.MESSAGE)
            {
                SIPTransportInit(localEndPoint, remoteEndPoint, request);
                KeepAlive keepAlive = KeepAlive.Instance.Read(request.Body);
                if (keepAlive != null && keepAlive.CmdType == CommandType.Keepalive)  //心跳
                {
                    //if (!_initSIP)
                    //{
                    //LocalEndPoint = request.Header.To.ToURI.ToSIPEndPoint();
                    //RemoteEndPoint = request.Header.From.FromURI.ToSIPEndPoint();
                    //LocalSIPId = request.Header.To.ToURI.User;
                    //RemoteSIPId = request.Header.From.FromURI.User;
                    //}

                    //_initSIP = true;
                    logger.Debug("KeepAlive:" + remoteEndPoint.ToHost() + "=====DevID:" + keepAlive.DeviceID + "=====Status:" + keepAlive.Status + "=====SN:" + keepAlive.SN);
                    OnSIPServiceChange(remoteEndPoint.ToHost(), SipServiceStatus.Complete);
                }
                else
                {
                    Catalog catalog = Catalog.Instance.Read(request.Body);
                    if (catalog != null && catalog.CmdType == CommandType.Catalog)  //设备目录
                    {
                        foreach (var cata in catalog.DeviceList.Items)
                        {
                            //cata.RemoteEP = request.Header.From.FromURI.Host;
                            cata.RemoteEP = remoteEndPoint.ToHost();
                            for (int i = 0; i < 2; i++)
                            {
                                CommandType cmdType = CommandType.Unknown;
                                if (i == 0)
                                {
                                    cmdType = CommandType.Play;
                                }
                                else
                                {
                                    cmdType = CommandType.Playback;
                                }
                                string key = cata.DeviceID + cmdType;
                                lock (MonitorService)
                                {
                                    if (MonitorService.ContainsKey(key))
                                    {
                                        continue;
                                    }
                                    ISIPMonitorService monitor = new SIPMonitorCore(this, cata.DeviceID, cata.Name, remoteEndPoint);
                                    monitor.OnSIPServiceChanged += monitor_OnSIPServiceChanged;
                                    MonitorService.Add(key, monitor);
                                }
                            }
                        }
                        if (OnCatalogReceived != null)
                        {
                            OnCatalogReceived(catalog);
                        }
                    }
                    RecordInfo record = RecordInfo.Instance.Read(request.Body);
                    if (record != null && record.CmdType == CommandType.RecordInfo)  //录像检索
                    {
                        lock (MonitorService)
                        {
                            MonitorService[record.DeviceID + CommandType.Playback].RecordQueryTotal(record.SumNum);
                        }
                        if (OnRecordInfoReceived != null && record.RecordItems != null)
                        {
                            OnRecordInfoReceived(record);
                        }
                    }
                }
                SIPResponse msgRes = GetResponse(localEndPoint, remoteEndPoint, SIPResponseStatusCodesEnum.Ok, "", request);
                Transport.SendResponse(msgRes);
            }
            //停止播放请求
            else if (request.Method == SIPMethodsEnum.BYE)
            {
                SIPResponse byeRes = GetResponse(localEndPoint, remoteEndPoint, SIPResponseStatusCodesEnum.Ok, "", request);
                Transport.SendResponse(byeRes);
            }
        }