示例#1
0
        public void Initialize(SIPAuthenticateRequestDelegate sipRequestAuthenticator,
                               Dictionary <string, PlatformConfig> platformList,
                               SIPAccount account)
        {
            m_registrarCore = new RegistrarCore(Transport, true, true, sipRequestAuthenticator);
            m_registrarCore.Start(1);


            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_2011(this, item.Key, item.Value.ChannelName, sipPoint);
                    monitor.OnSIPServiceChanged += monitor_OnSIPServiceChanged;
                    MonitorService.Add(key, monitor);
                }
            }
        }
示例#2
0
        /// <summary>
        /// sip请求消息
        /// </summary>
        /// <param name="localEndPoint">本地终结点</param>
        /// <param name="remoteEndPoint"b>远程终结点</param>
        /// <param name="request">sip请求</param>
        public override 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_2011(this, cata.DeviceID, cata.Name, remoteEndPoint);
                                    monitor.OnSIPServiceChanged += monitor_OnSIPServiceChanged;
                                    MonitorService.Add(key, monitor);
                                }
                            }
                        }
                        if (OnCatalogReceived != null)
                        {
                            OnCatalogReceived(catalog, remoteEndPoint.ToHost());
                        }
                    }
                    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);
            }
        }