Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is/enh/remove unused libraries #335

Merged
merged 5 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion telnyx_rtc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { ->
Expand Down
48 changes: 30 additions & 18 deletions telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/Call.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -261,6 +265,8 @@ class Call(
client.stopMediaPlayer()
peerConnection?.release()
peerConnection = null
answerResponse = null
inviteResponse = null
}

/**
Expand Down Expand Up @@ -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
)
)
)
Expand All @@ -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
)
)
)
Expand Down Expand Up @@ -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
)
)
)
Expand Down
21 changes: 12 additions & 9 deletions telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/TelnyxClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -128,6 +128,7 @@ class TxSocket(
"[%s] Connection established :: $host_address",
[email protected]
)
onConnected(true)
listener.onConnectionEstablished()
isConnected = true
}
Expand Down
32 changes: 32 additions & 0 deletions telnyx_rtc/src/test/java/com/telnyx/webrtc/sdk/TelnyxClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
Loading