Skip to content

Commit

Permalink
- Fix UnitTest Failures
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacakakpo1 committed Jul 24, 2024
1 parent 8233b26 commit 31f625a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
19 changes: 15 additions & 4 deletions app/src/main/java/com/telnyx/webrtc/sdk/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
}

Expand Down Expand Up @@ -98,7 +110,6 @@ class MainViewModel @Inject constructor(
fun getIsOnLoudSpeakerStatus(): LiveData<Boolean>? = currentCall?.getIsOnLoudSpeakerStatus()



fun doLoginWithToken(tokenConfig: TokenConfig) {
telnyxClient?.tokenLogin(tokenConfig)
}
Expand All @@ -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"))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ class TelnyxClient(
host_address = Config.TELNYX_PROD_HOST_ADDRESS,
port = Config.TELNYX_PORT
)
//socketResponseLiveData = MutableLiveData<SocketResponse<ReceivedMessageBody>>()
registerNetworkCallback()
}

Expand Down Expand Up @@ -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
*
*/
Expand Down
10 changes: 5 additions & 5 deletions telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/peer/Peer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -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)
}
Expand All @@ -219,7 +219,7 @@ internal class Peer(
}

}
}, statsInitial, statsInterval)
}, STATS_INITIAL, STATS_INTERVAL)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -240,14 +240,14 @@ 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",
port = 14938,
)
)

client.connect(txPushMetaData = null)

val config = TokenConfig(
MOCK_TOKEN,
Expand All @@ -268,15 +268,16 @@ 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",
port = 14938,
)
)

client.connect(txPushMetaData = null)

val config = TokenConfig(
anyString(),
"test",
Expand Down

0 comments on commit 31f625a

Please sign in to comment.