From 2133934e28c41856d7f0c4db398db19cdfc934fc Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Tue, 16 Apr 2024 17:11:32 +0200 Subject: [PATCH] Fix participant devices in meeting call view --- Linphone/UI/Call/CallView.swift | 6 -- Linphone/UI/Call/Model/ParticipantModel.swift | 5 +- .../UI/Call/ViewModel/CallViewModel.swift | 74 +++++++++++++------ 3 files changed, 55 insertions(+), 30 deletions(-) diff --git a/Linphone/UI/Call/CallView.swift b/Linphone/UI/Call/CallView.swift index aca0212eb..3005a880d 100644 --- a/Linphone/UI/Call/CallView.swift +++ b/Linphone/UI/Call/CallView.swift @@ -770,12 +770,6 @@ struct CallView: View { Spacer() } - .onDisappear { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - // callViewModel.getConference() - callViewModel.waitingForCreatedStateConference() - } - } .background(.clear) .frame( maxWidth: fullscreenVideo && !telecomManager.isPausedByRemote ? geometry.size.width : geometry.size.width - 8, diff --git a/Linphone/UI/Call/Model/ParticipantModel.swift b/Linphone/UI/Call/Model/ParticipantModel.swift index 9f23870fb..507dc4ba6 100644 --- a/Linphone/UI/Call/Model/ParticipantModel.swift +++ b/Linphone/UI/Call/Model/ParticipantModel.swift @@ -28,8 +28,9 @@ class ParticipantModel: ObservableObject { @Published var sipUri: String @Published var name: String @Published var avatarModel: ContactAvatarModel + @Published var isJoining: Bool - init(address: Address) { + init(address: Address, isJoining: Bool) { self.address = address self.sipUri = address.asStringUriOnly() @@ -54,5 +55,7 @@ class ParticipantModel: ObservableObject { && $0.friend!.address!.asStringUriOnly() == address.asStringUriOnly() }) ?? ContactAvatarModel(friend: nil, name: nameTmp, withPresence: false) : ContactAvatarModel(friend: nil, name: nameTmp, withPresence: false) + + self.isJoining = isJoining } } diff --git a/Linphone/UI/Call/ViewModel/CallViewModel.swift b/Linphone/UI/Call/ViewModel/CallViewModel.swift index 8d7a86722..b2331d500 100644 --- a/Linphone/UI/Call/ViewModel/CallViewModel.swift +++ b/Linphone/UI/Call/ViewModel/CallViewModel.swift @@ -97,7 +97,20 @@ class CallViewModel: ObservableObject { self.remoteAddressString = String(self.currentCall!.remoteAddress!.asStringUriOnly().dropFirst(4)) self.remoteAddress = self.currentCall!.remoteAddress! - self.displayName = self.currentCall?.conference?.subject ?? "" + if self.currentCall?.conference != nil { + self.displayName = self.currentCall?.conference?.subject ?? "" + } else if self.currentCall?.remoteAddress != nil { + let friend = ContactsManager.shared.getFriendWithAddress(address: self.currentCall!.remoteAddress!) + if friend != nil && friend!.address != nil && friend!.address!.displayName != nil { + self.displayName = friend!.address!.displayName! + } else { + if self.currentCall!.remoteAddress!.displayName != nil { + self.displayName = self.currentCall!.remoteAddress!.displayName! + } else if self.currentCall!.remoteAddress!.username != nil { + self.displayName = self.currentCall!.remoteAddress!.username! + } + } + } //self.avatarModel = ??? self.micMutted = self.currentCall!.microphoneMuted || !core.micEnabled @@ -145,17 +158,16 @@ class CallViewModel: ObservableObject { self.displayName = conf.subject ?? "" self.participantList = [] - if self.currentCall?.callLog?.localAddress != nil { - self.myParticipantModel = ParticipantModel(address: self.currentCall!.callLog!.localAddress!) - print("ParticipantModelParticipantModel 1 \(conf.me?.address!.asStringUriOnly())") + if conf.me?.address != nil { + self.myParticipantModel = ParticipantModel(address: conf.me!.address!, isJoining: false) + } else if self.currentCall?.callLog?.localAddress != nil { + self.myParticipantModel = ParticipantModel(address: self.currentCall!.callLog!.localAddress!, isJoining: false) } if conf.activeSpeakerParticipantDevice?.address != nil { - self.activeSpeakerParticipant = ParticipantModel(address: conf.activeSpeakerParticipantDevice!.address!) - print("ParticipantModelParticipantModel 2 \(conf.activeSpeakerParticipantDevice!.address!.asStringUriOnly())") + self.activeSpeakerParticipant = ParticipantModel(address: conf.activeSpeakerParticipantDevice!.address!, isJoining: false) } else if conf.participantList.first?.address != nil { - self.activeSpeakerParticipant = ParticipantModel(address: conf.participantList.first!.address!) - print("ParticipantModelParticipantModel 3 \(conf.participantList.first!.address!.asStringUriOnly())") + self.activeSpeakerParticipant = ParticipantModel(address: conf.participantList.first!.address!, isJoining: false) } if self.activeSpeakerParticipant != nil { @@ -172,14 +184,17 @@ class CallViewModel: ObservableObject { } conf.participantDeviceList.forEach({ participantDevice in - self.participantList.append(ParticipantModel(address: participantDevice.address!)) - print("ParticipantModelParticipantModel 4 \(participantDevice.address!.asStringUriOnly()) \(conf.isIn) \(conf.state) \(self.currentCall?.state)") + if participantDevice.address != nil && !conf.isMe(uri: participantDevice.address!.clone()!) { + if !conf.isMe(uri: participantDevice.address!.clone()!) { + self.participantList.append(ParticipantModel(address: participantDevice.address!, isJoining: participantDevice.state == .Joining)) + } + } }) - //self.addConferenceCallBacks() + self.addConferenceCallBacks() } } else if self.currentCall?.remoteContactAddress != nil { - //self.addConferenceCallBacks() + self.addConferenceCallBacks() } } } @@ -188,7 +203,6 @@ class CallViewModel: ObservableObject { self.mConferenceSuscriptions.insert( self.currentCall?.conference?.publisher?.onStateChanged?.postOnMainQueue {(cbValue: (conference: Conference, state: Conference.State)) in if cbValue.state == .Created { - print("ParticipantModelParticipantModel 0 \(cbValue.conference.isIn) \(cbValue.conference.state) \(self.currentCall?.state) \(cbValue.state)") self.getConference() } } @@ -201,7 +215,7 @@ class CallViewModel: ObservableObject { self.currentCall?.conference?.publisher?.onActiveSpeakerParticipantDevice?.postOnMainQueue {(cbValue: (conference: Conference, participantDevice: ParticipantDevice)) in if cbValue.participantDevice.address != nil { let activeSpeakerParticipantTmp = self.activeSpeakerParticipant - self.activeSpeakerParticipant = ParticipantModel(address: cbValue.participantDevice.address!) + self.activeSpeakerParticipant = ParticipantModel(address: cbValue.participantDevice.address!, isJoining: false) if self.activeSpeakerParticipant != nil { let friend = ContactsManager.shared.getFriendWithAddress(address: self.activeSpeakerParticipant!.address) @@ -222,9 +236,9 @@ class CallViewModel: ObservableObject { self.participantList = [] cbValue.conference.participantDeviceList.forEach({ participantDevice in - if participantDevice.address != nil && !cbValue.conference.isMe(uri: participantDevice.address!) { - if !cbValue.conference.isMe(uri: participantDevice.address!) { - self.participantList.append(ParticipantModel(address: participantDevice.address!)) + if participantDevice.address != nil && !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) { + if !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) { + self.participantList.append(ParticipantModel(address: participantDevice.address!, isJoining: participantDevice.state == .Joining)) } } }) @@ -238,9 +252,9 @@ class CallViewModel: ObservableObject { if cbValue.participant.address != nil { self.participantList = [] cbValue.conference.participantDeviceList.forEach({ participantDevice in - if participantDevice.address != nil && !cbValue.conference.isMe(uri: participantDevice.address!) { - if !cbValue.conference.isMe(uri: participantDevice.address!) { - self.participantList.append(ParticipantModel(address: participantDevice.address!)) + if participantDevice.address != nil && !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) { + if !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) { + self.participantList.append(ParticipantModel(address: participantDevice.address!, isJoining: participantDevice.state == .Joining)) } } }) @@ -253,15 +267,29 @@ class CallViewModel: ObservableObject { if cbValue.participant.address != nil { self.participantList = [] cbValue.conference.participantDeviceList.forEach({ participantDevice in - if participantDevice.address != nil && !cbValue.conference.isMe(uri: participantDevice.address!) { - if !cbValue.conference.isMe(uri: participantDevice.address!) { - self.participantList.append(ParticipantModel(address: participantDevice.address!)) + if participantDevice.address != nil && !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) { + if !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) { + self.participantList.append(ParticipantModel(address: participantDevice.address!, isJoining: participantDevice.state == .Joining)) } } }) } } ) + + self.mConferenceSuscriptions.insert( + self.currentCall?.conference?.publisher?.onParticipantDeviceStateChanged?.postOnMainQueue {(cbValue: (conference: Conference, device: ParticipantDevice, state: ParticipantDevice.State)) in + Log.info( + "[CallViewModel] Participant device \(cbValue.device.address!.asStringUriOnly()) state changed \(cbValue.state)" + ) + + self.participantList.forEach({ participantDevice in + if participantDevice.address.equal(address2: cbValue.device.address!) { + participantDevice.isJoining = cbValue.state == .Joining + } + }) + } + ) } }