Skip to content
Draft
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
211 changes: 105 additions & 106 deletions app/src/main/java/com/nextcloud/talk/activities/CallActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import androidx.annotation.DrawableRes
import androidx.appcompat.app.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.mutableStateListOf
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.graphics.toColorInt
import androidx.core.net.toUri
Expand All @@ -59,13 +58,11 @@ import com.bluelinelabs.logansquare.LoganSquare
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.ParticipantDisplayItem
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
import com.nextcloud.talk.call.CallParticipant
import com.nextcloud.talk.call.CallParticipantList
import com.nextcloud.talk.call.CallParticipantModel
import com.nextcloud.talk.call.LocalStateBroadcaster
import com.nextcloud.talk.call.LocalStateBroadcasterMcu
import com.nextcloud.talk.call.LocalStateBroadcasterNoMcu
Expand Down Expand Up @@ -260,11 +257,12 @@ class CallActivity : CallBaseActivity() {
private val callParticipantMessageListeners: MutableMap<String?, CallParticipantMessageListener> = HashMap()
private val selfPeerConnectionObserver: PeerConnectionObserver = CallActivitySelfPeerConnectionObserver()
private var callParticipants: MutableMap<String?, CallParticipant?> = HashMap()
private val screenParticipantDisplayItemManagers: MutableMap<String?, ScreenParticipantDisplayItemManager> =
HashMap()
private val screenParticipantDisplayItemManagersHandler = Handler(Looper.getMainLooper())
private val callParticipantEventDisplayers: MutableMap<String?, CallParticipantEventDisplayer> = HashMap()
private val callParticipantEventDisplayersHandler = Handler(Looper.getMainLooper())

// private val screenParticipantDisplayItemManagers: MutableMap<String?, ScreenParticipantDisplayItemManager> =
// HashMap()
// private val screenParticipantDisplayItemManagersHandler = Handler(Looper.getMainLooper())
// private val callParticipantEventDisplayers: MutableMap<String?, CallParticipantEventDisplayer> = HashMap()
// private val callParticipantEventDisplayersHandler = Handler(Looper.getMainLooper())
private val callParticipantListObserver: CallParticipantList.Observer = object : CallParticipantList.Observer {
override fun onCallParticipantsChanged(
joined: Collection<Participant>,
Expand Down Expand Up @@ -305,7 +303,7 @@ class CallActivity : CallBaseActivity() {
private var currentCallStatus: CallStatus? = null
private var mediaPlayer: MediaPlayer? = null

private val participantItems = mutableStateListOf<ParticipantDisplayItem>()
// private val participantItems = mutableStateListOf<ParticipantDisplayItem>()
private var binding: CallActivityBinding? = null
private var audioOutputDialog: AudioOutputDialog? = null
private var moreCallActionsDialog: MoreCallActionsDialog? = null
Expand Down Expand Up @@ -944,7 +942,12 @@ class CallActivity : CallBaseActivity() {
binding!!.composeParticipantGrid.visibility = View.VISIBLE
binding!!.composeParticipantGrid.setContent {
MaterialTheme {
val participantUiStates = participantItems.map { it.uiStateFlow.collectAsState().value }
Log.d(TAG, "callParticipants.size: " + callParticipants.size)
val participantUiStates = callParticipants.values.map {
it!!.callParticipantModel.uiState.collectAsState().value
}

// val participantUiStates = participantItems.map { it.uiStateFlow.collectAsState().value }
ParticipantGrid(
participantUiStates = participantUiStates,
eglBase = rootEglBase!!,
Expand Down Expand Up @@ -2050,7 +2053,9 @@ class CallActivity : CallBaseActivity() {
}
val callParticipantIdsToEnd: MutableList<String> = ArrayList(peerConnectionWrapperList.size)
for (callParticipant in callParticipants.values) {
callParticipantIdsToEnd.add(callParticipant!!.callParticipantModel.sessionId)
callParticipant!!.callParticipantModel.sessionId?.let {
callParticipantIdsToEnd.add(it)
}
}
for (sessionId in callParticipantIdsToEnd) {
removeCallParticipant(sessionId)
Expand Down Expand Up @@ -2473,20 +2478,22 @@ class CallActivity : CallBaseActivity() {
"screen"
)
}
val callParticipantModel = callParticipant.callParticipantModel
val screenParticipantDisplayItemManager = ScreenParticipantDisplayItemManager(callParticipantModel)
screenParticipantDisplayItemManagers[sessionId] = screenParticipantDisplayItemManager
callParticipantModel.addObserver(
screenParticipantDisplayItemManager,
screenParticipantDisplayItemManagersHandler
)
val callParticipantEventDisplayer = CallParticipantEventDisplayer(callParticipantModel)
callParticipantEventDisplayers[sessionId] = callParticipantEventDisplayer
callParticipantModel.addObserver(callParticipantEventDisplayer, callParticipantEventDisplayersHandler)
runOnUiThread { addParticipantDisplayItem(callParticipantModel, "video") }
// val callParticipantModel = callParticipant.callParticipantModel
// val screenParticipantDisplayItemManager = ScreenParticipantDisplayItemManager(callParticipantModel)
// screenParticipantDisplayItemManagers[sessionId] = screenParticipantDisplayItemManager
// // callParticipantModel.addObserver(
// // screenParticipantDisplayItemManager,
// // screenParticipantDisplayItemManagersHandler
// // )
// val callParticipantEventDisplayer = CallParticipantEventDisplayer(callParticipantModel)
// callParticipantEventDisplayers[sessionId] = callParticipantEventDisplayer
// // callParticipantModel.addObserver(callParticipantEventDisplayer, callParticipantEventDisplayersHandler)
// runOnUiThread { addParticipantDisplayItem(callParticipantModel, "video") }

localStateBroadcaster!!.handleCallParticipantAdded(callParticipant.callParticipantModel)

initGrid()

return callParticipant
}

Expand Down Expand Up @@ -2515,10 +2522,10 @@ class CallActivity : CallBaseActivity() {

localStateBroadcaster!!.handleCallParticipantRemoved(callParticipant.callParticipantModel)

val screenParticipantDisplayItemManager = screenParticipantDisplayItemManagers.remove(sessionId)
callParticipant.callParticipantModel.removeObserver(screenParticipantDisplayItemManager)
val callParticipantEventDisplayer = callParticipantEventDisplayers.remove(sessionId)
callParticipant.callParticipantModel.removeObserver(callParticipantEventDisplayer)
// val screenParticipantDisplayItemManager = screenParticipantDisplayItemManagers.remove(sessionId)
// callParticipant.callParticipantModel.removeObserver(screenParticipantDisplayItemManager)
// val callParticipantEventDisplayer = callParticipantEventDisplayers.remove(sessionId)
// callParticipant.callParticipantModel.removeObserver(callParticipantEventDisplayer)
callParticipant.destroy()
val listener = callParticipantMessageListeners.remove(sessionId)
signalingMessageReceiver!!.removeListener(listener)
Expand All @@ -2527,14 +2534,6 @@ class CallActivity : CallBaseActivity() {
signalingMessageReceiver!!.removeListener(offerAnswerNickProvider.videoWebRtcMessageListener)
signalingMessageReceiver!!.removeListener(offerAnswerNickProvider.screenWebRtcMessageListener)
}
runOnUiThread { removeParticipantDisplayItem(sessionId, "video") }
}

private fun removeParticipantDisplayItem(sessionId: String?, videoStreamType: String) {
val key = "$sessionId-$videoStreamType"
val participant = participantItems.find { it.sessionKey == key }
participant?.destroy()
participantItems.removeAll { it.sessionKey == key }
initGrid()
}

Expand Down Expand Up @@ -2635,28 +2634,28 @@ class CallActivity : CallBaseActivity() {
}
}

private fun addParticipantDisplayItem(callParticipantModel: CallParticipantModel, videoStreamType: String) {
if (callParticipantModel.isInternal == true) return

val defaultGuestNick = resources.getString(R.string.nc_nick_guest)
val participantDisplayItem = ParticipantDisplayItem(
context = context,
baseUrl = baseUrl!!,
defaultGuestNick = defaultGuestNick,
rootEglBase = rootEglBase!!,
streamType = videoStreamType,
roomToken = roomToken!!,
callParticipantModel = callParticipantModel
)

val sessionKey = participantDisplayItem.sessionKey

if (participantItems.none { it.sessionKey == sessionKey }) {
participantItems.add(participantDisplayItem)
}

initGrid()
}
// private fun addParticipantDisplayItem(callParticipantModel: CallParticipantModel, videoStreamType: String) {
// if (callParticipantModel.isInternal == true) return
//
// val defaultGuestNick = resources.getString(R.string.nc_nick_guest)
// val participantDisplayItem = ParticipantDisplayItem(
// context = context,
// baseUrl = baseUrl!!,
// defaultGuestNick = defaultGuestNick,
// rootEglBase = rootEglBase!!,
// streamType = videoStreamType,
// roomToken = roomToken!!,
// callParticipantModel = callParticipantModel
// )
//
// val sessionKey = participantDisplayItem.sessionKey
//
// if (participantItems.none { it.sessionKey == sessionKey }) {
// participantItems.add(participantDisplayItem)
// }
//
// initGrid()
// }

private fun setCallState(callState: CallStatus) {
if (currentCallStatus == null || currentCallStatus !== callState) {
Expand Down Expand Up @@ -2977,55 +2976,55 @@ class CallActivity : CallBaseActivity() {
}
}

private inner class ScreenParticipantDisplayItemManager(private val callParticipantModel: CallParticipantModel) :
CallParticipantModel.Observer {
override fun onChange() {
val sessionId = callParticipantModel.sessionId
if (callParticipantModel.screenIceConnectionState == null) {
removeParticipantDisplayItem(sessionId, "screen")
return
}
val screenParticipantDisplayItem = participantItems.find { it.sessionKey == "$sessionId-screen" }
if (screenParticipantDisplayItem == null) {
addParticipantDisplayItem(callParticipantModel, "screen")
}
}

override fun onReaction(reaction: String) {
// unused atm
}
}

private inner class CallParticipantEventDisplayer(private val callParticipantModel: CallParticipantModel) :
CallParticipantModel.Observer {
private var raisedHand: Boolean

init {
raisedHand = if (callParticipantModel.raisedHand != null) callParticipantModel.raisedHand.state else false
}

@SuppressLint("StringFormatInvalid")
override fun onChange() {
if (callParticipantModel.raisedHand == null || !callParticipantModel.raisedHand.state) {
raisedHand = false
return
}
if (raisedHand) {
return
}
raisedHand = true
val nick = callParticipantModel.nick
Snackbar.make(
binding!!.root,
String.format(context.resources.getString(R.string.nc_call_raised_hand), nick),
Snackbar.LENGTH_LONG
).show()
}

override fun onReaction(reaction: String) {
addReactionForAnimation(reaction, callParticipantModel.nick)
}
}
// private inner class ScreenParticipantDisplayItemManager(private val callParticipantModel: CallParticipantModel) :
// CallParticipantModel.Observer {
// override fun onChange() {
// val sessionId = callParticipantModel.sessionId
// if (callParticipantModel.screenIceConnectionState == null) {
// removeParticipantDisplayItem(sessionId, "screen")
// return
// }
// val screenParticipantDisplayItem = participantItems.find { it.sessionKey == "$sessionId-screen" }
// if (screenParticipantDisplayItem == null) {
// addParticipantDisplayItem(callParticipantModel, "screen")
// }
// }
//
// override fun onReaction(reaction: String) {
// // unused atm
// }
// }

// private inner class CallParticipantEventDisplayer(private val callParticipantModel: CallParticipantModel) :
// CallParticipantModel.Observer {
// private var raisedHand: Boolean
//
// init {
// raisedHand = if (callParticipantModel.raisedHand != null) callParticipantModel.raisedHand.state else false
// }
//
// @SuppressLint("StringFormatInvalid")
// override fun onChange() {
// if (callParticipantModel.raisedHand == null || !callParticipantModel.raisedHand.state) {
// raisedHand = false
// return
// }
// if (raisedHand) {
// return
// }
// raisedHand = true
// val nick = callParticipantModel.nick
// Snackbar.make(
// binding!!.root,
// String.format(context.resources.getString(R.string.nc_call_raised_hand), nick),
// Snackbar.LENGTH_LONG
// ).show()
// }
//
// override fun onReaction(reaction: String) {
// addReactionForAnimation(reaction, callParticipantModel.nick)
// }
// }

private inner class InternalSignalingMessageSender : SignalingMessageSender {
override fun send(ncSignalingMessage: NCSignalingMessage) {
Expand Down Expand Up @@ -3198,7 +3197,7 @@ class CallActivity : CallBaseActivity() {
binding!!.selfVideoRenderer.clearImage()
binding!!.selfVideoRenderer.release()

if (participantItems.size == 1) {
if (callParticipants.size == 1) {
binding!!.pipOverlay.visibility = View.GONE
} else {
binding!!.composeParticipantGrid.visibility = View.GONE
Expand Down
Loading
Loading