Fix active spearker detection method with API

This commit is contained in:
Christophe Deschamps 2022-05-11 09:49:48 +02:00
parent 88713cf1db
commit 2264103eee
3 changed files with 28 additions and 24 deletions

View file

@ -60,6 +60,7 @@ class ConferenceViewModel {
if (count > self.maxParticipantsForMosaicLayout) {
Log.w("[Conference] \(conference) More than \(self.maxParticipantsForMosaicLayout) participants \(count), forcing active speaker layout")
self.conferenceDisplayMode.value = .ActiveSpeaker
self.changeLayout(layout: .ActiveSpeaker)
}
},
onParticipantRemoved: {(conference: Conference, participant: Participant) in

View file

@ -46,7 +46,6 @@ class VoipConferenceActiveSpeakerView: UIView, UICollectionViewDataSource, UICol
let activeSpeakerVideoView = UIView()
let activeSpeakerAvatar = Avatar(diameter: CGFloat(Avatar.diameter_for_call_views), color:VoipTheme.voipBackgroundColor, textStyle: VoipTheme.call_generated_avatar_large)
let activeSpeakerDisplayName = StyledLabel(VoipTheme.call_remote_name)
var activeSpeakerMonitorTimer : Timer? = nil
var grid : UICollectionView
@ -60,7 +59,7 @@ class VoipConferenceActiveSpeakerView: UIView, UICollectionViewDataSource, UICol
duration.conference = model.conference.value
self.remotelyRecording.isRemotelyRecorded = model.isRemotelyRecorded
model.conferenceParticipantDevices.readCurrentAndObserve { (_) in
self.grid.reloadData()
self.reloadData()
}
model.isConferenceLocallyPaused.readCurrentAndObserve { (paused) in
self.pauseCallButtons.forEach {
@ -73,34 +72,29 @@ class VoipConferenceActiveSpeakerView: UIView, UICollectionViewDataSource, UICol
}
}
Core.get().nativeVideoWindow = self.activeSpeakerVideoView
activeSpeakerMonitorTimer?.invalidate()
activeSpeakerMonitorTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { timer in
var thereIsAnActiveSpeaker = false
model.conferenceParticipantDevices.value?.forEach { (data) in
if (data.activeSpeaker.value == true) {
thereIsAnActiveSpeaker = true
data.participantDevice.address.map {
self.activeSpeakerAvatar.isHidden = false
self.activeSpeakerAvatar.fillFromAddress(address: $0)
self.activeSpeakerDisplayName.text = $0.addressBookEnhancedDisplayName()
}
self.activeSpeakerVideoView.isHidden = data.videoEnabled.value != true
return
}
}
if (!thereIsAnActiveSpeaker) {
self.activeSpeakerAvatar.isHidden = true
self.activeSpeakerVideoView.isHidden = true
self.activeSpeakerDisplayName.text = VoipTexts.conference_display_no_active_speaker
self.activeSpeakerAvatar.isHidden = true
self.activeSpeakerVideoView.isHidden = true
self.activeSpeakerDisplayName.text = VoipTexts.conference_display_no_active_speaker
conferenceViewModel?.speakingParticipant.readCurrentAndObserve { speakingParticipant in
speakingParticipant?.participantDevice.address.map {
self.activeSpeakerAvatar.isHidden = false
self.activeSpeakerAvatar.fillFromAddress(address: $0)
self.activeSpeakerDisplayName.text = $0.addressBookEnhancedDisplayName()
}
self.activeSpeakerVideoView.isHidden = speakingParticipant?.videoEnabled.value != true
}
} else {
activeSpeakerMonitorTimer?.invalidate()
}
self.grid.reloadData()
self.reloadData()
}
}
func reloadData() {
if (self.isHidden || conferenceViewModel?.conference.value?.call?.params?.conferenceVideoLayout != .ActiveSpeaker) {
return
}
self.grid.reloadData()
}
init() {

View file

@ -174,6 +174,9 @@ class VoipConferenceGridView: UIView, UICollectionViewDataSource, UICollectionVi
// UICollectionView related delegates
func reloadData() {
if (self.isHidden || conferenceViewModel?.conference.value?.call?.params?.conferenceVideoLayout != .Grid) {
return
}
computeCellSize()
self.grid.reloadData()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
@ -185,6 +188,12 @@ class VoipConferenceGridView: UIView, UICollectionViewDataSource, UICollectionVi
}
}
func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
let gcell = (cell as! VoipGridParticipantCell)
gcell.participantData?.participantDevice.nativeVideoWindowId = nil
gcell.participantData?.clearObservers()
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return inter_cell
}