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

Feature/main webrtc 2356 hold unhold for demo app #360

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 8 additions & 1 deletion app/src/main/java/com/telnyx/webrtc/sdk/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ class MainActivity : AppCompatActivity() {
callInstanceFragment?.let {
supportFragmentManager.beginTransaction().remove(it).commit()
}
mainViewModel.onByeReceived(callId)
}
}
}
Expand Down Expand Up @@ -693,7 +694,6 @@ class MainActivity : AppCompatActivity() {
isActiveBye = true
it.endCall(it.callId)
}.also {
mainViewModel.setCurrentCall(callId)
onAcceptCall(callId, callerIdNumber)
}

Expand All @@ -702,6 +702,13 @@ class MainActivity : AppCompatActivity() {
incomingActiveCallSectionId.rejectCurrentCall.setOnClickListener {
onRejectActiveCall(callId)
}
incomingActiveCallSectionId.holdAndAccept.setOnClickListener {
mainViewModel.currentCall?.let {
mainViewModel.onHoldUnholdPressed(it.callId)
}.also {
onAcceptCall(callId, callerIdNumber)
}
}
}

}
Expand Down
32 changes: 27 additions & 5 deletions app/src/main/java/com/telnyx/webrtc/sdk/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.telnyx.webrtc.sdk.model.TxServerConfiguration
import com.telnyx.webrtc.sdk.verto.receive.ReceivedMessageBody
import com.telnyx.webrtc.sdk.verto.receive.SocketResponse
import dagger.hilt.android.lifecycle.HiltViewModel
import org.slf4j.Logger
import timber.log.Timber
import java.util.*
import javax.inject.Inject
Expand All @@ -33,8 +32,7 @@ class MainViewModel @Inject constructor(
private var telnyxClient: TelnyxClient? = null

var currentCall: Call? = null
private var previousCall: Call? = null

private val holdedCalls = mutableSetOf<Call>()
private var calls: Map<UUID, Call> = mapOf()

fun initConnection(
Expand Down Expand Up @@ -98,8 +96,11 @@ class MainViewModel @Inject constructor(
calls = telnyxClient?.getActiveCalls()!!
Log.e("setCall Previous", currentCall?.callId.toString())
Log.e("setCall Current", callId.toString())

if (calls.size > 1) {
previousCall = currentCall
currentCall?.let {
holdedCalls.add(it)
}
}
currentCall = calls[callId]!!
}
Expand Down Expand Up @@ -148,15 +149,29 @@ class MainViewModel @Inject constructor(
if (currentCall != null) {
telnyxClient?.endCall(currentCall?.callId!!)
}
//dev note - do we need it???
currentCall?.endCall(currentCall?.callId!!)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit strange to do it in both places? I believe they are referencing the same call? I believe we can remove it.

Copy link
Collaborator Author

@wojciechowskiradek wojciechowskiradek Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will change comment and push changes again

}
previousCall?.let {

holdedCalls.lastOrNull()?.let {
currentCall = it

if (currentCall?.getIsOnHoldStatus()?.value == true)
onHoldUnholdPressed(currentCall?.callId!!)

holdedCalls.remove(it)
}
}

fun onHoldUnholdPressed(callId: UUID) {
currentCall?.onHoldUnholdPressed(callId)
currentCall?.let {
if (it.getIsOnHoldStatus().value == true)
holdedCalls.add(it)

if (it.getIsOnHoldStatus().value == false)
holdedCalls.remove(it)
}
}

fun onMuteUnmutePressed() {
Expand All @@ -181,4 +196,11 @@ class MainViewModel @Inject constructor(
fun changeAudioOutput(audioDevice: AudioDevice) {
telnyxClient?.setAudioOutputDevice(audioDevice)
}

fun onByeReceived(callId: UUID) {
Timber.d("onByeReceived $callId")
holdedCalls.firstOrNull { it.callId == callId }?.let {
holdedCalls.remove(it)
}
}
}
5 changes: 2 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/call_state_text_value" />



<include
android:id="@+id/incoming_active_call_section_id"
layout="@layout/include_incoming_activel_section"
android:layout_width="0dp"
android:layout_height="360dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_medium"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/call_state_text_value" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_call_instance"
android:layout_width="0dp"
Expand Down
66 changes: 51 additions & 15 deletions app/src/main/res/layout/include_incoming_activel_section.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
android:id="@+id/endAndAccept"
android:clickable="true"
android:layout_width="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/incoming_call_id"
android:layout_marginTop="@dimen/spacing_huge"
android:layout_marginStart="@dimen/spacing_huge"
android:layout_marginBottom="@dimen/spacing_huge"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/reject_current_call"
app:layout_constraintStart_toEndOf="@id/guideline_start"
android:layout_height="wrap_content">
android:layout_marginTop="@dimen/spacing_huge"
android:layout_marginStart="@dimen/spacing_normal"
android:layout_marginBottom="@dimen/spacing_huge">


<ImageView
Expand Down Expand Up @@ -62,22 +62,20 @@
android:layout_height="wrap_content"
android:text="@string/end_and_accept"
android:layout_marginTop="15dp"
app:layout_constraintStart_toStartOf="@id/endAndAccept"
app:layout_constraintEnd_toEndOf="@+id/endAndAccept"
app:layout_constraintTop_toBottomOf="@+id/endAndAccept"
android:layout_marginStart="@dimen/spacing_huge"
app:layout_constraintStart_toEndOf="@id/guideline_start"/>
app:layout_constraintTop_toBottomOf="@+id/endAndAccept"/>

<RelativeLayout
android:id="@+id/reject_current_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:layout_constraintTop_toBottomOf="@+id/incoming_call_id"
android:layout_marginTop="@dimen/spacing_huge"
android:layout_marginStart="@dimen/spacing_huge"
android:layout_marginEnd="@dimen/spacing_huge"
app:layout_constraintStart_toEndOf="@id/guideline_start"
app:layout_constraintEnd_toStartOf="@id/guideline_end"
android:layout_marginBottom="@dimen/spacing_huge"
android:layout_height="wrap_content">
android:layout_marginTop="@dimen/spacing_huge"
android:layout_marginBottom="@dimen/spacing_huge">

<ImageView
android:layout_width="70dp"
Expand All @@ -92,18 +90,56 @@


</RelativeLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reject_incoming"
android:layout_marginTop="15dp"
android:layout_marginEnd="@dimen/spacing_huge"
app:layout_constraintTop_toBottomOf="@+id/reject_current_call"
app:layout_constraintStart_toStartOf="@+id/reject_current_call"
app:layout_constraintEnd_toEndOf="@id/reject_current_call" />

<RelativeLayout
android:id="@+id/hold_and_accept"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:layout_constraintTop_toBottomOf="@+id/reject_current_call"
app:layout_constraintEnd_toStartOf="@id/guideline_end"
/>
android:layout_marginTop="@dimen/spacing_huge"
android:layout_marginEnd="@dimen/spacing_normal"
android:layout_marginBottom="@dimen/spacing_huge">

<ImageView
android:padding="10dp"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/round_button_red"
android:gravity="center_vertical|center_horizontal"
android:src="@drawable/ic_call_white"
/>
<ImageView
android:padding="10dp"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginStart="40dp"
android:background="@drawable/round_button_green"
android:gravity="center_vertical|center_horizontal"
android:src="@drawable/ic_hold"

/>

</RelativeLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hold_and_accept"
android:layout_marginTop="15dp"
app:layout_constraintTop_toBottomOf="@+id/hold_and_accept"
app:layout_constraintStart_toStartOf="@+id/hold_and_accept"
app:layout_constraintEnd_toEndOf="@id/hold_and_accept" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline_start"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
<string name="reject">Reject</string>
<string name="answer">Answer</string>
<string name="incoming_call">Incoming Call</string>
<string name="end_and_accept">And and Accept</string>
<string name="end_and_accept">End and Accept</string>
<string name="reject_incoming">Reject Incoming</string>
<string name="hold_and_accept">Hold and Accept</string>

<string name="end">End</string>

Expand Down
Loading