diff --git a/app/src/main/kotlin/com/tutpro/baresip/Account.kt b/app/src/main/kotlin/com/tutpro/baresip/Account.kt index d98c0b70..a293fb20 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Account.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Account.kt @@ -234,7 +234,7 @@ class Account(val accp: Long, virtualAor: String? = null) { return if (nickName != "") nickName else - aor.split(":")[1].substringBefore(";") + luri.removePrefix("sip:") } private fun removeAudioCodecsStartingWith(prefix: String) { diff --git a/app/src/main/kotlin/com/tutpro/baresip/AccountsScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/AccountsScreen.kt index dc2b9817..6d9bc14c 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/AccountsScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/AccountsScreen.kt @@ -208,14 +208,22 @@ fun NewAccount(navController: NavController) { if (Account.ofAor(aor) != null) { alertTitle.value = ctx.getString(R.string.notice) 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 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" ) + 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) { alertTitle.value = ctx.getString(R.string.notice) alertMessage.value = ctx.getString(R.string.account_allocation_failure) @@ -225,7 +233,7 @@ fun NewAccount(navController: NavController) { val acc = ua.account 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() return acc } // createNew diff --git a/app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt b/app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt index 0447ac15..0a4e5dc1 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt @@ -98,11 +98,10 @@ class UserAgent(val uap: Long, virtualAccount: Account? = null) { return null } - fun uaAlloc(uri: String): UserAgent? { + fun uaAlloc(uri: String): Long { val uap = Api.ua_alloc(uri) - if (uap != 0L) return UserAgent(uap) - Log.e(TAG, "Failed to allocate UserAgent for $uri") - return null + if (uap == 0L) Log.e(TAG, "Failed to allocate UserAgent for $uri") + return uap } fun findAorIndex(aor: String): Int? {