Commit 1ce1601c authored by Christophe Deschamps's avatar Christophe Deschamps
Browse files

SIP Account login & push GW fixes


Former-commit-id: 05ca3d149df1265f21a6d58fac43d20b87178ed0
parent e9de1110
......@@ -23,7 +23,7 @@ size=vga
tunnel=disabled
push_notification=1
auto_start=1
debug=0
debug=1
[tunnel]
host=
......
package org.lindoor.entities
import android.text.TextUtils
import androidx.lifecycle.MutableLiveData
import org.lindoor.LindoorApplication
import org.lindoor.LindoorApplication.Companion.coreContext
import org.lindoor.LindoorApplication.Companion.corePreferences
import org.lindoor.utils.cdlog
import org.lindoor.utils.extensions.xDigitsUUID
import org.linphone.core.AccountCreator
import org.linphone.core.AccountCreatorListenerStub
......@@ -12,7 +14,7 @@ import java.util.*
object Account {
private const val PUSH_GW_REF_KEY = "lindoor_pushgateway"
private const val PUSH_GW_ID_KEY = "lindoor_pushgateway"
private const val PUSH_GW_USER_PREFIX = "lindoor_generated"
private const val PUSH_GW_DISPLAY_NAME = "Lindoor"
......@@ -21,15 +23,19 @@ object Account {
}
fun get(): ProxyConfig? {
return coreContext.core.defaultProxyConfig
coreContext.core.proxyConfigList.forEach {
if (PUSH_GW_ID_KEY != it.idkey)
return it
}
return null
}
fun lindoorAccountCreate(accountCreator: AccountCreator) {
accountCreator.createProxyConfig().refKey = PUSH_GW_REF_KEY
accountCreator.createProxyConfig().idkey = PUSH_GW_ID_KEY
}
fun lindoorAccountLogin(accountCreator: AccountCreator) {
accountCreator.createProxyConfig().refKey = PUSH_GW_REF_KEY
accountCreator.createProxyConfig().idkey = PUSH_GW_ID_KEY
}
fun sipAccountLogin(
......@@ -40,30 +46,30 @@ object Account {
) {
val proxyConfig: ProxyConfig? = accountCreator.createProxyConfig()
proxyConfig?.expires = expiration.toInt()
proxy?.also {
proxyConfig?.serverAddr = it
}
proxyConfig?.serverAddr = if (!TextUtils.isEmpty(proxy)) proxy else accountCreator.domain
if (pushGateway() != null)
linkProxiesWithPushGateway()
linkProxiesWithPushGateway(pushReady)
else
createPushGateway(pushReady)
}
fun pushGateway(): ProxyConfig? {
return coreContext.core.getProxyConfigByIdkey(PUSH_GW_REF_KEY)
return coreContext.core.getProxyConfigByIdkey(PUSH_GW_ID_KEY)
}
fun createPushGateway(pushReady: MutableLiveData<Boolean>) {
coreContext.core.loadConfigFromXml(LindoorApplication.corePreferences.lindoorAccountDefaultValuesPath)
coreContext.core.loadConfigFromXml(corePreferences.lindoorAccountDefaultValuesPath)
val accountCreator =
coreContext.core.createAccountCreator(LindoorApplication.corePreferences.xmlRpcServerUrl)
coreContext.core.createAccountCreator(corePreferences.xmlRpcServerUrl)
accountCreator.language = Locale.getDefault().language
val user: String = PUSH_GW_USER_PREFIX + xDigitsUUID()
val pass = UUID.randomUUID().toString()
accountCreator.domain = corePreferences.loginDomain
accountCreator.username = user
accountCreator.password = pass
accountCreator.email = "$user@${accountCreator.domain}"
accountCreator.displayName = PUSH_GW_DISPLAY_NAME
accountCreator.addListener(object : AccountCreatorListenerStub() {
override fun onCreateAccount(
creator: AccountCreator?,
......@@ -73,29 +79,30 @@ object Account {
if (status == AccountCreator.Status.AccountCreated) // TODO Adjust when server setup
creator?.also {
val pushGw = it.createProxyConfig()
pushGw.refKey = PUSH_GW_REF_KEY
pushGw.idkey = PUSH_GW_ID_KEY
pushGw.enableRegister(true)
pushGw.enablePublish(false)
pushGw.expires = 31536000
pushGw.serverAddr = "sips:${it.domain}:5061;transport=tls"
pushGw.route = pushGw.serverAddr
pushGw.isPushNotificationAllowed = true
linkProxiesWithPushGateway()
pushReady.value = true
linkProxiesWithPushGateway(pushReady)
}
}
})
accountCreator.createAccount()
if ( accountCreator.createAccount()!= AccountCreator.Status.RequestOk)
pushReady.value = false
}
fun linkProxiesWithPushGateway() {
fun linkProxiesWithPushGateway(pushReady: MutableLiveData<Boolean>) {
pushGateway()?.also { pgw ->
coreContext.core.proxyConfigList.forEach {
if (it.refKey != PUSH_GW_REF_KEY) {
if (it.idkey != PUSH_GW_ID_KEY) {
it.dependency = pgw
}
}
}
pushReady.value = true
}
......
......@@ -141,7 +141,6 @@ class NotificationsManager(private val context: Context) {
}
override fun onNextVideoFrameDecoded(call: Call?) {
cdlog("got a frame")
if (call != null) {
call.takeVideoSnapshot(call.callLog.historyEvent().mediaThumbnail.absolutePath)
GlobalScope.launch(context = Dispatchers.Main) {
......@@ -410,7 +409,6 @@ class NotificationsManager(private val context: Context) {
GlobalScope.launch(context = Dispatchers.Main) {
if (call.state == Call.State.IncomingEarlyMedia) {
call.requestNotifyNextVideoFrameDecoded()
cdlog("requesting video frame")
}
}
}
......
......@@ -10,6 +10,7 @@ import org.lindoor.linphonecore.extensions.callLogsWithNonEmptyCallId
import org.lindoor.linphonecore.extensions.isNew
import org.lindoor.linphonecore.extensions.toHumanReadable
import org.lindoor.store.DeviceStore
import org.lindoor.utils.cdlog
import org.linphone.core.*
class AccountViewModel : ViewModel() {
......@@ -35,6 +36,9 @@ class AccountViewModel : ViewModel() {
}
init {
LindoorApplication.coreContext.core.proxyConfigList.forEach {
cdlog("${it.identityAddress.asString()} ${it.idkey}")
}
LindoorApplication.coreContext.core.addListener(coreListener)
}
......
......@@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.lindoor.LindoorApplication
import org.lindoor.LindoorApplication.Companion.coreContext
import org.lindoor.LindoorApplication.Companion.corePreferences
import org.linphone.core.AccountCreator
import org.linphone.core.TransportType
import java.util.*
......@@ -18,6 +19,7 @@ open class CreatorAssistantViewModel(defaultValuePath: String) : ViewModel() {
accountCreator =
coreContext.core.createAccountCreator(LindoorApplication.corePreferences.xmlRpcServerUrl)
accountCreator.language = Locale.getDefault().language
accountCreator.domain = corePreferences.loginDomain
}
fun setUsername(field: Pair<MutableLiveData<String>, MutableLiveData<Boolean>>): AccountCreator.UsernameStatus? {
......
......@@ -4,6 +4,7 @@ import androidx.lifecycle.MutableLiveData
import org.lindoor.LindoorApplication.Companion.corePreferences
import org.lindoor.entities.Account
import org.lindoor.ui.assistant.CreatorAssistantViewModel
import org.lindoor.utils.cdlog
import org.linphone.core.AccountCreator
import org.linphone.core.AccountCreatorListenerStub
......
......@@ -47,6 +47,7 @@ class LoginSipAccountFragment : CreatorAssistantFragment() {
model.setTransport(TransportType.values()[model.transport.value!!])
if (model.valid()) {
hideKeyboard()
showProgress()
Account.sipAccountLogin(
model.accountCreator,
model.proxy.first.value,
......@@ -55,10 +56,11 @@ class LoginSipAccountFragment : CreatorAssistantFragment() {
)
}
}
model.pushReady.observe(viewLifecycleOwner, Observer { status ->
mainactivity.navController.popBackStack(R.id.navigation_devices, false)
if (status) {
model.pushReady.observe(viewLifecycleOwner, Observer { pushready ->
hideProgress()
if (pushready) {
DialogUtil.info("sip_account_created")
mainactivity.navController.popBackStack(R.id.navigation_devices, false)
} else
DialogUtil.error("failed_creating_pushgateway")
})
......
......@@ -8,14 +8,14 @@ class LoginSipAccountViewModel :
CreatorAssistantViewModel(corePreferences.sipAccountDefaultValuesPath) {
var username: Pair<MutableLiveData<String>, MutableLiveData<Boolean>> =
Pair(MutableLiveData<String>(), MutableLiveData<Boolean>(false))
Pair(MutableLiveData(), MutableLiveData<Boolean>(false))
var domain: Pair<MutableLiveData<String>, MutableLiveData<Boolean>> =
Pair(MutableLiveData<String>(), MutableLiveData<Boolean>(false))
Pair(MutableLiveData(), MutableLiveData<Boolean>(false))
var pass1: Pair<MutableLiveData<String>, MutableLiveData<Boolean>> =
Pair(MutableLiveData<String>(), MutableLiveData<Boolean>(false))
Pair(MutableLiveData(), MutableLiveData<Boolean>(false))
var transport: MutableLiveData<Int> = MutableLiveData<Int>(0)
var proxy: Pair<MutableLiveData<String>, MutableLiveData<Boolean>> =
Pair(MutableLiveData<String>(), MutableLiveData<Boolean>(false))
var proxy: Pair<MutableLiveData<String?>, MutableLiveData<Boolean>> =
Pair(MutableLiveData(), MutableLiveData<Boolean>(false))
var expiration: Pair<MutableLiveData<String>, MutableLiveData<Boolean>> = Pair(
MutableLiveData<String>(
corePreferences.config.getString(
......
......@@ -23,8 +23,7 @@ class RemoteAnyAccountViewModel : ViewModel() {
override fun onConfiguringStatus(core: Core, status: ConfiguringState, message: String?) {
if (status == ConfiguringState.Successful) {
if (Account.pushGateway() != null) {
Account.linkProxiesWithPushGateway()
pushReady.postValue(true)
Account.linkProxiesWithPushGateway(pushReady)
} else
Account.createPushGateway(pushReady)
}
......
......@@ -43,9 +43,9 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
style='@{"account_info"}'
android:lines="2"
android:lines="3"
android:visibility="@{model.pushGw != null &amp;&amp; model.account != model.pushGw ? View.VISIBLE : View.GONE}"
android:text='@{model.accountDesc}' />
android:text='@{model.pushGWDesc}' />
<org.lindoor.ui.widgets.LRoundRectButton
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment