Esempio n. 1
0
        public void BeginRegister()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name, "不能执行注册操作。");
            }
            if (_regi != null)
            {
                _regi.Dispose();
            }

            string localSn   = _gateway.SipNumber;
            int    localPort = _gateway.Port;

            string remoteSn   = _platform.SipNumber;
            int    remotePort = _platform.Port;
            string remoteIP   = _platform.Ip;


            string user  = _platform.UserName;
            string pwd   = _platform.Password;
            string realm = _platform.Realm;

            SIP_Stack         stack = SipProxyWrapper.Instance.Stack;
            SIP_t_NameAddress from  = new SIP_t_NameAddress($"sip:{localSn}@{_localIp}:{localPort}");
            SIP_t_NameAddress to    = new SIP_t_NameAddress($"sip:{localSn}@{_localIp}:{localPort}");

            SIP_Uri server = new SIP_Uri()
            {
                Host = remoteIP,
                Port = remotePort,
                User = remoteSn
            };
            string              aor     = $"{localSn}@{_localIp}:{localPort}";
            AbsoluteUri         contact = AbsoluteUri.Parse($"sip:{localSn}@" + stack.BindInfo[0].EndPoint.ToString());
            SIP_UA_Registration regi    = stack.CreateRegistration(server, aor, contact, 7200);

            _regi = regi; //记录

            regi.Credential    = new NetworkCredential(user, pwd, realm);
            regi.Registered   += Regi_Registered;
            regi.StateChanged += Regi_StateChanged;

            if (_timerRegi == null)
            {
                _timerRegi = new Timer(timerRegi_Callback, null, 21000, Timeout.Infinite);
            }
            else
            {
                _timerRegi.Change(21000, Timeout.Infinite);
            }
            regi.BeginRegister(true);
        }