/// <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
        public void Initialize(SIPAuthenticateRequestDelegate sipRequestAuthenticator,
                               Dictionary <string, PlatformConfig> platformList,
                               SIPAccount account)
        {
            LocalEndPoint = SIPEndPoint.ParseSIPEndPoint("udp:" + account.LocalIP.ToString() + ":" + account.LocalPort);
            LocalSIPId    = account.LocalID;
            //foreach (var account in accounts)
            //{
            //    SIPEndPoint remoteEP = SIPEndPoint.ParseSIPEndPoint("udp:" + account.SIPDomain);
            //    RemoteTrans.Add(remoteEP.ToString(), account.SIPUsername);
            //    if (LocalEndPoint == null)
            //    {
            //        LocalEndPoint = SIPEndPoint.ParseSIPEndPoint("udp:" + account.LocalIP.ToString() + ":" + account.LocalPort);
            //    }
            //    if (LocalSIPId == null)
            //    {
            //        LocalSIPId = account.LocalID;
            //    }
            //}

            m_registrarCore = new RegistrarCore(Transport, true, true, sipRequestAuthenticator);
            m_registrarCore.Start(1);
            MonitorService = new Dictionary <string, ISIPMonitorService>();

            foreach (var item in platformList)
            {
                string      sipEndPointStr = "udp:" + item.Value.RemoteIP + ":" + item.Value.RemotePort;
                SIPEndPoint sipPoint       = SIPEndPoint.ParseSIPEndPoint(sipEndPointStr);
                for (int i = 0; i < 2; i++)
                {
                    CommandType cmdType = CommandType.Unknown;
                    if (i == 0)
                    {
                        cmdType = CommandType.Play;
                    }
                    else
                    {
                        cmdType = CommandType.Playback;
                    }
                    string             key     = item.Key + cmdType;
                    ISIPMonitorService monitor = new SIPMonitorCore(this, item.Key, item.Value.ChannelName, sipPoint);
                    monitor.OnSIPServiceChanged += monitor_OnSIPServiceChanged;
                    MonitorService.Add(key, monitor);
                }
            }
        }
        public void Initialize(string switchboarduserAgentPrefix,
                               SIPAuthenticateRequestDelegate sipRequestAuthenticator,
                               GetCanonicalDomainDelegate getCanonicalDomain,
                               SIPAssetGetDelegate <SIPAccount> getSIPAccount,
                               SIPUserAgentConfigurationManager userAgentConfigs,
                               SIPRegistrarBindingsManager registrarBindingsManager,
                               Dictionary <string, string> devList)
        {
            m_registrarCore = new RegistrarCore(Transport, registrarBindingsManager, getSIPAccount, getCanonicalDomain, true, true, userAgentConfigs, sipRequestAuthenticator, switchboarduserAgentPrefix);
            m_registrarCore.Start(1);
            MonitorService = new Dictionary <string, ISIPMonitorService>();

            foreach (var item in devList)
            {
                ISIPMonitorService monitor = new SIPMonitorCore(this, item.Key, item.Value);
                monitor.OnSIPServiceChanged += monitor_OnSIPServiceChanged;
                MonitorService.Add(item.Key, monitor);
            }
        }
Пример #4
0
        /// <summary>
        /// 目录查询响应消息处理
        /// </summary>
        /// <param name="localEP">本地终结点</param>
        /// <param name="remoteEP">远程终结点</param>
        /// <param name="request">sip请求</param>
        /// <param name="catalog">目录结构体</param>
        private void CatalogHandle(SIPEndPoint localEP, SIPEndPoint remoteEP, SIPRequest request, Catalog catalog)
        {
            foreach (var cata in catalog.DeviceList.Items)
            {
                if (cata == null)
                {
                    continue;
                }
                cata.RemoteEP = remoteEP.ToHost();
                DevCataType devCata = DevType.GetCataType(cata.DeviceID);
                if (devCata != DevCataType.Device)
                {
                    continue;
                }
                for (int i = 0; i < 2; i++)
                {
                    CommandType cmdType = i == 0 ? CommandType.Play : CommandType.Playback;
                    MonitorKey  key     = new MonitorKey()
                    {
                        DeviceID = cata.DeviceID,
                        CmdType  = cmdType
                    };
                    lock (MonitorService)
                    {
                        if (MonitorService.ContainsKey(key))
                        {
                            continue;
                        }
                        remoteEP.Port = _account.KeepaliveInterval;
                        ISIPMonitorService monitor = new SIPMonitorCore(this, cata.DeviceID, remoteEP, _account);
                        MonitorService.Add(key, monitor);
                    }
                }
            }

            if (OnCatalogReceived != null)
            {
                OnCatalogReceived(catalog);
            }
        }
Пример #5
0
        public SIPMessageCore(IList <CameraInfo> cameras, SIPAccount account)
        {
            _serviceState = ServiceStatus.Wait;
            _account      = account;
            LocalEP       = SIPEndPoint.ParseSIPEndPoint("udp:" + account.LocalIP.ToString() + ":" + account.LocalPort);
            LocalSIPId    = account.LocalID;

            MonitorService = new Dictionary <MonitorKey, ISIPMonitorService>();
            Trans          = new Dictionary <string, string>();
            foreach (var channel in cameras)
            {
                for (int i = 0; i < 2; i++)
                {
                    CommandType cmdType = i == 0 ? CommandType.Play : CommandType.Playback;
                    MonitorKey  key     = new MonitorKey()
                    {
                        DeviceID = channel.ChannelID,
                        CmdType  = cmdType
                    };
                    ISIPMonitorService monitor = new SIPMonitorCore(this, channel.ChannelID, RemoteEP, account);
                    MonitorService.Add(key, monitor);
                }
            }
        }
Пример #6
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);
            }
        }