Switched to SDK 5.0 and use new Account object instead of deprecated ProxyConfig

This commit is contained in:
Sylvain Berfini
2021-04-15 16:43:26 +02:00
parent 63f9b66e33
commit 458135fea4
14 changed files with 85 additions and 99 deletions

View File

@@ -45,6 +45,6 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
// Latest version is 4.5.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:4.5+'
// Latest version is 5.0.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:5.0+'
}

View File

@@ -26,6 +26,7 @@ import android.widget.RadioGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import org.linphone.core.*
import org.linphone.core.tools.Log
class AccountLoginActivity: AppCompatActivity() {
private lateinit var core: Core
@@ -33,12 +34,7 @@ class AccountLoginActivity: AppCompatActivity() {
// Create a Core listener to listen for the callback we need
// In this case, we want to know about the account registration status
private val coreListener = object: CoreListenerStub() {
override fun onRegistrationStateChanged(
core: Core,
proxyConfig: ProxyConfig,
state: RegistrationState?,
message: String
) {
override fun onAccountRegistrationStateChanged(core: Core, account: Account, state: RegistrationState, message: String) {
// If account has been configured correctly, we will go through InProgress and Registered states
// Otherwise, we will be Failed.
findViewById<TextView>(R.id.registration_status).text = message
@@ -80,7 +76,7 @@ class AccountLoginActivity: AppCompatActivity() {
else -> TransportType.Tls
}
// To create an account, we need a ProxyConfig object and an AuthInfo object
// To configure a SIP account, we need an Account object and an AuthInfo object
// The first one is how to connect to the proxy server, the second one stores the credentials
// The auth info can be created from the Factory as it's only a data class
@@ -89,29 +85,39 @@ class AccountLoginActivity: AppCompatActivity() {
// The realm will be determined automatically from the first register, as well as the algorithm
val authInfo = Factory.instance().createAuthInfo(username, null, password, null, null, domain, null)
// Proxy config object depends on the Core so we can't create it using the Factory
val proxyConfig = core.createProxyConfig()
// Proxy config needs an identity address that we can construct from the username and domain
// Account object replaces deprecated ProxyConfig object
// Account object is configured through an AccountParams object that we can obtain from the Core
val accountParams = core.createAccountParams()
// A SIP account is identified by an identity address that we can construct from the username and domain
val identity = Factory.instance().createAddress("sip:$username@$domain")
proxyConfig.identityAddress = identity
accountParams.identityAddress = identity
// We also need to configure where the proxy server is located
val address = Factory.instance().createAddress("sip:$domain")
// We use the Address object to easily set the transport protocol
address?.transport = transportType
proxyConfig.serverAddr = address?.asStringUriOnly()
accountParams.serverAddress = address
// And we ensure the account will start the registration process
proxyConfig.enableRegister(true)
accountParams.registerEnabled = true
// Now that our AccountParams is configured, we can create the Account object
val account = core.createAccount(accountParams)
// Now let's add our objects to the Core
core.addAuthInfo(authInfo)
core.addProxyConfig(proxyConfig)
core.addAccount(account)
// Also set the newly added account as default
core.defaultProxyConfig = proxyConfig
core.defaultAccount = account
// To be notified of the connection status of our account, we need to add the listener to the Core
core.addListener(coreListener)
// We can also register a callback on the Account object
account.addListener { _, state, message ->
// There is a Log helper in org.linphone.core.tools package
Log.i("[Account] Registration state changed: $state, $message")
}
// Finally we need the Core to be started for the registration to happen (it could have been started before)
core.start()

View File

@@ -45,6 +45,6 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
// Latest version is 4.5.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:4.5+'
// Latest version is 5.0.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:5.0+'
}

View File

@@ -33,17 +33,12 @@ class AdvancedChatActivity: AppCompatActivity() {
private var chatRoom: ChatRoom? = null
private val coreListener = object: CoreListenerStub() {
override fun onRegistrationStateChanged(
core: Core,
proxyConfig: ProxyConfig,
state: RegistrationState?,
message: String
) {
override fun onAccountRegistrationStateChanged(core: Core, account: Account, state: RegistrationState?, message: String) {
findViewById<TextView>(R.id.registration_status).text = message
if (state == RegistrationState.Failed) {
core.clearAllAuthInfo()
core.clearProxyConfig()
core.clearAccounts()
findViewById<Button>(R.id.connect).isEnabled = true
} else if (state == RegistrationState.Ok) {
findViewById<LinearLayout>(R.id.register_layout).visibility = View.GONE
@@ -180,25 +175,26 @@ class AdvancedChatActivity: AppCompatActivity() {
}
val authInfo = Factory.instance().createAuthInfo(username, null, password, null, null, domain, null)
val proxyConfig = core.createProxyConfig()
val params = core.createAccountParams()
val identity = Factory.instance().createAddress("sip:$username@$domain")
proxyConfig.identityAddress = identity
params.identityAddress = identity
val address = Factory.instance().createAddress("sip:$domain")
address?.transport = transportType
proxyConfig.serverAddr = address?.asStringUriOnly()
proxyConfig.enableRegister(true)
params.serverAddress = address
params.registerEnabled = true
// We need a conference factory URI set on the proxy config to be able to create chat rooms with flexisip backend
proxyConfig.conferenceFactoryUri = "sip:conference-factory@sip.linphone.org"
// We need a conference factory URI set on the Account to be able to create chat rooms with flexisip backend
params.conferenceFactoryUri = "sip:conference-factory@sip.linphone.org"
core.addAuthInfo(authInfo)
core.addProxyConfig(proxyConfig)
val account = core.createAccount(params)
core.addAccount(account)
// We also need a LIME X3DH server URL configured for end to end encryption
core.limeX3DhServerUrl = "https://lime.linphone.org/lime-server/lime-server.php"
core.defaultProxyConfig = proxyConfig
core.defaultAccount = account
core.addListener(coreListener)
core.start()
}
@@ -206,7 +202,7 @@ class AdvancedChatActivity: AppCompatActivity() {
private fun createFlexisipChatRoom() {
// In this tutorial we will create a Flexisip one-to-one chat room with end-to-end encryption
// For it to work, the proxy server we connect to must be an instance of Flexisip
// And we must have configured on the ProxyConfig a conference-factory URI
// And we must have configured on the Account a conference-factory URI
val params = core.createDefaultChatRoomParams()
// We won't create a group chat, only a 1-1 with advanced features such as end-to-end encryption
@@ -228,7 +224,7 @@ class AdvancedChatActivity: AppCompatActivity() {
if (remoteAddress != null) {
// And finally we will need our local SIP address
val localAddress = core.defaultProxyConfig?.identityAddress
val localAddress = core.defaultAccount?.params?.identityAddress
val room = core.createChatRoom(params, localAddress, arrayOf(remoteAddress))
if (room != null) {
// If chat room isn't created yet, wait for it to go in state Created

View File

@@ -45,6 +45,6 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
// Latest version is 4.5.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:4.5+'
// Latest version is 5.0.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:5.0+'
}

View File

@@ -34,17 +34,12 @@ class BasicChatActivity: AppCompatActivity() {
private var chatRoom: ChatRoom? = null
private val coreListener = object: CoreListenerStub() {
override fun onRegistrationStateChanged(
core: Core,
proxyConfig: ProxyConfig,
state: RegistrationState?,
message: String
) {
override fun onAccountRegistrationStateChanged(core: Core, account: Account, state: RegistrationState?, message: String) {
findViewById<TextView>(R.id.registration_status).text = message
if (state == RegistrationState.Failed) {
core.clearAllAuthInfo()
core.clearProxyConfig()
core.clearAccounts()
findViewById<Button>(R.id.connect).isEnabled = true
} else if (state == RegistrationState.Ok) {
findViewById<LinearLayout>(R.id.register_layout).visibility = View.GONE
@@ -139,19 +134,20 @@ class BasicChatActivity: AppCompatActivity() {
}
val authInfo = Factory.instance().createAuthInfo(username, null, password, null, null, domain, null)
val proxyConfig = core.createProxyConfig()
val params = core.createAccountParams()
val identity = Factory.instance().createAddress("sip:$username@$domain")
proxyConfig.identityAddress = identity
params.identityAddress = identity
val address = Factory.instance().createAddress("sip:$domain")
address?.transport = transportType
proxyConfig.serverAddr = address?.asStringUriOnly()
proxyConfig.enableRegister(true)
params.serverAddress = address
params.registerEnabled = true
val account = core.createAccount(params)
core.addAuthInfo(authInfo)
core.addProxyConfig(proxyConfig)
core.addAccount(account)
core.defaultProxyConfig = proxyConfig
core.defaultAccount = account
core.addListener(coreListener)
core.start()
}
@@ -173,7 +169,7 @@ class BasicChatActivity: AppCompatActivity() {
if (remoteAddress != null) {
// And finally we will need our local SIP address
val localAddress = core.defaultProxyConfig?.identityAddress
val localAddress = core.defaultAccount?.params?.identityAddress
val room = core.createChatRoom(params, localAddress, arrayOf(remoteAddress))
if (room != null) {
chatRoom = room

View File

@@ -43,6 +43,6 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
// Latest version is 4.5.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:4.5+'
// Latest version is 5.0.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:5.0+'
}

View File

@@ -45,8 +45,8 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
// Latest version is 4.5.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:4.5+'
// Latest version is 5.0.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:5.0+'
// Adding this dependency allows the linphone-sdk to automatically handle audio focus
implementation 'androidx.media:media:1.2.0'
}

View File

@@ -31,12 +31,7 @@ class IncomingCallActivity: AppCompatActivity() {
private lateinit var core: Core
private val coreListener = object: CoreListenerStub() {
override fun onRegistrationStateChanged(
core: Core,
proxyConfig: ProxyConfig,
state: RegistrationState?,
message: String
) {
override fun onAccountRegistrationStateChanged(core: Core, account: Account, state: RegistrationState?, message: String) {
findViewById<TextView>(R.id.registration_status).text = message
if (state == RegistrationState.Failed) {
@@ -161,19 +156,20 @@ class IncomingCallActivity: AppCompatActivity() {
}
val authInfo = Factory.instance().createAuthInfo(username, null, password, null, null, domain, null)
val proxyConfig = core.createProxyConfig()
val params = core.createAccountParams()
val identity = Factory.instance().createAddress("sip:$username@$domain")
proxyConfig.identityAddress = identity
params.identityAddress = identity
val address = Factory.instance().createAddress("sip:$domain")
address?.transport = transportType
proxyConfig.serverAddr = address?.asStringUriOnly()
proxyConfig.enableRegister(true)
params.serverAddress = address
params.registerEnabled = true
val account = core.createAccount(params)
core.addAuthInfo(authInfo)
core.addProxyConfig(proxyConfig)
core.addAccount(account)
core.defaultProxyConfig = proxyConfig
core.defaultAccount = account
core.addListener(coreListener)
core.start()

View File

@@ -45,8 +45,8 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
// Latest version is 4.5.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:4.5+'
// Latest version is 5.0.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:5.0+'
// Adding this dependency allows the linphone-sdk to automatically handle audio focus
implementation 'androidx.media:media:1.2.0'
}

View File

@@ -32,12 +32,7 @@ class OutgoingCallActivity: AppCompatActivity() {
private lateinit var core: Core
private val coreListener = object: CoreListenerStub() {
override fun onRegistrationStateChanged(
core: Core,
proxyConfig: ProxyConfig,
state: RegistrationState?,
message: String
) {
override fun onAccountRegistrationStateChanged(core: Core, account: Account, state: RegistrationState?, message: String) {
findViewById<TextView>(R.id.registration_status).text = message
if (state == RegistrationState.Failed) {
@@ -192,19 +187,20 @@ class OutgoingCallActivity: AppCompatActivity() {
}
val authInfo = Factory.instance().createAuthInfo(username, null, password, null, null, domain, null)
val proxyConfig = core.createProxyConfig()
val params = core.createAccountParams()
val identity = Factory.instance().createAddress("sip:$username@$domain")
proxyConfig.identityAddress = identity
params.identityAddress = identity
val address = Factory.instance().createAddress("sip:$domain")
address?.transport = transportType
proxyConfig.serverAddr = address?.asStringUriOnly()
proxyConfig.enableRegister(true)
params.serverAddress = address
params.registerEnabled = true
val account = core.createAccount(params)
core.addAuthInfo(authInfo)
core.addProxyConfig(proxyConfig)
core.addAccount(account)
core.defaultProxyConfig = proxyConfig
core.defaultAccount = account
core.addListener(coreListener)
core.start()

View File

@@ -120,7 +120,7 @@
android:id="@+id/toggle_camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle video"
android:text="Toggle camera"
android:layout_alignParentRight="true"
android:layout_below="@id/call_status"/>

View File

@@ -45,8 +45,8 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
// Latest version is 4.5.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:4.5+'
// Latest version is 5.0.x, using + to get the latest available
implementation 'org.linphone:linphone-sdk-android:5.0+'
// Required for firebase push notifications
implementation 'com.google.firebase:firebase-messaging:19.0.1'
}

View File

@@ -29,12 +29,7 @@ class PushNotificationsActivity: AppCompatActivity() {
private lateinit var core: Core
private val coreListener = object: CoreListenerStub() {
override fun onRegistrationStateChanged(
core: Core,
proxyConfig: ProxyConfig,
state: RegistrationState?,
message: String
) {
override fun onAccountRegistrationStateChanged(core: Core, account: Account, state: RegistrationState?, message: String) {
findViewById<TextView>(R.id.registration_status).text = message
if (state == RegistrationState.Failed) {
@@ -44,7 +39,7 @@ class PushNotificationsActivity: AppCompatActivity() {
View.GONE
// This will display the push information stored in the contact URI parameters
findViewById<TextView>(R.id.push_info).text = proxyConfig.contactUriParameters
findViewById<TextView>(R.id.push_info).text = account.params.contactUriParameters
}
}
}
@@ -82,22 +77,23 @@ class PushNotificationsActivity: AppCompatActivity() {
}
val authInfo = Factory.instance().createAuthInfo(username, null, password, null, null, domain, null)
val proxyConfig = core.createProxyConfig()
val params = core.createAccountParams()
val identity = Factory.instance().createAddress("sip:$username@$domain")
proxyConfig.identityAddress = identity
params.identityAddress = identity
val address = Factory.instance().createAddress("sip:$domain")
address?.transport = transportType
proxyConfig.serverAddr = address?.asStringUriOnly()
proxyConfig.enableRegister(true)
params.serverAddress = address
params.registerEnabled = true
// Ensure push notification is enabled for this account
proxyConfig.isPushNotificationAllowed = true
params.pushNotificationAllowed = true
core.addAuthInfo(authInfo)
core.addProxyConfig(proxyConfig)
val account = core.createAccount(params)
core.addAccount(account)
core.defaultProxyConfig = proxyConfig
core.defaultAccount = account
core.addListener(coreListener)
core.start()