diff --git a/app/src/main/java/com/telnyx/webrtc/sdk/ui/MainViewModel.kt b/app/src/main/java/com/telnyx/webrtc/sdk/ui/MainViewModel.kt index b6144930..3dac62b1 100644 --- a/app/src/main/java/com/telnyx/webrtc/sdk/ui/MainViewModel.kt +++ b/app/src/main/java/com/telnyx/webrtc/sdk/ui/MainViewModel.kt @@ -48,9 +48,21 @@ class MainViewModel @Inject constructor( telnyxClient = TelnyxClient(context) providedServerConfig?.let { - telnyxClient?.connect(it,credentialConfig!!,txPushMetaData,true) + telnyxClient?.connect(it, credentialConfig!!, txPushMetaData, true) } ?: run { - telnyxClient?.connect(txPushMetaData = txPushMetaData, credentialConfig = credentialConfig!!, autoLogin = true) + if (tokenConfig != null) { + telnyxClient?.connect( + txPushMetaData = txPushMetaData, + tokenConfig = tokenConfig, + autoLogin = true + ) + } else { + telnyxClient?.connect( + txPushMetaData = txPushMetaData, + credentialConfig = credentialConfig!!, + autoLogin = true + ) + } } } @@ -98,7 +110,6 @@ class MainViewModel @Inject constructor( fun getIsOnLoudSpeakerStatus(): LiveData? = currentCall?.getIsOnLoudSpeakerStatus() - fun doLoginWithToken(tokenConfig: TokenConfig) { telnyxClient?.tokenLogin(tokenConfig) } @@ -109,7 +120,7 @@ class MainViewModel @Inject constructor( destinationNumber: String, clientState: String ) { - val call = telnyxClient?.newInvite( + val call = telnyxClient?.newInvite( callerName, callerNumber, destinationNumber, clientState, mapOf(Pair("X-test", "123456")) ) diff --git a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/TelnyxClient.kt b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/TelnyxClient.kt index da442172..444ca894 100644 --- a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/TelnyxClient.kt +++ b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/TelnyxClient.kt @@ -400,7 +400,6 @@ class TelnyxClient( host_address = Config.TELNYX_PROD_HOST_ADDRESS, port = Config.TELNYX_PORT ) - //socketResponseLiveData = MutableLiveData>() registerNetworkCallback() } @@ -483,7 +482,8 @@ class TelnyxClient( * (Get this from push notification - fcm data payload) * required fot push calls to work * - * @param autoLogin, if true, the SDK will automatically log in with the provided credentials on connection established + * @param autoLogin, if true, the SDK will automatically log in with + * the provided credentials on connection established * We recommend setting this to true * */ diff --git a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/peer/Peer.kt b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/peer/Peer.kt index b5905154..b4690bda 100644 --- a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/peer/Peer.kt +++ b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/peer/Peer.kt @@ -49,13 +49,13 @@ internal class Peer( companion object { private const val AUDIO_LOCAL_TRACK_ID = "audio_local_track" private const val AUDIO_LOCAL_STREAM_ID = "audio_local_stream" + private const val CANDIDATE_LIMIT : Int = 5 + private const val STATS_INTERVAL : Long = 2000L + private const val STATS_INITIAL : Long = 0L } private val rootEglBase: EglBase = EglBase.create() - private val candidateNumber = 5 - private val statsInterval = 2000L - private val statsInitial = 0L internal var debugStatsId = UUID.randomUUID() @@ -193,7 +193,7 @@ internal class Peer( val jsonOutbound = gson.toJsonTree(value) outBoundStats.add(jsonOutbound) } - if (value.type == "candidate-pair" && candidateParis.size() < candidateNumber) { + if (value.type == "candidate-pair" && candidateParis.size() < CANDIDATE_LIMIT) { val jsonCandidatePair = gson.toJsonTree(value) candidateParis.add(jsonCandidatePair) } @@ -219,7 +219,7 @@ internal class Peer( } } - }, statsInitial, statsInterval) + }, STATS_INITIAL, STATS_INTERVAL) } diff --git a/telnyx_rtc/src/test/java/com/telnyx/webrtc/sdk/TelnyxClientTest.kt b/telnyx_rtc/src/test/java/com/telnyx/webrtc/sdk/TelnyxClientTest.kt index 5cd5bf2b..f00aba7e 100644 --- a/telnyx_rtc/src/test/java/com/telnyx/webrtc/sdk/TelnyxClientTest.kt +++ b/telnyx_rtc/src/test/java/com/telnyx/webrtc/sdk/TelnyxClientTest.kt @@ -183,13 +183,13 @@ class TelnyxClientTest : BaseTest() { @Test fun `login with valid credentials - login sent to socket and json received`() { client = Mockito.spy(TelnyxClient(mockContext)) + client.connect(txPushMetaData = null) client.socket = Mockito.spy( TxSocket( host_address = "rtc.telnyx.com", port = 14938, ) ) - client.connect(txPushMetaData = null) val config = CredentialConfig( MOCK_USERNAME_TEST, @@ -210,13 +210,13 @@ class TelnyxClientTest : BaseTest() { @Test fun `login with invalid credentials - login sent to socket and json received`() { client = Mockito.spy(TelnyxClient(mockContext)) + client.connect(txPushMetaData = null) client.socket = Mockito.spy( TxSocket( host_address = "rtc.telnyx.com", port = 14938, ) ) - client.connect(txPushMetaData = null) val config = CredentialConfig( "asdfasass", @@ -240,6 +240,7 @@ class TelnyxClientTest : BaseTest() { @Test fun `login with valid token - login sent to socket and json received`() { client = Mockito.spy(TelnyxClient(mockContext)) + client.connect(txPushMetaData = null) client.socket = Mockito.spy( TxSocket( host_address = "rtc.telnyx.com", @@ -247,7 +248,6 @@ class TelnyxClientTest : BaseTest() { ) ) - client.connect(txPushMetaData = null) val config = TokenConfig( MOCK_TOKEN, @@ -268,6 +268,9 @@ class TelnyxClientTest : BaseTest() { @Test fun `login with invalid token - login sent to socket and json received`() { client = Mockito.spy(TelnyxClient(mockContext)) + + + client.connect(txPushMetaData = null) client.socket = Mockito.spy( TxSocket( host_address = "rtc.telnyx.com", @@ -275,8 +278,6 @@ class TelnyxClientTest : BaseTest() { ) ) - client.connect(txPushMetaData = null) - val config = TokenConfig( anyString(), "test",