|
@@ -29,6 +29,16 @@ class WhiteboardViewController: UIViewController, WhiteboardDelegate {
|
|
var roomId = ""
|
|
var roomId = ""
|
|
var destinations = [String]()
|
|
var destinations = [String]()
|
|
var incoming = false
|
|
var incoming = false
|
|
|
|
+ var fromContact: Int?
|
|
|
|
+ let myImage = UIImageView()
|
|
|
|
+ let name = UILabel()
|
|
|
|
+ let profileImage = UIImageView()
|
|
|
|
+ let labelIncomingOutgoing = UILabel()
|
|
|
|
+ var user: User?
|
|
|
|
+ let buttonDecline = UIButton()
|
|
|
|
+ let buttonAccept = UIButton()
|
|
|
|
+ var constraintLeadingButtonDecline = NSLayoutConstraint()
|
|
|
|
+ var constraintBottomButtonDecline = NSLayoutConstraint()
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
super.init(coder: coder)
|
|
@@ -37,8 +47,17 @@ class WhiteboardViewController: UIViewController, WhiteboardDelegate {
|
|
|
|
|
|
override func viewDidLoad() {
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
super.viewDidLoad()
|
|
- initWhiteboard()
|
|
|
|
|
|
+ if fromContact != nil {
|
|
|
|
+ addBackgroundIncoming()
|
|
|
|
+ addProfileNameCalling()
|
|
|
|
+ Calling()
|
|
|
|
+ addToolbar()
|
|
|
|
+ } else {
|
|
|
|
+ initWhiteboard()
|
|
|
|
+ }
|
|
self.title = "Whiteboard".localized()
|
|
self.title = "Whiteboard".localized()
|
|
|
|
+ let center: NotificationCenter = NotificationCenter.default
|
|
|
|
+ center.addObserver(self, selector: #selector(wbSession(notification:)), name: NSNotification.Name(rawValue: "wbSession"), object: nil)
|
|
// navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Close".localized(), style: .plain, target: self, action: #selector(close))
|
|
// navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Close".localized(), style: .plain, target: self, action: #selector(close))
|
|
// navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Clear".localized(), style: .plain,target: self, action: #selector(clear))
|
|
// navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Clear".localized(), style: .plain,target: self, action: #selector(clear))
|
|
|
|
|
|
@@ -46,6 +65,208 @@ class WhiteboardViewController: UIViewController, WhiteboardDelegate {
|
|
// Do any additional setup after loading the view.
|
|
// Do any additional setup after loading the view.
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ func addBackgroundIncoming() {
|
|
|
|
+ view.addSubview(myImage)
|
|
|
|
+ myImage.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
|
+ myImage.topAnchor.constraint(equalTo: view.topAnchor),
|
|
|
|
+ myImage.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
|
|
|
+ myImage.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
|
|
+ myImage.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
|
|
|
+ ])
|
|
|
|
+ myImage.backgroundColor = .lightGray
|
|
|
|
+ myImage.tintColor = .secondaryColor
|
|
|
|
+ let image = user!.thumb
|
|
|
|
+ if image.isEmpty {
|
|
|
|
+ myImage.image = UIImage(systemName: "person")
|
|
|
|
+ myImage.contentMode = .scaleAspectFit
|
|
|
|
+ } else {
|
|
|
|
+ myImage.setImage(name: image)
|
|
|
|
+ myImage.contentMode = .scaleAspectFill
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func addProfileNameCalling() {
|
|
|
|
+ view.addSubview(profileImage)
|
|
|
|
+ profileImage.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
+ profileImage.frame.size = CGSize(width: 60.0, height: 60.0)
|
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
|
+ profileImage.topAnchor.constraint(equalTo: view.topAnchor, constant: 40.0),
|
|
|
|
+ profileImage.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
|
|
|
+ profileImage.widthAnchor.constraint(equalToConstant: 60.0),
|
|
|
|
+ profileImage.heightAnchor.constraint(equalToConstant: 63.0)
|
|
|
|
+ ])
|
|
|
|
+ profileImage.backgroundColor = .lightGray
|
|
|
|
+ profileImage.tintColor = .secondaryColor
|
|
|
|
+ profileImage.circle()
|
|
|
|
+ let image = user!.thumb
|
|
|
|
+ if image.isEmpty {
|
|
|
|
+ profileImage.image = UIImage(systemName: "person")
|
|
|
|
+ profileImage.contentMode = .scaleAspectFit
|
|
|
|
+ profileImage.layer.borderWidth = 1
|
|
|
|
+ profileImage.layer.borderColor = UIColor.secondaryColor.cgColor
|
|
|
|
+ } else {
|
|
|
|
+ profileImage.setImage(name: image)
|
|
|
|
+ profileImage.contentMode = .scaleAspectFill
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ view.addSubview(name)
|
|
|
|
+ name.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
|
+ name.topAnchor.constraint(equalTo: profileImage.bottomAnchor, constant: 5.0),
|
|
|
|
+ name.centerXAnchor.constraint(equalTo: view.centerXAnchor)
|
|
|
|
+ ])
|
|
|
|
+ name.font = UIFont.systemFont(ofSize: 12)
|
|
|
|
+ name.backgroundColor = .black.withAlphaComponent(0.05)
|
|
|
|
+ name.layer.cornerRadius = 5.0
|
|
|
|
+ name.clipsToBounds = true
|
|
|
|
+ name.textColor = .mainColor
|
|
|
|
+ name.text = user?.fullName.trimmingCharacters(in: .whitespaces)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func Calling() {
|
|
|
|
+ view.addSubview(labelIncomingOutgoing)
|
|
|
|
+ labelIncomingOutgoing.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
|
+ labelIncomingOutgoing.topAnchor.constraint(equalTo: name.bottomAnchor, constant: 40.0),
|
|
|
|
+ labelIncomingOutgoing.centerXAnchor.constraint(equalTo: view.centerXAnchor)
|
|
|
|
+ ])
|
|
|
|
+ if fromContact == 0 {
|
|
|
|
+ labelIncomingOutgoing.text = "Waiting for answer".localized() + "..."
|
|
|
|
+ _ = Nexilis.write(message: CoreMessage_TMessageBank.wbCreate(l_pin: user!.pin))
|
|
|
|
+ } else {
|
|
|
|
+ labelIncomingOutgoing.text = "Incoming Whiteboard".localized() + "..."
|
|
|
|
+ }
|
|
|
|
+ labelIncomingOutgoing.font = UIFont.systemFont(ofSize: 12)
|
|
|
|
+ labelIncomingOutgoing.backgroundColor = .black.withAlphaComponent(0.05)
|
|
|
|
+ labelIncomingOutgoing.layer.cornerRadius = 5.0
|
|
|
|
+ labelIncomingOutgoing.clipsToBounds = true
|
|
|
|
+ labelIncomingOutgoing.textColor = .mainColor
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func addToolbar() {
|
|
|
|
+ view.addSubview(buttonDecline)
|
|
|
|
+ buttonDecline.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
+ buttonDecline.frame.size = CGSize(width: 70.0, height: 70.0)
|
|
|
|
+ if fromContact == 0 {
|
|
|
|
+ constraintLeadingButtonDecline = buttonDecline.centerXAnchor.constraint(equalTo: view.centerXAnchor)
|
|
|
|
+ } else {
|
|
|
|
+ constraintLeadingButtonDecline = buttonDecline.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: view.frame.width * 0.2)
|
|
|
|
+ }
|
|
|
|
+ constraintBottomButtonDecline = buttonDecline.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -60.0)
|
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
|
+ constraintBottomButtonDecline,
|
|
|
|
+ constraintLeadingButtonDecline,
|
|
|
|
+ buttonDecline.widthAnchor.constraint(equalToConstant: 70.0),
|
|
|
|
+ buttonDecline.heightAnchor.constraint(equalToConstant: 70.0)
|
|
|
|
+ ])
|
|
|
|
+ buttonDecline.backgroundColor = .red
|
|
|
|
+ buttonDecline.circle()
|
|
|
|
+ buttonDecline.setImage(UIImage(systemName: "xmark", withConfiguration: UIImage.SymbolConfiguration(pointSize: 30, weight: .medium, scale: .default)), for: .normal)
|
|
|
|
+ buttonDecline.tintColor = .white
|
|
|
|
+ buttonDecline.addTarget(self, action: #selector(didTapDeclineCallButton(sender:)), for: .touchUpInside)
|
|
|
|
+
|
|
|
|
+ if fromContact == 1 {
|
|
|
|
+ view.addSubview(buttonAccept)
|
|
|
|
+ buttonAccept.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
+ buttonAccept.frame.size = CGSize(width: 70.0, height: 70.0)
|
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
|
+ buttonAccept.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -60.0),
|
|
|
|
+ buttonAccept.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -(view.frame.width * 0.2)),
|
|
|
|
+ buttonAccept.widthAnchor.constraint(equalToConstant: 70.0),
|
|
|
|
+ buttonAccept.heightAnchor.constraint(equalToConstant: 70.0)
|
|
|
|
+ ])
|
|
|
|
+ buttonAccept.backgroundColor = .greenColor
|
|
|
|
+ buttonAccept.circle()
|
|
|
|
+ buttonAccept.setImage(UIImage(systemName: "checkmark", withConfiguration: UIImage.SymbolConfiguration(pointSize: 30, weight: .medium, scale: .default)), for: .normal)
|
|
|
|
+ buttonAccept.tintColor = .white
|
|
|
|
+ buttonAccept.addTarget(self, action: #selector(didTapAcceptCallButton), for: .touchUpInside)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @objc func didTapDeclineCallButton(sender: Any) {
|
|
|
|
+ let alert = UIAlertController(title: "End Whiteboard Session".localized(), message: "Are you sure you want to end whiteboard session?".localized(), preferredStyle: .alert)
|
|
|
|
+ alert.addAction(UIAlertAction(title: "No".localized(), style: UIAlertAction.Style.default, handler: nil))
|
|
|
|
+ alert.addAction(UIAlertAction(title: "Yes".localized(), style: UIAlertAction.Style.default, handler: {(_) in
|
|
|
|
+ if self.fromContact == 0 {
|
|
|
|
+ _ = Nexilis.write(message: CoreMessage_TMessageBank.wbEnded(l_pin: self.user!.pin))
|
|
|
|
+ } else {
|
|
|
|
+ _ = Nexilis.write(message: CoreMessage_TMessageBank.wbReject(l_pin: self.user!.pin))
|
|
|
|
+ }
|
|
|
|
+ self.dismiss(animated: true, completion: nil)
|
|
|
|
+ }))
|
|
|
|
+ self.present(alert, animated: true, completion: nil)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @objc func didTapAcceptCallButton() {
|
|
|
|
+ _ = Nexilis.write(message: CoreMessage_TMessageBank.wbAccept(l_pin: user!.pin))
|
|
|
|
+ self.myImage.removeFromSuperview()
|
|
|
|
+ self.name.removeFromSuperview()
|
|
|
|
+ self.profileImage.removeFromSuperview()
|
|
|
|
+ self.labelIncomingOutgoing.removeFromSuperview()
|
|
|
|
+ self.buttonDecline.removeFromSuperview()
|
|
|
|
+ self.buttonAccept.removeFromSuperview()
|
|
|
|
+ NSLayoutConstraint.deactivate([
|
|
|
|
+ self.constraintLeadingButtonDecline,
|
|
|
|
+ self.constraintBottomButtonDecline
|
|
|
|
+ ])
|
|
|
|
+ self.initWhiteboard()
|
|
|
|
+ let tid = CoreMessage_TMessageUtil.getTID()
|
|
|
|
+ self.roomId = "\(user!.pin)WB\(tid)"
|
|
|
|
+ let idMe = UserDefaults.standard.string(forKey: "me")!
|
|
|
|
+ UserDefaults.standard.set("\(user!.pin),\(idMe)", forKey: "wb_vc")
|
|
|
|
+ self.sendJoin()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @objc func wbSession(notification: NSNotification) {
|
|
|
|
+ DispatchQueue.main.async { [self] in
|
|
|
|
+ let data:[AnyHashable : Any] = notification.userInfo!
|
|
|
|
+ if let message = data["message"] as? TMessage {
|
|
|
|
+ let status = message.getBody(key: CoreMessage_TMessageKey.STATUS, default_value: "")
|
|
|
|
+ switch (Int(status)) {
|
|
|
|
+ case CoreMessage_TMessageCode.WB_ACCEPT_INCOMING:
|
|
|
|
+ print("WB_ACCEPT_INCOMING")
|
|
|
|
+ let f_pin = message.getBody(key: CoreMessage_TMessageKey.F_USER_ID, default_value: "")
|
|
|
|
+ _ = Nexilis.write(message: CoreMessage_TMessageBank.wbOffhook(l_pin: f_pin))
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ let l_pin = message.getBody(key: CoreMessage_TMessageKey.L_PIN, default_value: "")
|
|
|
|
+ self.myImage.removeFromSuperview()
|
|
|
|
+ self.name.removeFromSuperview()
|
|
|
|
+ self.profileImage.removeFromSuperview()
|
|
|
|
+ self.labelIncomingOutgoing.removeFromSuperview()
|
|
|
|
+ self.buttonDecline.removeFromSuperview()
|
|
|
|
+ NSLayoutConstraint.deactivate([
|
|
|
|
+ self.constraintLeadingButtonDecline,
|
|
|
|
+ self.constraintBottomButtonDecline
|
|
|
|
+ ])
|
|
|
|
+ self.initWhiteboard()
|
|
|
|
+ let tid = CoreMessage_TMessageUtil.getTID()
|
|
|
|
+ self.roomId = "\(f_pin)WB\(tid)"
|
|
|
|
+ self.destinations = [l_pin]
|
|
|
|
+ self.sendInit()
|
|
|
|
+ }
|
|
|
|
+ case CoreMessage_TMessageCode.WB_REJECT_INCOMING,CoreMessage_TMessageCode.WB_END:
|
|
|
|
+ print("WB_REJECT_INCOMING \(status)")
|
|
|
|
+ if self.labelIncomingOutgoing.isDescendant(of: self.view) {
|
|
|
|
+ self.labelIncomingOutgoing.text = "WhiteBoard session is over".localized()
|
|
|
|
+ }
|
|
|
|
+ if self.buttonDecline.isDescendant(of: self.view) {
|
|
|
|
+ self.buttonDecline.removeFromSuperview()
|
|
|
|
+ }
|
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
|
|
|
+ self.dismiss(animated: true, completion: nil)
|
|
|
|
+ }
|
|
|
|
+ case CoreMessage_TMessageCode.WB_OFFHOOK:
|
|
|
|
+ print("WB_OFFHOOK")
|
|
|
|
+ case CoreMessage_TMessageCode.WB_RINGING:
|
|
|
|
+ print("WB_RINGING")
|
|
|
|
+ default:
|
|
|
|
+ print("default")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
func initWhiteboard(){
|
|
func initWhiteboard(){
|
|
let wbHeight = self.view.frame.width * 20.0 / 9.0
|
|
let wbHeight = self.view.frame.width * 20.0 / 9.0
|
|
let rect = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height)
|
|
let rect = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height)
|
|
@@ -84,6 +305,10 @@ class WhiteboardViewController: UIViewController, WhiteboardDelegate {
|
|
}
|
|
}
|
|
|
|
|
|
@IBAction func didTapClose(_ sender: Any) {
|
|
@IBAction func didTapClose(_ sender: Any) {
|
|
|
|
+ if fromContact != nil {
|
|
|
|
+ didTapDeclineCallButton(sender: 0)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
close?()
|
|
close?()
|
|
}
|
|
}
|
|
|
|
|