-
Notifications
You must be signed in to change notification settings - Fork 4
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
Remove Unwanted IPS from SDP #358
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,13 +184,13 @@ class TelnyxClient( | |
// reset audio mode to communication | ||
speakerState?.let { setSpeakerMode(it) } | ||
|
||
|
||
callStateLiveData.postValue(CallState.ACTIVE) | ||
callStateLiveData.value = CallState.ACTIVE | ||
client.callOngoing() | ||
|
||
} | ||
} | ||
this.addToCalls(acceptCall) | ||
Timber.d("Event-Check Active ${ calls[callId]?.getCallState()?.value}") | ||
return acceptCall | ||
} | ||
|
||
|
@@ -214,14 +214,19 @@ class TelnyxClient( | |
val inviteCallId: UUID = UUID.randomUUID() | ||
|
||
callId = inviteCallId | ||
val call = this | ||
|
||
// Create new peer | ||
peerConnection = Peer( | ||
context, client, providedTurn, providedStun, callId.toString(), | ||
object : PeerConnectionObserver() { | ||
override fun onIceCandidate(p0: IceCandidate?) { | ||
super.onIceCandidate(p0) | ||
peerConnection?.addIceCandidate(p0) | ||
Timber.d("Event-IceCandidate Generated") | ||
if (call.getCallState().value != CallState.ACTIVE){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little change here. Please add a space between parentheses and braces |
||
peerConnection?.addIceCandidate(p0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should check if peerConnection exist before printing the log that the ICE candidate was added |
||
Timber.d("Event-IceCandidate Added") | ||
} | ||
} | ||
} | ||
) | ||
|
@@ -311,7 +316,7 @@ class TelnyxClient( | |
* @param call, and instance of [Call] | ||
*/ | ||
internal fun addToCalls(call: Call) { | ||
calls.getOrPut(call.callId) { call } | ||
calls[call.callId] = call | ||
} | ||
|
||
/** | ||
|
@@ -1274,6 +1279,7 @@ class TelnyxClient( | |
peerConnection?.onRemoteSessionReceived(sdp) | ||
|
||
callStateLiveData.postValue(CallState.ACTIVE) | ||
callStateLiveData.value = CallState.ACTIVE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before |
||
|
||
val answerResponse = AnswerResponse( | ||
UUID.fromString(callId), | ||
|
@@ -1309,6 +1315,7 @@ class TelnyxClient( | |
) | ||
) | ||
callStateLiveData.postValue(CallState.ACTIVE) | ||
callStateLiveData.value = CallState.ACTIVE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as before |
||
} | ||
|
||
else -> { | ||
|
@@ -1320,6 +1327,9 @@ class TelnyxClient( | |
client.callOngoing() | ||
client.stopMediaPlayer() | ||
} | ||
answeredCall?.let { | ||
addToCalls(it) | ||
} | ||
|
||
} | ||
|
||
|
@@ -1405,6 +1415,7 @@ class TelnyxClient( | |
|
||
// Set global callID | ||
callId = offerCallId | ||
val call = this | ||
|
||
//retrieve custom headers | ||
val customHeaders = | ||
|
@@ -1414,8 +1425,12 @@ class TelnyxClient( | |
object : PeerConnectionObserver() { | ||
override fun onIceCandidate(p0: IceCandidate?) { | ||
super.onIceCandidate(p0) | ||
peerConnection?.addIceCandidate(p0) | ||
Timber.d("On IceCandidate Added") | ||
Timber.d("Event-IceCandidate Generated") | ||
Timber.d("Event-IceCandidate ${calls[callId]?.getCallState()?.value}") | ||
if (calls[callId]?.getCallState()?.value != CallState.ACTIVE){ | ||
peerConnection?.addIceCandidate(p0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check if peerConnection exist before printing the log There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Peer connection should always exit on line 1425 |
||
Timber.d("Event-IceCandidate Added") | ||
} | ||
} | ||
|
||
override fun onRenegotiationNeeded() { | ||
|
@@ -1540,8 +1555,6 @@ class TelnyxClient( | |
} | ||
|
||
override fun onAttachReceived(jsonObject: JsonObject) { | ||
/* val params = jsonObject.getAsJsonObject("params") | ||
val callId = UUID.fromString(params.get("callID").asString)*/ | ||
|
||
val attachCall = call!!.copy( | ||
context = context, | ||
|
@@ -1572,14 +1585,16 @@ class TelnyxClient( | |
// Set global callID | ||
callId = offerCallId | ||
|
||
|
||
peerConnection = Peer( | ||
context, client, providedTurn, providedStun, offerCallId.toString(), | ||
object : PeerConnectionObserver() { | ||
override fun onIceCandidate(p0: IceCandidate?) { | ||
super.onIceCandidate(p0) | ||
peerConnection?.addIceCandidate(p0) | ||
Timber.d("On IceCandidate Added") | ||
Timber.d("Event-IceCandidate Generated") | ||
if (calls[callId]?.getCallState()?.value != CallState.ACTIVE){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a space between parentheses and braces And check if peerConnection Exist before printing the log |
||
peerConnection?.addIceCandidate(p0) | ||
Timber.d("Event-IceCandidate Added") | ||
} | ||
} | ||
|
||
override fun onRenegotiationNeeded() { | ||
|
@@ -1608,7 +1623,7 @@ class TelnyxClient( | |
Call.ICE_CANDIDATE_DELAY | ||
) | ||
} | ||
|
||
attachCall.callStateLiveData.value = CallState.ACTIVE | ||
calls[attachCall.callId] = attachCall | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right?
In line
188
we are using postValue, which is thread-safe, and in the next line, we are using .value, which is not thread-safe, and they perform almost the same operation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah they are the same, the issue is callStateLiveData.postValue(CallState.ACTIVE) doesent set the value somehow (it just updates the observers) and I have to observe the value from the TelnyxClient.kt class might I don't want to do. I could create a separate variablle for CallState.ACTIVE but then there's not single souce of truth.
For thread safety
@Override public void setValue(T value) { super.setValue(value); }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I am actually using it :
if (call.getCallState().value != CallState.ACTIVE)
but somehow it doesn't print the latest value. Let me see if I can make it workThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMPORTANT NOTE: I just noticed that if you're in main thread and use postValue it will take a few more millis compared to setValue to dispatch the data. I had this happen when I fill a layout manually, with setValue it was instant but not with post.
-- Probably this is why it still has the previous value. I may have to observe then
https://stackoverflow.com/a/51299672/24361182
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the mutable livedata with a flow and deprecated livedata. This was in Todo for sometime and I think I will want to deprecate all mutable livedata infavour of flow because it's threadsafe.