VoIPCallSender.swift 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2019-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. import Foundation
  21. import CocoaLumberjackSwift
  22. class VoIPCallSender: NSObject {
  23. class func sendVoIPCall(offer: VoIPCallOfferMessage) {
  24. let msg = BoxVoIPCallOfferMessage()
  25. do {
  26. msg.jsonData = try offer.jsonData()
  27. msg.toIdentity = offer.contact!.identity
  28. DDLogNotice("Threema call: send offer to \(offer.contact!.identity ?? "?") with callId \(offer.callId.callId)")
  29. MessageQueue.shared()?.enqueue(msg)
  30. } catch let error {
  31. DDLogError("Threema call: Can't send offer message to \(offer.contact!.identity ?? "?") with callId \(offer.callId.callId)) -> \(error.localizedDescription)")
  32. }
  33. }
  34. class func sendVoIPCall(answer: VoIPCallAnswerMessage) {
  35. let msg = BoxVoIPCallAnswerMessage()
  36. do {
  37. msg.jsonData = try answer.jsonData()
  38. msg.toIdentity = answer.contact!.identity
  39. DDLogNotice("Threema call: send answer to \(answer.contact!.identity ?? "?") with callId \(answer.callId.callId)")
  40. MessageQueue.shared()?.enqueue(msg)
  41. }
  42. catch let error {
  43. DDLogError("Threema call: Can't send answer message to \(answer.contact!.identity ?? "?") with callId \(answer.callId.callId)) -> \(error.localizedDescription)")
  44. }
  45. }
  46. class func sendVoIPCall(iceCandidates: VoIPCallIceCandidatesMessage) {
  47. let msg = BoxVoIPCallIceCandidatesMessage()
  48. do {
  49. msg.jsonData = try iceCandidates.jsonData()
  50. msg.toIdentity = iceCandidates.contact!.identity
  51. DDLogNotice("Threema call: send iceCandidates to \(iceCandidates.contact!.identity ?? "?") with callId \(iceCandidates.callId.callId)")
  52. MessageQueue.shared()?.enqueue(msg)
  53. }
  54. catch let error {
  55. DDLogError("Threema call: Can't send ice candidates message \(iceCandidates.contact!.identity ?? "?") with callId \(iceCandidates.callId.callId)) -> \(error.localizedDescription)")
  56. }
  57. }
  58. class func sendVoIPCallHangup(hangupMessage: VoIPCallHangupMessage, wait: Bool) {
  59. let msg = BoxVoIPCallHangupMessage()
  60. do {
  61. msg.jsonData = try hangupMessage.jsonData()
  62. msg.toIdentity = hangupMessage.contact.identity
  63. DDLogNotice("Threema call: send hangup to \(hangupMessage.contact.identity ?? "?") with callId \(hangupMessage.callId.callId)")
  64. if wait == true {
  65. MessageQueue.shared()?.enqueueWait(msg)
  66. } else {
  67. MessageQueue.shared()?.enqueue(msg)
  68. }
  69. }
  70. catch let error {
  71. DDLogError("Threema call: Can't send hangup message to \(hangupMessage.contact.identity ?? "?") with callId \(hangupMessage.callId.callId)) -> \(error.localizedDescription)")
  72. }
  73. }
  74. class func sendVoIPCallRinging(ringingMessage: VoIPCallRingingMessage) {
  75. let msg = BoxVoIPCallRingingMessage()
  76. do {
  77. msg.jsonData = try ringingMessage.jsonData()
  78. msg.toIdentity = ringingMessage.contact.identity
  79. DDLogNotice("Threema call: send ringing to \(ringingMessage.contact.identity ?? "?") with callId \(ringingMessage.callId.callId)")
  80. MessageQueue.shared()?.enqueue(msg)
  81. }
  82. catch let error {
  83. DDLogError("Threema call: Can't send ringing message to \(ringingMessage.contact.identity ?? "?") with callId \(ringingMessage.callId.callId)) -> \(error.localizedDescription)")
  84. }
  85. }
  86. }