Beispiel #1
0
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Register all configured accounts
        /// </summary>
        /// <returns></returns>
        public int registerAccounts()
        {
            if (!pjsipStackProxy.Instance.IsInitialized)
            {
                return(-1);
            }

            if (Config.Accounts.Count <= 0)
            {
                return(0);
            }

            // unregister accounts
            PjsipMethods.dll_removeAccounts();

            // iterate all accounts
            for (int i = 0; i < Config.Accounts.Count; i++)
            {
                IAccount acc = Config.Accounts[i];
                // check if accounts available
                if (null == acc)
                {
                    return(-1);
                }

                // reset account Index field
                Config.Accounts[i].Index = -1;
                // reset account state
                Config.Accounts[i].RegState = -1;

                if (acc.Enabled && (acc.Id.Length > 0) && (acc.HostName.Length > 0))
                {
                    string displayName = acc.DisplayName;
                    // warning:::Publish do not work if display name in uri !!!
                    string uri = "sip:" + acc.UserName;
                    if (acc.UserName.IndexOf("@") < 0)
                    {
                        uri += "@" + acc.HostName;
                    }
                    string reguri = "sip:" + acc.HostName;
                    // check transport - if TCP add transport=TCP
                    reguri = pjsipStackProxy.Instance.SetTransport(i, reguri);

                    string domain   = acc.DomainName;
                    string username = acc.UserName;
                    string password = acc.Password;

                    string proxy = "";
                    if (acc.ProxyAddress.Length > 0)
                    {
                        proxy = "sip:" + acc.ProxyAddress;
                    }

                    int accId = PjsipMethods.dll_registerAccount(uri, reguri, domain, username, password, proxy, (i == Config.DefaultAccountIndex ? true : false));

                    // store account Id to Index field
                    Config.Accounts[i].Index = accId;
                }
                else
                {
                    // trigger callback
                    BaseAccountStateChanged(i, -1);
                }
            }
            return(1);
        }