当前位置: 首页 > 工具软件 > LinPhone > 使用案例 >

Linphone探索:6 . Linphone用户注册

冉昊
2023-12-01

前言

Linphone的用户注册包含3个部分
1. 用户创建
2. 用户修改
3. 服务器注册

1. 用户创建

在Linphone示例程序中,当我们第一次运行的时候,软件会直接跳转到一个创建用户界面,接着通过输入ID、name、密码、服务器地址可以创建一个用户。
实际这个界面说做的业务,主要通过AssistantActivity.java 的public void saveCreatedAccount(String username, String password, String displayName, String domain, TransportType transport)方法实现。
当我们需要淡化创建用户的过程时,比如说用户ID由管理员设置,其它人都不能更改。此时在初始化时我们这样调用该函数就可达到自动创建用户的功能。
在LinphoneActivity.java的onCreate方法中添加如下代码即可自动生成一个用户:

int nbAccounts = LinphonePreferences.instance().getAccountCount();
debug.i("nbAccounts = "+nbAccounts);
if(nbAccounts <= 0){
    saveCreatedAccount("1001", "1234", "192.168.1.33");
}

使用refreshRegisters();方法使Linphone自动向服务器发起注册

自动创建用户,并且向服务器注册的整体流程如下:

int nbAccounts = LinphonePreferences.instance().getAccountCount();
debug.i("nbAccounts = "+nbAccounts);
if(nbAccounts <= 0){
    saveCreatedAccount("1001", "1234", "192.168.1.33");
}
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
nbAccounts = LinphonePreferences.instance().getAccountCount();
debug.i("nbAccounts = "+nbAccounts);
if(nbAccounts > 0)   
{
    debug.i("lc.refreshRegisters()");   
    int accountIndex = 0;
    LinphonePreferences.instance().setDefaultAccount(accountIndex);         
    debug.i("accountPosition = "+0);
    lc.setDefaultProxyConfig((LinphoneProxyConfig) LinphoneManager.getLc().getProxyConfigList()[0]);
    if (lc.isNetworkReachable()) {
        lc.refreshRegisters();
    }
}

2. 用户修改

用户注册后,有些参数需要修改,一般如下所示:
1. 修改网络传输方式:TCP、UDP、TLS
2. 修改用户名
3. 修改显示名称
4. 修改ID号码
5. 修改密码
6. 修改域名
7. 修改代理

可以通过如下方法修改上述参数,列举部分

LinphonePreferences mPrefs = LinphonePreferences.instance();
//修改用户名
mPrefs.setAccountUsername(0, "1002");
//修改ID号码
mPrefs.setAccountUserId(0, "1002");     

//pref_transport_udp_key 使用udp
//pref_transport_tcp_key 使用tcp
//pref_transport_tls_key 使用tls
mPrefs.setAccountTransport(0,"pref_transport_tcp_key");

修改用户属性,并向服务器发起注册:

LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
LinphonePreferences mPrefs = LinphonePreferences.instance();
int nbAccounts = LinphonePreferences.instance().getAccountCount();
debug.i("nbAccounts = "+nbAccounts);
if(nbAccounts > 0){                     
    mPrefs.setAccountUsername(0, callNumberMyself);
    mPrefs.setAccountUserId(0, callNumberMyself);           
    mPrefs.setAccountTransport(0,"pref_transport_tcp_key");
    debug.i("change now account params");
}
else{
    saveCreatedAccount(callNumberMyself, "1234", "192.168.1.33");
}
nbAccounts = LinphonePreferences.instance().getAccountCount();
debug.i("nbAccounts = "+nbAccounts);
if(nbAccounts > 0)   
{
    debug.i("lc.refreshRegisters()");   
    int accountIndex = 0;
    LinphonePreferences.instance().setDefaultAccount(accountIndex);         
    debug.i("accountPosition = "+0);
    lc.setDefaultProxyConfig((LinphoneProxyConfig) LinphoneManager.getLc().getProxyConfigList()[0]);
    if (lc.isNetworkReachable()) {
        lc.refreshRegisters();
    }
}
 类似资料: