forked from mirrors/linphone-iphone
Use Conference object in StartCallViewModel for group call init
This commit is contained in:
parent
ad48ff8bca
commit
ce24ddc919
2 changed files with 29 additions and 62 deletions
|
|
@ -50,7 +50,6 @@ class ConversationModel: ObservableObject, Identifiable {
|
||||||
@Published var unreadMessagesCount: Int
|
@Published var unreadMessagesCount: Int
|
||||||
@Published var avatarModel: ContactAvatarModel
|
@Published var avatarModel: ContactAvatarModel
|
||||||
|
|
||||||
//private var conference: Conference?
|
|
||||||
private var conferenceDelegate: ConferenceDelegate?
|
private var conferenceDelegate: ConferenceDelegate?
|
||||||
|
|
||||||
init(chatRoom: ChatRoom) {
|
init(chatRoom: ChatRoom) {
|
||||||
|
|
@ -134,10 +133,6 @@ class ConversationModel: ObservableObject, Identifiable {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let conferenceInfo = try Factory.Instance.createConferenceInfo()
|
|
||||||
conferenceInfo.organizer = account!.params?.identityAddress
|
|
||||||
conferenceInfo.subject = self.chatRoom.subject ?? "Conference"
|
|
||||||
|
|
||||||
var participantsList: [Address] = []
|
var participantsList: [Address] = []
|
||||||
self.chatRoom.participants.forEach { participant in
|
self.chatRoom.participants.forEach { participant in
|
||||||
participantsList.append(participant.address!)
|
participantsList.append(participant.address!)
|
||||||
|
|
@ -152,7 +147,7 @@ class ConversationModel: ObservableObject, Identifiable {
|
||||||
callParams.videoEnabled = true
|
callParams.videoEnabled = true
|
||||||
callParams.videoDirection = .RecvOnly
|
callParams.videoDirection = .RecvOnly
|
||||||
|
|
||||||
print("\(ConversationModel.TAG) Inviting \(participantsList.count) participant(s) into newly created conference")
|
Log.info("\(ConversationModel.TAG) Inviting \(participantsList.count) participant(s) into newly created conference")
|
||||||
|
|
||||||
try conference.inviteParticipants(addresses: participantsList, params: callParams)
|
try conference.inviteParticipants(addresses: participantsList, params: callParams)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,7 @@ class StartCallViewModel: ObservableObject {
|
||||||
|
|
||||||
@Published var operationInProgress: Bool = false
|
@Published var operationInProgress: Bool = false
|
||||||
|
|
||||||
private var conferenceScheduler: ConferenceScheduler?
|
private var conferenceDelegate: ConferenceDelegate?
|
||||||
private var conferenceSchedulerDelegate: ConferenceSchedulerDelegate?
|
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
coreContext.doOnCoreQueue { core in
|
coreContext.doOnCoreQueue { core in
|
||||||
|
|
@ -67,7 +66,7 @@ class StartCallViewModel: ObservableObject {
|
||||||
let account = core.defaultAccount
|
let account = core.defaultAccount
|
||||||
if account == nil {
|
if account == nil {
|
||||||
Log.error(
|
Log.error(
|
||||||
"\(StartCallViewModel.TAG) No default account found, can't create group call!"
|
"\(ConversationModel.TAG) No default account found, can't create group call!"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -77,86 +76,59 @@ class StartCallViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let conferenceInfo = try Factory.Instance.createConferenceInfo()
|
var participantsList: [Address] = []
|
||||||
conferenceInfo.organizer = account!.params?.identityAddress
|
|
||||||
conferenceInfo.subject = self.messageText
|
|
||||||
|
|
||||||
var participantsList: [ParticipantInfo] = []
|
|
||||||
self.participants.forEach { participant in
|
self.participants.forEach { participant in
|
||||||
do {
|
participantsList.append(participant.address)
|
||||||
let info = try Factory.Instance.createParticipantInfo(address: participant.address)
|
|
||||||
// For meetings, all participants must have Speaker role
|
|
||||||
info.role = Participant.Role.Speaker
|
|
||||||
participantsList.append(info)
|
|
||||||
} catch let error {
|
|
||||||
Log.error(
|
|
||||||
"\(StartCallViewModel.TAG) Can't create ParticipantInfo: \(error)"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.participants.removeAll()
|
self.participants.removeAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
conferenceInfo.addParticipantInfos(participantInfos: participantsList)
|
|
||||||
|
|
||||||
Log.info(
|
Log.info(
|
||||||
"\(StartCallViewModel.TAG) Creating group call with subject \(self.messageText) and \(participantsList.count) participant(s)"
|
"\(ConversationModel.TAG) Creating group call with subject \(self.messageText) and \(participantsList.count) participant(s)"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.conferenceScheduler = try core.createConferenceScheduler(account: account)
|
if let conference = LinphoneUtils.createGroupCall(core: core, account: account, subject: self.messageText) {
|
||||||
if self.conferenceScheduler != nil {
|
self.conferenceAddDelegate(core: core, conference: conference)
|
||||||
self.conferenceAddDelegate(core: core, conferenceScheduler: self.conferenceScheduler!)
|
let callParams = try? core.createCallParams(call: nil)
|
||||||
// Will trigger the conference creation/update automatically
|
if let callParams = callParams {
|
||||||
self.conferenceScheduler!.info = conferenceInfo
|
callParams.videoEnabled = true
|
||||||
|
callParams.videoDirection = .RecvOnly
|
||||||
|
|
||||||
|
Log.info("\(ConversationModel.TAG) Inviting \(participantsList.count) participant(s) into newly created conference")
|
||||||
|
|
||||||
|
try conference.inviteParticipants(addresses: participantsList, params: callParams)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch let error {
|
} catch let error {
|
||||||
Log.error(
|
Log.error(
|
||||||
"\(StartCallViewModel.TAG) createGroupCall: \(error)"
|
"\(ConversationModel.TAG) createGroupCall: \(error)"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func conferenceAddDelegate(core: Core, conferenceScheduler: ConferenceScheduler) {
|
func conferenceAddDelegate(core: Core, conference: Conference) {
|
||||||
self.conferenceSchedulerDelegate = ConferenceSchedulerDelegateStub(onStateChanged: { (conferenceScheduler: ConferenceScheduler, state: ConferenceScheduler.State) in
|
self.conferenceDelegate = ConferenceDelegateStub(onStateChanged: { (conference: Conference, state: Conference.State) in
|
||||||
Log.info("\(StartCallViewModel.TAG) Conference scheduler state is \(state)")
|
Log.info("\(StartCallViewModel.TAG) Conference state is \(state)")
|
||||||
if state == ConferenceScheduler.State.Ready {
|
if state == .Created {
|
||||||
conferenceScheduler.removeDelegate(delegate: self.conferenceSchedulerDelegate!)
|
|
||||||
self.conferenceSchedulerDelegate = nil
|
|
||||||
|
|
||||||
let conferenceAddress = conferenceScheduler.info?.uri
|
|
||||||
if conferenceAddress != nil {
|
|
||||||
Log.info(
|
|
||||||
"\(StartCallViewModel.TAG) Conference info created, address is \(conferenceAddress?.asStringUriOnly() ?? "Error conference address")"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.startVideoCall(core: core, conferenceAddress: conferenceAddress!)
|
|
||||||
} else {
|
|
||||||
Log.error("\(StartCallViewModel.TAG) Conference info URI is null!")
|
|
||||||
|
|
||||||
ToastViewModel.shared.toastMessage = "Failed_to_create_group_call_error"
|
|
||||||
ToastViewModel.shared.displayToast = true
|
|
||||||
}
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.operationInProgress = false
|
self.operationInProgress = false
|
||||||
}
|
}
|
||||||
} else if state == ConferenceScheduler.State.Error {
|
} else if state == .CreationFailed {
|
||||||
conferenceScheduler.removeDelegate(delegate: self.conferenceSchedulerDelegate!)
|
|
||||||
self.conferenceSchedulerDelegate = nil
|
|
||||||
Log.error("\(StartCallViewModel.TAG) Failed to create group call!")
|
Log.error("\(StartCallViewModel.TAG) Failed to create group call!")
|
||||||
|
|
||||||
ToastViewModel.shared.toastMessage = "Failed_to_create_group_call_error"
|
|
||||||
ToastViewModel.shared.displayToast = true
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
ToastViewModel.shared.toastMessage = "Failed_to_create_group_call_error"
|
||||||
|
ToastViewModel.shared.displayToast = true
|
||||||
self.operationInProgress = false
|
self.operationInProgress = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
conferenceScheduler.addDelegate(delegate: self.conferenceSchedulerDelegate!)
|
|
||||||
|
if self.conferenceDelegate != nil {
|
||||||
|
conference.addDelegate(delegate: self.conferenceDelegate!)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func startVideoCall(core: Core, conferenceAddress: Address) {
|
func startVideoCall(core: Core, conferenceAddress: Address) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue