Skip to content

Commit

Permalink
Merge pull request #41 from team-telnyx/WEBRTC-619
Browse files Browse the repository at this point in the history
[WEBRTC-619] Add telnyx session ID and leg ID to Call object
  • Loading branch information
Oliver-Zimmerman authored Jul 8, 2021
2 parents 3c66b1d + f16b2a2 commit 248336a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 3 deletions.
29 changes: 29 additions & 0 deletions telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/Call.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class Call(

lateinit var callId: UUID

private var telnyxSessionId: UUID? = null
private var telnyxLegId: UUID? = null

private val callStateLiveData = MutableLiveData(CallState.NEW)

// Ongoing call options
Expand Down Expand Up @@ -290,6 +293,24 @@ class Call(
*/
fun getIsOnLoudSpeakerStatus(): LiveData<Boolean> = loudSpeakerLiveData

/**
* Returns the TelnyxSessionId set as a response
* from an invite or ringing socket call
* @return [UUID]
*/
fun getTelnyxSessionId(): UUID? {
return telnyxSessionId
}

/**
* Returns the TelnyxSessionId set as a response
* from an invite or ringing socket call
* @return [UUID]
*/
fun getTelnyxLegId(): UUID? {
return telnyxLegId
}

/**
* Resets all call options, primarily hold, mute and loudspeaker state, as well as the earlySDP boolean value.
* @return [LiveData]
Expand Down Expand Up @@ -411,6 +432,8 @@ class Call(
val remoteSdp = params.get("sdp").asString
val callerName = params.get("caller_id_name").asString
val callerNumber = params.get("caller_id_number").asString
telnyxSessionId = UUID.fromString(params.get("telnyx_session_id").asString)
telnyxLegId = UUID.fromString(params.get("telnyx_leg_id").asString)

//Set global callID
callId = offerCallId
Expand Down Expand Up @@ -448,6 +471,12 @@ class Call(
client.addToCalls(this)
}

override fun onRingingReceived(jsonObject: JsonObject) {
val params = jsonObject.getAsJsonObject("params")
telnyxSessionId = UUID.fromString(params.get("telnyx_session_id").asString)
telnyxLegId = UUID.fromString(params.get("telnyx_leg_id").asString)
}

override fun onIceCandidateReceived(iceCandidate: IceCandidate) {
callStateLiveData.postValue(CallState.CONNECTING)
Timber.d(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class TelnyxClient(

private var socketReconnection: TxSocket? = null


internal var isNetworkCallbackRegistered = false
private val networkCallback = object : ConnectivityHelper.NetworkCallback() {
override fun onNetworkAvailable() {
Expand Down Expand Up @@ -147,6 +146,7 @@ class TelnyxClient(
host_address = Config.TELNYX_HOST_ADDRESS,
port = Config.TELNYX_PORT
)

registerNetworkCallback()
}

Expand Down Expand Up @@ -497,6 +497,11 @@ class TelnyxClient(
call?.onOfferReceived(jsonObject)
}

override fun onRingingReceived(jsonObject: JsonObject) {
Timber.d("[%s] :: onRingingReceived [%s]", this@TelnyxClient.javaClass.simpleName, jsonObject)
call?.onRingingReceived(jsonObject)
}

override fun onIceCandidateReceived(iceCandidate: IceCandidate) {
call?.onIceCandidateReceived(iceCandidate)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ enum class SocketMethod(var methodName: String) {
MODIFY("telnyx_rtc.modify"),
MEDIA("telnyx_rtc.media"),
INFO("telnyx_rtc.info"),
RINGING("telnyx_rtc.ringing"),
LOGIN("login")
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class TxSocket(
INVITE.methodName -> {
listener.onOfferReceived(jsonObject)
}
RINGING.methodName -> {
listener.onRingingReceived(jsonObject)
}
}
}
jsonObject.has("error") -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ interface TxSocketListener {
*/
fun onOfferReceived(jsonObject: JsonObject)

/**
* Fires once we receive a ringing socket response, containing Telnyx information
* @param jsonObject, the socket response in a jsonObject format
* @see [TxSocket]
*/
fun onRingingReceived(jsonObject: JsonObject)

/**
* Fires when a usable IceCandidate has been received
* @param iceCandidate, the [IceCandidate] that was received
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ class TelnyxClientTest : BaseTest() {
Thread.sleep(3000)
Mockito.verify(client.socket, Mockito.times(1)).send(any(SendingMessageBody::class.java))
Mockito.verify(client, Mockito.times(0)).onLoginSuccessful(jsonMock)

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class TxSocketTest : BaseTest() {
MockKAnnotations.init(this, true)
Mockito.`when`(application.applicationContext).thenReturn(mockContext)

BuildConfig.IS_TESTING.set(true);
BuildConfig.IS_TESTING.set(true)

every {socket.callOngoing()} just Runs
every {socket.callNotOngoing()} just Runs
Expand Down Expand Up @@ -182,6 +182,7 @@ class TxSocketTest : BaseTest() {

@Test
fun `set call to ongoing`() {
BuildConfig.IS_TESTING.set(true)
socket = Mockito.spy(TxSocket(
host_address = "rtc.telnyx.com",
port = 14938,
Expand Down

0 comments on commit 248336a

Please sign in to comment.