mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-04-29 23:26:23 +00:00
Replace publisher with delegate in CallViewModel
This commit is contained in:
parent
72e8ecfd7e
commit
57d4e3cc1f
1 changed files with 266 additions and 284 deletions
|
|
@ -25,7 +25,6 @@ import Combine
|
||||||
// swiftlint:disable line_length
|
// swiftlint:disable line_length
|
||||||
// swiftlint:disable type_body_length
|
// swiftlint:disable type_body_length
|
||||||
// swiftlint:disable cyclomatic_complexity
|
// swiftlint:disable cyclomatic_complexity
|
||||||
// swiftlint:disable large_tuple
|
|
||||||
class CallViewModel: ObservableObject {
|
class CallViewModel: ObservableObject {
|
||||||
|
|
||||||
static let TAG = "[CallViewModel]"
|
static let TAG = "[CallViewModel]"
|
||||||
|
|
@ -67,7 +66,8 @@ class CallViewModel: ObservableObject {
|
||||||
@Published var qualityValue: Float = 0.0
|
@Published var qualityValue: Float = 0.0
|
||||||
@Published var qualityIcon = "cell-signal-full"
|
@Published var qualityIcon = "cell-signal-full"
|
||||||
|
|
||||||
private var mConferenceSuscriptions = Set<AnyCancellable?>()
|
private var conferenceDelegate: ConferenceDelegate?
|
||||||
|
private var waitingForConferenceDelegate: ConferenceDelegate?
|
||||||
|
|
||||||
@Published var calls: [Call] = []
|
@Published var calls: [Call] = []
|
||||||
@Published var callsCounter: Int = 0
|
@Published var callsCounter: Int = 0
|
||||||
|
|
@ -77,7 +77,7 @@ class CallViewModel: ObservableObject {
|
||||||
|
|
||||||
var currentCall: Call?
|
var currentCall: Call?
|
||||||
|
|
||||||
private var callSuscriptions = Set<AnyCancellable?>()
|
private var callDelegate: CallDelegate?
|
||||||
|
|
||||||
@Published var letters1: String = "AA"
|
@Published var letters1: String = "AA"
|
||||||
@Published var letters2: String = "BB"
|
@Published var letters2: String = "BB"
|
||||||
|
|
@ -87,7 +87,7 @@ class CallViewModel: ObservableObject {
|
||||||
@Published var operationInProgress: Bool = false
|
@Published var operationInProgress: Bool = false
|
||||||
@Published var displayedConversation: ConversationModel?
|
@Published var displayedConversation: ConversationModel?
|
||||||
|
|
||||||
private var chatRoomSuscriptions = Set<AnyCancellable?>()
|
private var chatRoomDelegate: ChatRoomDelegate?
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
do {
|
do {
|
||||||
|
|
@ -100,10 +100,19 @@ class CallViewModel: ObservableObject {
|
||||||
func resetCallView() {
|
func resetCallView() {
|
||||||
coreContext.doOnCoreQueue { core in
|
coreContext.doOnCoreQueue { core in
|
||||||
if core.currentCall != nil && core.currentCall!.remoteAddress != nil {
|
if core.currentCall != nil && core.currentCall!.remoteAddress != nil {
|
||||||
|
if self.callDelegate != nil {
|
||||||
|
self.currentCall?.removeDelegate(delegate: self.callDelegate!)
|
||||||
|
self.callDelegate = nil
|
||||||
|
}
|
||||||
|
if self.conferenceDelegate != nil {
|
||||||
|
self.currentCall?.conference?.removeDelegate(delegate: self.conferenceDelegate!)
|
||||||
|
self.conferenceDelegate = nil
|
||||||
|
}
|
||||||
|
if self.waitingForConferenceDelegate != nil {
|
||||||
|
self.currentCall?.conference?.removeDelegate(delegate: self.waitingForConferenceDelegate!)
|
||||||
|
self.waitingForConferenceDelegate = nil
|
||||||
|
}
|
||||||
self.currentCall = core.currentCall
|
self.currentCall = core.currentCall
|
||||||
self.callSuscriptions.removeAll()
|
|
||||||
self.mConferenceSuscriptions.removeAll()
|
|
||||||
|
|
||||||
let callsCounterTmp = core.calls.count
|
let callsCounterTmp = core.calls.count
|
||||||
|
|
||||||
var videoDisplayedTmp = false
|
var videoDisplayedTmp = false
|
||||||
|
|
@ -231,47 +240,41 @@ class CallViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.callSuscriptions.insert(self.currentCall!.publisher?.onEncryptionChanged?.postOnCoreQueue { _ in
|
self.callDelegate = CallDelegateStub(onEncryptionChanged: { (_: Call, _: Bool, _: String)in
|
||||||
self.updateEncryption(withToast: false)
|
self.updateEncryption(withToast: false)
|
||||||
if self.currentCall != nil {
|
if self.currentCall != nil {
|
||||||
self.callMediaEncryptionModel.update(call: self.currentCall!)
|
self.callMediaEncryptionModel.update(call: self.currentCall!)
|
||||||
}
|
}
|
||||||
})
|
}, onAuthenticationTokenVerified: { (_, verified: Bool) in
|
||||||
|
Log.warn("[CallViewModel][ZRTPPopup] Notified that authentication token is \(verified ? "verified" : "not verified!")")
|
||||||
self.callSuscriptions.insert(self.currentCall!.publisher?.onStatsUpdated?.postOnCoreQueue {(cbVal: (call: Call, stats: CallStats)) in
|
if verified {
|
||||||
|
self.updateEncryption(withToast: true)
|
||||||
|
if self.currentCall != nil {
|
||||||
|
self.callMediaEncryptionModel.update(call: self.currentCall!)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if self.telecomManager.isNotVerifiedCounter == 0 {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isNotVerified = true
|
||||||
|
self.telecomManager.isNotVerifiedCounter += 1
|
||||||
|
}
|
||||||
|
self.showZrtpSasDialogIfPossible()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isNotVerified = true
|
||||||
|
self.telecomManager.isNotVerifiedCounter += 1
|
||||||
|
self.zrtpPopupDisplayed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, onStatsUpdated: { (_: Call, stats: CallStats) in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if self.currentCall != nil {
|
if self.currentCall != nil {
|
||||||
self.callStatsModel.update(call: self.currentCall!, stats: cbVal.stats)
|
self.callStatsModel.update(call: self.currentCall!, stats: stats)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
self.currentCall!.addDelegate(delegate: self.callDelegate!)
|
||||||
self.callSuscriptions.insert(
|
|
||||||
self.currentCall!.publisher?.onAuthenticationTokenVerified?.postOnCoreQueue {(_, verified: Bool) in
|
|
||||||
Log.warn("[CallViewModel][ZRTPPopup] Notified that authentication token is \(verified ? "verified" : "not verified!")")
|
|
||||||
if verified {
|
|
||||||
self.updateEncryption(withToast: true)
|
|
||||||
if self.currentCall != nil {
|
|
||||||
self.callMediaEncryptionModel.update(call: self.currentCall!)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if self.telecomManager.isNotVerifiedCounter == 0 {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.isNotVerified = true
|
|
||||||
self.telecomManager.isNotVerifiedCounter += 1
|
|
||||||
}
|
|
||||||
self.showZrtpSasDialogIfPossible()
|
|
||||||
} else {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.isNotVerified = true
|
|
||||||
self.telecomManager.isNotVerifiedCounter += 1
|
|
||||||
self.zrtpPopupDisplayed = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
self.updateCallQualityIcon()
|
self.updateCallQualityIcon()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -385,263 +388,241 @@ class CallViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitingForCreatedStateConference() {
|
func waitingForCreatedStateConference() {
|
||||||
self.mConferenceSuscriptions.insert(
|
if let conference = self.currentCall?.conference {
|
||||||
self.currentCall?.conference?.publisher?.onStateChanged?.postOnCoreQueue {(cbValue: (conference: Conference, newState: Conference.State)) in
|
self.waitingForConferenceDelegate = ConferenceDelegateStub(onStateChanged: { (_: Conference, newState: Conference.State) in
|
||||||
if cbValue.newState == .Created {
|
if newState == .Created {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.getConference()
|
self.getConference()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
conference.addDelegate(delegate: self.waitingForConferenceDelegate!)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addConferenceCallBacks() {
|
func addConferenceCallBacks() {
|
||||||
coreContext.doOnCoreQueue { _ in
|
coreContext.doOnCoreQueue { _ in
|
||||||
self.mConferenceSuscriptions.insert(
|
guard let conference = self.currentCall?.conference else { return }
|
||||||
self.currentCall?.conference?.publisher?.onActiveSpeakerParticipantDevice?.postOnCoreQueue {(cbValue: (conference: Conference, participantDevice: ParticipantDevice)) in
|
|
||||||
if cbValue.participantDevice.address != nil {
|
|
||||||
let activeSpeakerParticipantBis = self.activeSpeakerParticipant
|
|
||||||
|
|
||||||
let activeSpeakerParticipantTmp = ParticipantModel(
|
self.conferenceDelegate = ConferenceDelegateStub(onParticipantDeviceAdded: { (conference: Conference, participantDevice: ParticipantDevice) in
|
||||||
address: cbValue.participantDevice.address!,
|
if participantDevice.address != nil {
|
||||||
isJoining: false,
|
var participantListTmp: [ParticipantModel] = []
|
||||||
onPause: cbValue.participantDevice.state == .OnHold,
|
conference.participantDeviceList.forEach({ pDevice in
|
||||||
isMuted: cbValue.participantDevice.isMuted
|
if pDevice.address != nil && !conference.isMe(uri: pDevice.address!.clone()!) {
|
||||||
)
|
if !conference.isMe(uri: pDevice.address!.clone()!) {
|
||||||
|
let isAdmin = conference.participantList.first(where: {$0.address!.equal(address2: pDevice.address!.clone()!)})?.isAdmin
|
||||||
var activeSpeakerNameTmp = ""
|
participantListTmp.append(
|
||||||
let friend = ContactsManager.shared.getFriendWithAddress(address: activeSpeakerParticipantTmp.address)
|
ParticipantModel(
|
||||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
address: pDevice.address!,
|
||||||
activeSpeakerNameTmp = friend!.address!.displayName!
|
isJoining: pDevice.state == .Joining || pDevice.state == .Alerting,
|
||||||
} else {
|
onPause: pDevice.state == .OnHold,
|
||||||
if activeSpeakerParticipantTmp.address.displayName != nil {
|
isMuted: pDevice.isMuted,
|
||||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp.address.displayName!
|
isAdmin: isAdmin ?? false
|
||||||
} else if activeSpeakerParticipantTmp.address.username != nil {
|
)
|
||||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp.address.username!
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
var participantListTmp: [ParticipantModel] = []
|
var activeSpeakerParticipantTmp: ParticipantModel?
|
||||||
if (activeSpeakerParticipantBis != nil && !activeSpeakerParticipantBis!.address.equal(address2: activeSpeakerParticipantTmp.address))
|
var activeSpeakerNameTmp = ""
|
||||||
|| ( activeSpeakerParticipantBis == nil) {
|
|
||||||
|
|
||||||
cbValue.conference.participantDeviceList.forEach({ participantDevice in
|
if self.activeSpeakerParticipant == nil {
|
||||||
if participantDevice.address != nil && !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) {
|
if conference.activeSpeakerParticipantDevice?.address != nil {
|
||||||
if !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) {
|
activeSpeakerParticipantTmp = ParticipantModel(
|
||||||
let isAdmin = cbValue.conference.participantList.first(where: {$0.address!.equal(address2: participantDevice.address!.clone()!)})?.isAdmin
|
address: conference.activeSpeakerParticipantDevice!.address!,
|
||||||
participantListTmp.append(
|
isJoining: false,
|
||||||
ParticipantModel(
|
onPause: conference.activeSpeakerParticipantDevice!.state == .OnHold,
|
||||||
address: participantDevice.address!,
|
isMuted: conference.activeSpeakerParticipantDevice!.isMuted
|
||||||
isJoining: participantDevice.state == .Joining || participantDevice.state == .Alerting,
|
)
|
||||||
onPause: participantDevice.state == .OnHold,
|
} else if conference.participantList.first?.address != nil && conference.participantList.first!.address!.clone()!.equal(address2: (conference.me?.address)!) {
|
||||||
isMuted: participantDevice.isMuted,
|
activeSpeakerParticipantTmp = ParticipantModel(
|
||||||
isAdmin: isAdmin ?? false
|
address: conference.participantDeviceList.first!.address!,
|
||||||
)
|
isJoining: false,
|
||||||
)
|
onPause: conference.participantDeviceList.first!.state == .OnHold,
|
||||||
}
|
isMuted: conference.participantDeviceList.first!.isMuted
|
||||||
}
|
)
|
||||||
})
|
} else if conference.participantList.last?.address != nil {
|
||||||
|
activeSpeakerParticipantTmp = ParticipantModel(
|
||||||
|
address: conference.participantDeviceList.last!.address!,
|
||||||
|
isJoining: false,
|
||||||
|
onPause: conference.participantDeviceList.last!.state == .OnHold,
|
||||||
|
isMuted: conference.participantDeviceList.last!.isMuted
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
if activeSpeakerParticipantTmp != nil {
|
||||||
|
let friend = ContactsManager.shared.getFriendWithAddress(address: activeSpeakerParticipantTmp?.address)
|
||||||
|
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||||
|
activeSpeakerNameTmp = friend!.address!.displayName!
|
||||||
|
} else {
|
||||||
|
if activeSpeakerParticipantTmp!.address.displayName != nil {
|
||||||
|
activeSpeakerNameTmp = activeSpeakerParticipantTmp!.address.displayName!
|
||||||
|
} else if activeSpeakerParticipantTmp!.address.username != nil {
|
||||||
|
activeSpeakerNameTmp = activeSpeakerParticipantTmp!.address.username!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if self.activeSpeakerParticipant == nil {
|
||||||
|
self.activeSpeakerName = activeSpeakerNameTmp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if self.activeSpeakerParticipant == nil {
|
||||||
self.activeSpeakerParticipant = activeSpeakerParticipantTmp
|
self.activeSpeakerParticipant = activeSpeakerParticipantTmp
|
||||||
self.activeSpeakerName = activeSpeakerNameTmp
|
self.activeSpeakerName = activeSpeakerNameTmp
|
||||||
if (activeSpeakerParticipantBis != nil && !activeSpeakerParticipantBis!.address.equal(address2: activeSpeakerParticipantTmp.address))
|
|
||||||
|| ( activeSpeakerParticipantBis == nil) {
|
|
||||||
self.participantList = participantListTmp
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
self.participantList = participantListTmp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
}, onParticipantDeviceRemoved: { (conference: Conference, participantDevice: ParticipantDevice) in
|
||||||
|
if participantDevice.address != nil {
|
||||||
self.mConferenceSuscriptions.insert(
|
var participantListTmp: [ParticipantModel] = []
|
||||||
self.currentCall?.conference?.publisher?.onParticipantDeviceAdded?.postOnCoreQueue {(cbValue: (conference: Conference, participantDevice: ParticipantDevice)) in
|
conference.participantDeviceList.forEach({ pDevice in
|
||||||
if cbValue.participantDevice.address != nil {
|
if pDevice.address != nil && !conference.isMe(uri: pDevice.address!.clone()!) {
|
||||||
var participantListTmp: [ParticipantModel] = []
|
if !conference.isMe(uri: pDevice.address!.clone()!) {
|
||||||
cbValue.conference.participantDeviceList.forEach({ participantDevice in
|
let isAdmin = conference.participantList.first(where: {$0.address!.equal(address2: pDevice.address!.clone()!)})?.isAdmin
|
||||||
if participantDevice.address != nil && !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) {
|
participantListTmp.append(
|
||||||
if !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) {
|
ParticipantModel(
|
||||||
let isAdmin = cbValue.conference.participantList.first(where: {$0.address!.equal(address2: participantDevice.address!.clone()!)})?.isAdmin
|
address: pDevice.address!,
|
||||||
participantListTmp.append(
|
isJoining: pDevice.state == .Joining || pDevice.state == .Alerting,
|
||||||
ParticipantModel(
|
onPause: pDevice.state == .OnHold,
|
||||||
address: participantDevice.address!,
|
isMuted: pDevice.isMuted,
|
||||||
isJoining: participantDevice.state == .Joining || participantDevice.state == .Alerting,
|
isAdmin: isAdmin ?? false
|
||||||
onPause: participantDevice.state == .OnHold,
|
|
||||||
isMuted: participantDevice.isMuted,
|
|
||||||
isAdmin: isAdmin ?? false
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
var activeSpeakerParticipantTmp: ParticipantModel?
|
|
||||||
var activeSpeakerNameTmp = ""
|
|
||||||
|
|
||||||
if self.activeSpeakerParticipant == nil {
|
|
||||||
if cbValue.conference.activeSpeakerParticipantDevice?.address != nil {
|
|
||||||
activeSpeakerParticipantTmp = ParticipantModel(
|
|
||||||
address: cbValue.conference.activeSpeakerParticipantDevice!.address!,
|
|
||||||
isJoining: false,
|
|
||||||
onPause: cbValue.conference.activeSpeakerParticipantDevice!.state == .OnHold,
|
|
||||||
isMuted: cbValue.conference.activeSpeakerParticipantDevice!.isMuted
|
|
||||||
)
|
)
|
||||||
} else if cbValue.conference.participantList.first?.address != nil && cbValue.conference.participantList.first!.address!.clone()!.equal(address2: (cbValue.conference.me?.address)!) {
|
|
||||||
activeSpeakerParticipantTmp = ParticipantModel(
|
|
||||||
address: cbValue.conference.participantDeviceList.first!.address!,
|
|
||||||
isJoining: false,
|
|
||||||
onPause: cbValue.conference.participantDeviceList.first!.state == .OnHold,
|
|
||||||
isMuted: cbValue.conference.participantDeviceList.first!.isMuted
|
|
||||||
)
|
|
||||||
} else if cbValue.conference.participantList.last?.address != nil {
|
|
||||||
activeSpeakerParticipantTmp = ParticipantModel(
|
|
||||||
address: cbValue.conference.participantDeviceList.last!.address!,
|
|
||||||
isJoining: false,
|
|
||||||
onPause: cbValue.conference.participantDeviceList.last!.state == .OnHold,
|
|
||||||
isMuted: cbValue.conference.participantDeviceList.last!.isMuted
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if activeSpeakerParticipantTmp != nil {
|
|
||||||
let friend = ContactsManager.shared.getFriendWithAddress(address: activeSpeakerParticipantTmp?.address)
|
|
||||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
|
||||||
activeSpeakerNameTmp = friend!.address!.displayName!
|
|
||||||
} else {
|
|
||||||
if activeSpeakerParticipantTmp!.address.displayName != nil {
|
|
||||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp!.address.displayName!
|
|
||||||
} else if activeSpeakerParticipantTmp!.address.username != nil {
|
|
||||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp!.address.username!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
if self.activeSpeakerParticipant == nil {
|
|
||||||
self.activeSpeakerName = activeSpeakerNameTmp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
if self.activeSpeakerParticipant == nil {
|
|
||||||
self.activeSpeakerParticipant = activeSpeakerParticipantTmp
|
|
||||||
self.activeSpeakerName = activeSpeakerNameTmp
|
|
||||||
}
|
|
||||||
self.participantList = participantListTmp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
self.mConferenceSuscriptions.insert(
|
|
||||||
self.currentCall?.conference?.publisher?.onParticipantDeviceRemoved?.postOnCoreQueue {(cbValue: (conference: Conference, participantDevice: ParticipantDevice)) in
|
|
||||||
if cbValue.participantDevice.address != nil {
|
|
||||||
var participantListTmp: [ParticipantModel] = []
|
|
||||||
cbValue.conference.participantDeviceList.forEach({ participantDevice in
|
|
||||||
if participantDevice.address != nil && !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) {
|
|
||||||
if !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) {
|
|
||||||
let isAdmin = cbValue.conference.participantList.first(where: {$0.address!.equal(address2: participantDevice.address!.clone()!)})?.isAdmin
|
|
||||||
participantListTmp.append(
|
|
||||||
ParticipantModel(
|
|
||||||
address: participantDevice.address!,
|
|
||||||
isJoining: participantDevice.state == .Joining || participantDevice.state == .Alerting,
|
|
||||||
onPause: participantDevice.state == .OnHold,
|
|
||||||
isMuted: participantDevice.isMuted,
|
|
||||||
isAdmin: isAdmin ?? false
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
let participantDeviceListCount = cbValue.conference.participantDeviceList.count
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.participantList = participantListTmp
|
|
||||||
|
|
||||||
if participantDeviceListCount == 1 {
|
|
||||||
self.activeSpeakerParticipant = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
self.mConferenceSuscriptions.insert(
|
|
||||||
self.currentCall?.conference?.publisher?.onParticipantDeviceIsMuted?.postOnCoreQueue {(cbValue: (conference: Conference, participantDevice: ParticipantDevice, isMuted: Bool)) in
|
|
||||||
if self.activeSpeakerParticipant != nil && self.activeSpeakerParticipant!.address.equal(address2: cbValue.participantDevice.address!) {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.activeSpeakerParticipant!.isMuted = cbValue.isMuted
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.participantList.forEach({ participantDevice in
|
|
||||||
if participantDevice.address.equal(address2: cbValue.participantDevice.address!) {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
participantDevice.isMuted = cbValue.isMuted
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
self.mConferenceSuscriptions.insert(
|
let participantDeviceListCount = conference.participantDeviceList.count
|
||||||
self.currentCall?.conference?.publisher?.onParticipantDeviceStateChanged?.postOnCoreQueue {(cbValue: (conference: Conference, device: ParticipantDevice, state: ParticipantDevice.State)) in
|
|
||||||
Log.info(
|
DispatchQueue.main.async {
|
||||||
"[CallViewModel] Participant device \(cbValue.device.address!.asStringUriOnly()) state changed \(cbValue.state)"
|
self.participantList = participantListTmp
|
||||||
|
|
||||||
|
if participantDeviceListCount == 1 {
|
||||||
|
self.activeSpeakerParticipant = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, onParticipantAdminStatusChanged: { (_: Conference, participant: Participant) in
|
||||||
|
let isAdmin = participant.isAdmin
|
||||||
|
if self.myParticipantModel != nil && self.myParticipantModel!.address.clone()!.equal(address2: participant.address!) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.myParticipantModel!.isAdmin = isAdmin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.participantList.forEach({ participantDevice in
|
||||||
|
if participantDevice.address.clone()!.equal(address2: participant.address!) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
participantDevice.isAdmin = isAdmin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, onParticipantDeviceStateChanged: { (_: Conference, device: ParticipantDevice, state: ParticipantDevice.State) in
|
||||||
|
Log.info(
|
||||||
|
"[CallViewModel] Participant device \(device.address!.asStringUriOnly()) state changed \(state)"
|
||||||
|
)
|
||||||
|
if self.activeSpeakerParticipant != nil && self.activeSpeakerParticipant!.address.equal(address2: device.address!) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.activeSpeakerParticipant!.onPause = state == .OnHold
|
||||||
|
self.activeSpeakerParticipant!.isJoining = state == .Joining || state == .Alerting
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.participantList.forEach({ participantDevice in
|
||||||
|
if participantDevice.address.equal(address2: device.address!) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
participantDevice.onPause = state == .OnHold
|
||||||
|
participantDevice.isJoining = state == .Joining || state == .Alerting
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, onParticipantDeviceIsSpeakingChanged: { (_: Conference, device: ParticipantDevice, isSpeaking: Bool) in
|
||||||
|
let isSpeaking = device.isSpeaking
|
||||||
|
if self.myParticipantModel != nil && self.myParticipantModel!.address.clone()!.equal(address2: device.address!) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.myParticipantModel!.isSpeaking = isSpeaking
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.participantList.forEach({ participantDeviceList in
|
||||||
|
if participantDeviceList.address.clone()!.equal(address2: device.address!) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
participantDeviceList.isSpeaking = isSpeaking
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, onParticipantDeviceIsMuted: { (_: Conference, device: ParticipantDevice, isMuted: Bool) in
|
||||||
|
if self.activeSpeakerParticipant != nil && self.activeSpeakerParticipant!.address.equal(address2: device.address!) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.activeSpeakerParticipant!.isMuted = isMuted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.participantList.forEach({ participantDevice in
|
||||||
|
if participantDevice.address.equal(address2: device.address!) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
participantDevice.isMuted = isMuted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, onActiveSpeakerParticipantDevice: { (conference: Conference, participantDevice: ParticipantDevice) in
|
||||||
|
if participantDevice.address != nil {
|
||||||
|
let activeSpeakerParticipantBis = self.activeSpeakerParticipant
|
||||||
|
|
||||||
|
let activeSpeakerParticipantTmp = ParticipantModel(
|
||||||
|
address: participantDevice.address!,
|
||||||
|
isJoining: false,
|
||||||
|
onPause: participantDevice.state == .OnHold,
|
||||||
|
isMuted: participantDevice.isMuted
|
||||||
)
|
)
|
||||||
if self.activeSpeakerParticipant != nil && self.activeSpeakerParticipant!.address.equal(address2: cbValue.device.address!) {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.activeSpeakerParticipant!.onPause = cbValue.state == .OnHold
|
|
||||||
self.activeSpeakerParticipant!.isJoining = cbValue.state == .Joining || cbValue.state == .Alerting
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.participantList.forEach({ participantDevice in
|
|
||||||
if participantDevice.address.equal(address2: cbValue.device.address!) {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
participantDevice.onPause = cbValue.state == .OnHold
|
|
||||||
participantDevice.isJoining = cbValue.state == .Joining || cbValue.state == .Alerting
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
self.mConferenceSuscriptions.insert(
|
var activeSpeakerNameTmp = ""
|
||||||
self.currentCall?.conference?.publisher?.onParticipantAdminStatusChanged?.postOnCoreQueue {(cbValue: (conference: Conference, participant: Participant)) in
|
let friend = ContactsManager.shared.getFriendWithAddress(address: activeSpeakerParticipantTmp.address)
|
||||||
let isAdmin = cbValue.participant.isAdmin
|
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||||
if self.myParticipantModel != nil && self.myParticipantModel!.address.clone()!.equal(address2: cbValue.participant.address!) {
|
activeSpeakerNameTmp = friend!.address!.displayName!
|
||||||
DispatchQueue.main.async {
|
} else {
|
||||||
self.myParticipantModel!.isAdmin = isAdmin
|
if activeSpeakerParticipantTmp.address.displayName != nil {
|
||||||
|
activeSpeakerNameTmp = activeSpeakerParticipantTmp.address.displayName!
|
||||||
|
} else if activeSpeakerParticipantTmp.address.username != nil {
|
||||||
|
activeSpeakerNameTmp = activeSpeakerParticipantTmp.address.username!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.participantList.forEach({ participantDevice in
|
|
||||||
if participantDevice.address.clone()!.equal(address2: cbValue.participant.address!) {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
participantDevice.isAdmin = isAdmin
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
self.mConferenceSuscriptions.insert(
|
var participantListTmp: [ParticipantModel] = []
|
||||||
self.currentCall?.conference?.publisher?.onParticipantDeviceIsSpeakingChanged?.postOnCoreQueue {(cbValue: (conference: Conference, participantDevice: ParticipantDevice, isSpeaking: Bool)) in
|
if (activeSpeakerParticipantBis != nil && !activeSpeakerParticipantBis!.address.equal(address2: activeSpeakerParticipantTmp.address))
|
||||||
let isSpeaking = cbValue.participantDevice.isSpeaking
|
|| ( activeSpeakerParticipantBis == nil) {
|
||||||
if self.myParticipantModel != nil && self.myParticipantModel!.address.clone()!.equal(address2: cbValue.participantDevice.address!) {
|
|
||||||
DispatchQueue.main.async {
|
conference.participantDeviceList.forEach({ pDevice in
|
||||||
self.myParticipantModel!.isSpeaking = isSpeaking
|
if pDevice.address != nil && !conference.isMe(uri: pDevice.address!.clone()!) {
|
||||||
|
if !conference.isMe(uri: pDevice.address!.clone()!) {
|
||||||
|
let isAdmin = conference.participantList.first(where: {$0.address!.equal(address2: pDevice.address!.clone()!)})?.isAdmin
|
||||||
|
participantListTmp.append(
|
||||||
|
ParticipantModel(
|
||||||
|
address: pDevice.address!,
|
||||||
|
isJoining: pDevice.state == .Joining || pDevice.state == .Alerting,
|
||||||
|
onPause: pDevice.state == .OnHold,
|
||||||
|
isMuted: pDevice.isMuted,
|
||||||
|
isAdmin: isAdmin ?? false
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.activeSpeakerParticipant = activeSpeakerParticipantTmp
|
||||||
|
self.activeSpeakerName = activeSpeakerNameTmp
|
||||||
|
if (activeSpeakerParticipantBis != nil && !activeSpeakerParticipantBis!.address.equal(address2: activeSpeakerParticipantTmp.address))
|
||||||
|
|| ( activeSpeakerParticipantBis == nil) {
|
||||||
|
self.participantList = participantListTmp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.participantList.forEach({ participantDeviceList in
|
|
||||||
if participantDeviceList.address.clone()!.equal(address2: cbValue.participantDevice.address!) {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
participantDeviceList.isSpeaking = isSpeaking
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
)
|
})
|
||||||
|
conference.addDelegate(delegate: self.conferenceDelegate!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1306,13 +1287,27 @@ class CallViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func chatRoomAddDelegate(core: Core, chatRoom: ChatRoom) {
|
func chatRoomAddDelegate(core: Core, chatRoom: ChatRoom) {
|
||||||
self.chatRoomSuscriptions.insert(chatRoom.publisher?.onConferenceJoined?.postOnCoreQueue { (chatRoom: ChatRoom, _: EventLog) in
|
self.chatRoomDelegate = ChatRoomDelegateStub(onStateChanged: { (chatRoom: ChatRoom, state: ChatRoom.State) in
|
||||||
|
let state = chatRoom.state
|
||||||
|
let id = LinphoneUtils.getChatRoomId(room: chatRoom)
|
||||||
|
if state == ChatRoom.State.CreationFailed {
|
||||||
|
Log.error("\(StartConversationViewModel.TAG) Conversation \(id) creation has failed!")
|
||||||
|
chatRoom.removeDelegate(delegate: self.chatRoomDelegate!)
|
||||||
|
self.chatRoomDelegate = nil
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.operationInProgress = false
|
||||||
|
ToastViewModel.shared.toastMessage = "Failed_to_create_conversation_error"
|
||||||
|
ToastViewModel.shared.displayToast = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, onConferenceJoined: { (chatRoom: ChatRoom, _: EventLog) in
|
||||||
let state = chatRoom.state
|
let state = chatRoom.state
|
||||||
let id = LinphoneUtils.getChatRoomId(room: chatRoom)
|
let id = LinphoneUtils.getChatRoomId(room: chatRoom)
|
||||||
Log.info("\(StartConversationViewModel.TAG) Conversation \(id) \(chatRoom.subject ?? "") state changed: \(state)")
|
Log.info("\(StartConversationViewModel.TAG) Conversation \(id) \(chatRoom.subject ?? "") state changed: \(state)")
|
||||||
if state == ChatRoom.State.Created {
|
if state == ChatRoom.State.Created {
|
||||||
Log.info("\(StartConversationViewModel.TAG) Conversation \(id) successfully created")
|
Log.info("\(StartConversationViewModel.TAG) Conversation \(id) successfully created")
|
||||||
self.chatRoomSuscriptions.removeAll()
|
chatRoom.removeDelegate(delegate: self.chatRoomDelegate!)
|
||||||
|
self.chatRoomDelegate = nil
|
||||||
|
|
||||||
let model = ConversationModel(chatRoom: chatRoom)
|
let model = ConversationModel(chatRoom: chatRoom)
|
||||||
if self.operationInProgress == false {
|
if self.operationInProgress == false {
|
||||||
|
|
@ -1332,21 +1327,8 @@ class CallViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
} else if state == ChatRoom.State.CreationFailed {
|
} else if state == ChatRoom.State.CreationFailed {
|
||||||
Log.error("\(StartConversationViewModel.TAG) Conversation \(id) creation has failed!")
|
Log.error("\(StartConversationViewModel.TAG) Conversation \(id) creation has failed!")
|
||||||
self.chatRoomSuscriptions.removeAll()
|
chatRoom.removeDelegate(delegate: self.chatRoomDelegate!)
|
||||||
DispatchQueue.main.async {
|
self.chatRoomDelegate = nil
|
||||||
self.operationInProgress = false
|
|
||||||
ToastViewModel.shared.toastMessage = "Failed_to_create_conversation_error"
|
|
||||||
ToastViewModel.shared.displayToast = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
self.chatRoomSuscriptions.insert(chatRoom.publisher?.onStateChanged?.postOnCoreQueue { (chatRoom: ChatRoom, state: ChatRoom.State) in
|
|
||||||
let state = chatRoom.state
|
|
||||||
let id = LinphoneUtils.getChatRoomId(room: chatRoom)
|
|
||||||
if state == ChatRoom.State.CreationFailed {
|
|
||||||
Log.error("\(StartConversationViewModel.TAG) Conversation \(id) creation has failed!")
|
|
||||||
self.chatRoomSuscriptions.removeAll()
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.operationInProgress = false
|
self.operationInProgress = false
|
||||||
ToastViewModel.shared.toastMessage = "Failed_to_create_conversation_error"
|
ToastViewModel.shared.toastMessage = "Failed_to_create_conversation_error"
|
||||||
|
|
@ -1354,9 +1336,9 @@ class CallViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
chatRoom.addDelegate(delegate: self.chatRoomDelegate!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// swiftlint:enable type_body_length
|
// swiftlint:enable type_body_length
|
||||||
// swiftlint:enable line_length
|
// swiftlint:enable line_length
|
||||||
// swiftlint:enable cyclomatic_complexity
|
// swiftlint:enable cyclomatic_complexity
|
||||||
// swiftlint:enable large_tuple
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue