2022-05-24 19:34:27 +01:00
|
|
|
//
|
|
|
|
// IncomingCallView.swift
|
|
|
|
// SimpleX (iOS)
|
|
|
|
//
|
|
|
|
// Created by Evgeny on 24/05/2022.
|
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2022-05-31 07:55:13 +01:00
|
|
|
import SimpleXChat
|
2022-05-24 19:34:27 +01:00
|
|
|
|
|
|
|
struct IncomingCallView: View {
|
|
|
|
@EnvironmentObject var m: ChatModel
|
|
|
|
@ObservedObject var cc = CallController.shared
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
let sp = SoundPlayer.shared
|
|
|
|
if let invitation = cc.activeCallInvitation {
|
|
|
|
if m.showCallView {
|
|
|
|
incomingCall(invitation)
|
|
|
|
} else {
|
|
|
|
incomingCall(invitation)
|
|
|
|
.onAppear { sp.startRingtone() }
|
|
|
|
.onDisappear { sp.stopRingtone() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 15:15:15 +04:00
|
|
|
private func incomingCall(_ invitation: RcvCallInvitation) -> some View {
|
2022-05-24 19:34:27 +01:00
|
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
|
|
HStack {
|
2023-01-23 13:20:58 +00:00
|
|
|
if m.users.count > 1 {
|
|
|
|
ProfileImage(imageStr: invitation.user.image, color: .white)
|
|
|
|
.frame(width: 24, height: 24)
|
|
|
|
}
|
2022-07-05 15:15:15 +04:00
|
|
|
Image(systemName: invitation.callType.media == .video ? "video.fill" : "phone.fill").foregroundColor(.green)
|
2022-05-24 19:34:27 +01:00
|
|
|
Text(invitation.callTypeText)
|
|
|
|
}
|
|
|
|
HStack {
|
|
|
|
ProfilePreview(profileOf: invitation.contact, color: .white)
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
callButton("Reject", "phone.down.fill", .red) {
|
|
|
|
cc.endCall(invitation: invitation)
|
|
|
|
}
|
|
|
|
|
|
|
|
callButton("Ignore", "multiply", .accentColor) {
|
|
|
|
cc.activeCallInvitation = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
callButton("Accept", "checkmark", .green) {
|
|
|
|
if let call = m.activeCall {
|
|
|
|
cc.endCall(call: call) {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
cc.answerCall(invitation: invitation)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cc.answerCall(invitation: invitation)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.horizontal, 16)
|
|
|
|
.padding(.vertical, 12)
|
|
|
|
.frame(maxWidth: .infinity)
|
|
|
|
.background(Color(uiColor: .tertiarySystemGroupedBackground))
|
|
|
|
}
|
|
|
|
|
|
|
|
private func callButton(_ text: LocalizedStringKey, _ image: String, _ color: Color, action: @escaping () -> Void) -> some View {
|
|
|
|
Button(action: action, label: {
|
|
|
|
VStack(spacing: 2) {
|
|
|
|
Image(systemName: image)
|
|
|
|
.scaleEffect(1.24)
|
|
|
|
.foregroundColor(color)
|
|
|
|
.frame(width: 24, height: 24)
|
|
|
|
Text(text)
|
|
|
|
.font(.caption)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
.frame(minWidth: 44)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct IncomingCallView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2022-07-05 15:15:15 +04:00
|
|
|
CallController.shared.activeCallInvitation = RcvCallInvitation.sampleData
|
2023-01-23 13:20:58 +00:00
|
|
|
let m = ChatModel()
|
|
|
|
m.users = [UserInfo.sampleData, UserInfo.sampleData]
|
|
|
|
return IncomingCallView().environmentObject(m)
|
2022-05-24 19:34:27 +01:00
|
|
|
}
|
|
|
|
}
|