From b2116487b93db3609295947018727c1dfe851364 Mon Sep 17 00:00:00 2001 From: isaacakakpo1 <134492608+isaacakakpo1@users.noreply.github.com> Date: Fri, 17 Nov 2023 08:55:15 +0000 Subject: [PATCH] Is/enh/remove unused libraries (#335) * Version Bump * Main Stash * Version Bump * Refactor TxSocket.kt --- telnyx_rtc/build.gradle | 2 +- .../main/java/com/telnyx/webrtc/sdk/Call.kt | 48 ++++++++++++------- .../com/telnyx/webrtc/sdk/TelnyxClient.kt | 21 ++++---- .../com/telnyx/webrtc/sdk/socket/TxSocket.kt | 5 +- .../com/telnyx/webrtc/sdk/TelnyxClientTest.kt | 32 +++++++++++++ 5 files changed, 78 insertions(+), 30 deletions(-) diff --git a/telnyx_rtc/build.gradle b/telnyx_rtc/build.gradle index eb9995ae..603dcf50 100644 --- a/telnyx_rtc/build.gradle +++ b/telnyx_rtc/build.gradle @@ -13,7 +13,7 @@ apply plugin: 'maven-publish' apply plugin: "com.bugsnag.android.gradle" def getVersionName = { -> - return "1.2.7" + return "1.3.0" } def getArtifactId = { -> diff --git a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/Call.kt b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/Call.kt index f11b1b8e..14a8e189 100644 --- a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/Call.kt +++ b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/Call.kt @@ -22,6 +22,7 @@ import com.telnyx.webrtc.sdk.socket.TxSocketListener import com.telnyx.webrtc.sdk.utilities.encodeBase64 import com.telnyx.webrtc.sdk.verto.receive.* import com.telnyx.webrtc.sdk.verto.send.* +import org.jetbrains.annotations.TestOnly import org.webrtc.IceCandidate import org.webrtc.SessionDescription import timber.log.Timber @@ -58,6 +59,9 @@ class Call( private var earlySDP = false + var inviteResponse:InviteResponse? = null + var answerResponse:AnswerResponse? = null + lateinit var callId: UUID private var telnyxSessionId: UUID? = null @@ -261,6 +265,8 @@ class Call( client.stopMediaPlayer() peerConnection?.release() peerConnection = null + answerResponse = null + inviteResponse = null } /** @@ -450,15 +456,17 @@ class Call( callStateLiveData.postValue(CallState.ACTIVE) + val answerResponse = AnswerResponse( + UUID.fromString(callId), + stringSdp, + customHeaders?.toCustomHeaders() ?: arrayListOf() + ) + this.answerResponse = answerResponse client.socketResponseLiveData.postValue( SocketResponse.messageReceived( ReceivedMessageBody( SocketMethod.ANSWER.methodName, - AnswerResponse( - UUID.fromString(callId), - stringSdp, - customHeaders?.toCustomHeaders() ?: arrayListOf() - ) + answerResponse ) ) ) @@ -467,15 +475,17 @@ class Call( earlySDP -> { callStateLiveData.postValue(CallState.CONNECTING) val stringSdp = peerConnection?.getLocalDescription()?.description + val answerResponse = AnswerResponse( + UUID.fromString(callId), + stringSdp!!, + customHeaders?.toCustomHeaders() ?: arrayListOf() + ) + this.answerResponse = answerResponse client.socketResponseLiveData.postValue( SocketResponse.messageReceived( ReceivedMessageBody( SocketMethod.ANSWER.methodName, - AnswerResponse( - UUID.fromString(callId), - stringSdp!!, - customHeaders?.toCustomHeaders() ?: arrayListOf() - ) + answerResponse ) ) ) @@ -563,18 +573,20 @@ class Call( peerConnection?.answer(AppSdpObserver()) + val inviteResponse = InviteResponse( + callId, + remoteSdp, + callerName, + callerNumber, + sessionId, + customHeaders = customHeaders?.toCustomHeaders() ?: arrayListOf() + ) + this.inviteResponse = inviteResponse client.socketResponseLiveData.postValue( SocketResponse.messageReceived( ReceivedMessageBody( SocketMethod.INVITE.methodName, - InviteResponse( - callId, - remoteSdp, - callerName, - callerNumber, - sessionId, - customHeaders = customHeaders?.toCustomHeaders() ?: arrayListOf() - ) + inviteResponse ) ) ) 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 9b936229..da877220 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 @@ -184,15 +184,18 @@ class TelnyxClient( } // Connect to new socket - socket.connect(this@TelnyxClient, providedHostAddress, providedPort, pushMetaData) - delay(1000) - // Login with stored configuration - credentialSessionConfig?.let { - credentialLogin(it) - } ?: tokenLogin(tokenSessionConfig!!) - - // Change an ongoing call's socket to the new socket. - call?.let { call?.socket = socket } + socket.connect(this@TelnyxClient, providedHostAddress, providedPort, pushMetaData) { + + //We can safely assume that the socket is connected at this point + // Login with stored configuration + credentialSessionConfig?.let { + credentialLogin(it) + } ?: tokenLogin(tokenSessionConfig!!) + + // Change an ongoing call's socket to the new socket. + call?.let { call?.socket = socket } + } + } } diff --git a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/socket/TxSocket.kt b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/socket/TxSocket.kt index bb64830e..4c8ba61b 100644 --- a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/socket/TxSocket.kt +++ b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/socket/TxSocket.kt @@ -47,7 +47,6 @@ class TxSocket( private lateinit var client: OkHttpClient private lateinit var socket: WebSocket - /** * Connects to the socket with the provided Host Address and Port which were used to create an instance of TxSocket * @param listener the [TelnyxClient] used to create an instance of TxSocket that contains our @@ -62,7 +61,8 @@ class TxSocket( listener: TelnyxClient, providedHostAddress: String? = Config.TELNYX_PROD_HOST_ADDRESS, providedPort: Int? = Config.TELNYX_PORT, - pushmetaData: PushMetaData? = null + pushmetaData: PushMetaData? = null, + onConnected:(Boolean) -> Unit = {} ) = launch { val loggingInterceptor = HttpLoggingInterceptor() @@ -128,6 +128,7 @@ class TxSocket( "[%s] Connection established :: $host_address", this@TxSocket.javaClass.simpleName ) + onConnected(true) listener.onConnectionEstablished() isConnected = true } 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 cf615862..bc97ea4f 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 @@ -10,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.arch.core.executor.testing.InstantTaskExecutorRule import androidx.lifecycle.LiveData import androidx.lifecycle.Observer +import com.google.gson.JsonArray import com.google.gson.JsonObject import com.telnyx.webrtc.sdk.model.AudioDevice import com.telnyx.webrtc.sdk.model.GatewayState @@ -501,6 +502,37 @@ class TelnyxClientTest : BaseTest() { Mockito.verify(client.call, Mockito.atLeast(1))?.onAnswerReceived(callMessage) } + @Test + fun `Test onAnswerReceived customHeaders`() { + client = Mockito.spy(TelnyxClient(mockContext)) + client.socket = Mockito.spy( + TxSocket( + host_address = "rtc.telnyx.com", + port = 14938, + ) + ) + val fakeCall = Mockito.spy(Call(mockContext, client, client.socket, "", audioManager)) + Mockito.`when`(client.call).thenReturn(fakeCall) + val callMessage = JsonObject() + val params = JsonObject() + val callID = UUID.randomUUID() + params.addProperty("callID", callID.toString()) + params.addProperty("sdp","sdp") + val dialogParams = JsonObject() + dialogParams.add("customHeaders", JsonArray().apply { + add(JsonObject().apply { + addProperty("X-key", "Value") + }) + }) + params.add("dialogParams", dialogParams) + callMessage.add("params", params) + client.onAnswerReceived(callMessage) + Mockito.verify(client.call, Mockito.atLeast(1))?.onAnswerReceived(callMessage) + assert(fakeCall.answerResponse != null) + } + + + @Test fun `Test onMediaReceived calls call related method`() { client = Mockito.spy(TelnyxClient(mockContext))