Skip to content

Commit

Permalink
Initial support for multiple calls
Browse files Browse the repository at this point in the history
Registers calls, changes their state, handles device switching per call
  • Loading branch information
liviu-timar committed Aug 8, 2024
1 parent 6acdd61 commit b1b3ced
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import io.getstream.video.android.core.model.UpdateUserPermissionsData
import io.getstream.video.android.core.model.VideoTrack
import io.getstream.video.android.core.model.toIceServer
import io.getstream.video.android.core.socket.SocketState
import io.getstream.video.android.core.telecom.TelecomCallState
import io.getstream.video.android.core.telecom.TelecomCompat
import io.getstream.video.android.core.telecom.TelecomHandler
import io.getstream.video.android.core.utils.RampValueUpAndDownHelper
import io.getstream.video.android.core.utils.safeCall
Expand Down Expand Up @@ -444,6 +446,13 @@ public class Call(

monitor.start()
client.state.setActiveCall(this)

TelecomCompat.changeCallState(
clientImpl.context,
TelecomCallState.ONGOING,
this,
)

startCallStatsReporting(result.value.statsOptions.reportingIntervalMs.toLong())

// listen to Signal WS
Expand Down Expand Up @@ -1038,7 +1047,7 @@ public class Call(
state.removeRingingCall()

if (TelecomHandler.isSupported(context)) {
telecomHandler?.unregisterCall()
// telecomHandler?.unregisterCall()
} else {
state.maybeStopForegroundService()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.runtime.Stable
import androidx.core.content.ContextCompat
import io.getstream.log.taggedLogger
import io.getstream.video.android.core.notifications.internal.service.CallService
import io.getstream.video.android.core.telecom.TelecomCallState
import io.getstream.video.android.core.telecom.TelecomCompat
import io.getstream.video.android.core.utils.safeCall
import io.getstream.video.android.model.StreamCallId
Expand Down Expand Up @@ -127,38 +128,49 @@ class ClientState(client: StreamVideo) {

fun setActiveCall(call: Call) {
_activeCall.value = call

removeRingingCall()
TelecomCompat.registerCall(
clientImpl.context,
CallService.TRIGGER_ONGOING_CALL,
call = call,
)
}

fun removeActiveCall() {
_activeCall.value = null
_activeCall.value?.let { call ->
TelecomCompat.unregisterCall(
clientImpl.context,
CallService.TRIGGER_ONGOING_CALL,
call,
)

_activeCall.value = null
}

removeRingingCall()
TelecomCompat.unregisterCall(
clientImpl.context,
CallService.TRIGGER_ONGOING_CALL,
)
}

fun addRingingCall(call: Call, ringingState: RingingState) {
logger.d { "[addRingingCall] call: $call, ringingState: $ringingState" }

_ringingCall.value = call
if (ringingState is RingingState.Outgoing) {
TelecomCompat.registerCall(

TelecomCompat.changeCallState(
clientImpl.context,
if (ringingState is RingingState.Incoming) {
TelecomCallState.INCOMING
} else {
TelecomCallState.OUTGOING
},
call = call,
)
}

fun removeRingingCall() {
_ringingCall.value?.let { call ->
TelecomCompat.unregisterCall(
clientImpl.context,
CallService.TRIGGER_OUTGOING_CALL,
call = call,
call,
)
}
}

fun removeRingingCall() {
_ringingCall.value = null
_ringingCall.value = null
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ class MicrophoneManager(
if (canHandleDeviceSwitch()) {
audioHandler = TelecomCompat.getAudioHandler(
context = mediaManager.context,
call = mediaManager.call,
listener = { devices, selected ->
logger.i {
"[setup] listenForDevices. Selected: ${selected?.name}, available: ${devices.map { it.name }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import io.getstream.video.android.core.socket.ErrorResponse
import io.getstream.video.android.core.socket.PersistentSocket
import io.getstream.video.android.core.socket.SocketState
import io.getstream.video.android.core.sounds.Sounds
import io.getstream.video.android.core.telecom.TelecomCompat
import io.getstream.video.android.core.telecom.TelecomHandler
import io.getstream.video.android.core.utils.DebugInfo
import io.getstream.video.android.core.utils.LatencyResult
Expand Down Expand Up @@ -1044,7 +1045,10 @@ internal class StreamVideoImpl internal constructor(
calls[cid]!!
} else {
val call = Call(this, type, idOrRandom, user)

calls[cid] = call
TelecomCompat.registerCall(context, call)

call
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import io.getstream.video.android.core.notifications.NotificationHandler.Compani
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.ACTION_NOTIFICATION
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.INCOMING_CALL_NOTIFICATION_ID
import io.getstream.video.android.core.notifications.internal.DefaultStreamIntentResolver
import io.getstream.video.android.core.notifications.internal.service.CallService
import io.getstream.video.android.core.telecom.TelecomCompat
import io.getstream.video.android.model.StreamCallId

Expand Down Expand Up @@ -88,11 +87,11 @@ public open class DefaultNotificationHandler(

override fun onRingingCall(callId: StreamCallId, callDisplayName: String) {
logger.d { "[onRingingCall] #ringing; callId: ${callId.id}" }

TelecomCompat.registerCall(
application,
CallService.TRIGGER_INCOMING_CALL,
callDisplayName,
callId = callId,
isTriggeredByNotification = true,
)
}

Expand Down
Loading

0 comments on commit b1b3ced

Please sign in to comment.