Allocate UserAgent only once

If given, show also port/transport of account's SIP URI
This commit is contained in:
Juha Heinanen
2026-08-07 17:36:47 +03:00
parent ad39438ebe
commit 283cfdfb2f
3 changed files with 15 additions and 8 deletions

View File

@ -234,7 +234,7 @@ class Account(val accp: Long, virtualAor: String? = null) {
return if (nickName != "") return if (nickName != "")
nickName nickName
else else
aor.split(":")[1].substringBefore(";") luri.removePrefix("sip:")
} }
private fun removeAudioCodecsStartingWith(prefix: String) { private fun removeAudioCodecsStartingWith(prefix: String) {

View File

@ -208,14 +208,22 @@ fun NewAccount(navController: NavController) {
if (Account.ofAor(aor) != null) { if (Account.ofAor(aor) != null) {
alertTitle.value = ctx.getString(R.string.notice) alertTitle.value = ctx.getString(R.string.notice)
alertMessage.value = alertMessage.value =
String.format(ctx.getString(R.string.account_exists), aor.split(":")[1]) String.format(ctx.getString(R.string.account_exists), aor.removePrefix("sip:"))
showAlert.value = true showAlert.value = true
return null return null
} }
val ua = UserAgent.uaAlloc( val uap = UserAgent.uaAlloc(
"<$aor>;stunserver=\"stun:stun.l.google.com:19302\";regq=0.5;pubint=0;regint=0;check_origin=no;mwi=no" "<$aor>;stunserver=\"stun:stun.l.google.com:19302\";regq=0.5;pubint=0;regint=0;check_origin=no;mwi=no"
) )
if (uap == 0L) {
alertTitle.value = ctx.getString(R.string.notice)
alertMessage.value = ctx.getString(R.string.account_allocation_failure)
showAlert.value = true
return null
}
val ua = UserAgent.ofUap(uap)
if (ua == null) { if (ua == null) {
alertTitle.value = ctx.getString(R.string.notice) alertTitle.value = ctx.getString(R.string.notice)
alertMessage.value = ctx.getString(R.string.account_allocation_failure) alertMessage.value = ctx.getString(R.string.account_allocation_failure)
@ -225,7 +233,7 @@ fun NewAccount(navController: NavController) {
val acc = ua.account val acc = ua.account
acc.checkOrigin = true acc.checkOrigin = true
Log.d(TAG, "Allocated UA ${ua.uap} with SIP URI ${acc.luri}") Log.d(TAG, "Allocated UA $uap with SIP URI ${acc.luri}")
Account.saveAccounts() Account.saveAccounts()
return acc return acc
} // createNew } // createNew

View File

@ -98,11 +98,10 @@ class UserAgent(val uap: Long, virtualAccount: Account? = null) {
return null return null
} }
fun uaAlloc(uri: String): UserAgent? { fun uaAlloc(uri: String): Long {
val uap = Api.ua_alloc(uri) val uap = Api.ua_alloc(uri)
if (uap != 0L) return UserAgent(uap) if (uap == 0L) Log.e(TAG, "Failed to allocate UserAgent for $uri")
Log.e(TAG, "Failed to allocate UserAgent for $uri") return uap
return null
} }
fun findAorIndex(aor: String): Int? { fun findAorIndex(aor: String): Int? {