Callback.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // Callback.swift
  3. // Runner
  4. //
  5. // Created by Yayan Dwi on 15/04/20.
  6. // Copyright © 2020 The Chromium Authors. All rights reserved.
  7. //
  8. import Foundation
  9. import nuSDKService
  10. class Callback : CallBack {
  11. var sID: String = "Callback"
  12. func connectionStateChanged(sUserID: String!, sDeviceID: String!, bConState: Bool!, nConType: Int!, nConSubType: Int!, nCLMConStat: UInt8!) {
  13. //print(sUserID, "/", sDeviceID, "/", bConState, "/", nConType, "/", nConSubType, "/", nCLMConStat)
  14. if let dispatch = DigiX.dispatch, bConState {
  15. dispatch.leave()
  16. }
  17. if let delegate = DigiX.shared.connectionDelegate {
  18. delegate.connectionStateChanged(userId: sUserID, deviceId: sDeviceID, state: bConState)
  19. }
  20. OutgoingThread.default.set(wait: nCLMConStat == 0)
  21. }
  22. func gpsStateChanged(nState: Int!) {
  23. }
  24. func sleepStateChanged(bState: Bool!) {
  25. }
  26. func callStateChanged(nState: Int!, sMessage: String!) -> Int {
  27. //print(nState,"/",sMessage)
  28. if nState == DigiX.AUDIO_CALL_INCOMING || nState == DigiX.VIDEO_CALL_INCOMING {
  29. if let delegate = DigiX.shared.callDelegate {
  30. if !DigiX.showLibraryNotification {
  31. delegate.onStatusCall(state: nState, message: sMessage)
  32. } else {
  33. delegate.onIncomingCall(state: nState, message: sMessage)
  34. }
  35. }
  36. } else {
  37. // if nState == 28 {
  38. // let pin = sMessage.split(separator: ",")[0]
  39. // if let call = Palio.shared.callManager.call(with: String(pin)), !call.hasVideo, !call.hasEnded {
  40. // call.reconnectingCall()
  41. // return 1
  42. // }
  43. // }
  44. if let delegate = DigiX.shared.callDelegate {
  45. delegate.onStatusCall(state: nState, message: sMessage)
  46. }
  47. }
  48. return 1
  49. }
  50. func bcastStateChanged(nState: Int!, sMessage: String!) -> Int {
  51. //print(("LS CALLBACK ",nState,"/",sMessage)
  52. if let delegate = DigiX.shared.streamingDelagate {
  53. delegate.onStartLS(state: nState, message: sMessage)
  54. }
  55. if let delegate = DigiX.shared.streamingDelagate {
  56. delegate.onJoinLS(state: nState, message: sMessage)
  57. }
  58. if let delegate = DigiX.shared.seminarDelegate {
  59. delegate.onStartSeminar(state: nState, message: sMessage)
  60. }
  61. if let delegate = DigiX.shared.seminarDelegate {
  62. delegate.onJoinSeminar(state: nState, message: sMessage)
  63. }
  64. return 1
  65. }
  66. func sshareStateChanged(nState: Int!, sMessage: String!) -> Int {
  67. //print(("Screen sharing state: ",nState,"/",sMessage)
  68. switch nState {
  69. case 0:
  70. if (sMessage.starts(with: "Initiating")){
  71. if let delegate = DigiX.shared.screenSharingDelegate {
  72. delegate.onStartScreenSharing(state: nState, message: sMessage)
  73. }
  74. }
  75. case 12:
  76. if let delegate = DigiX.shared.screenSharingDelegate {
  77. delegate.onStartScreenSharing(state: nState, message: sMessage)
  78. }
  79. case 22:
  80. if let delegate = DigiX.shared.screenSharingDelegate {
  81. delegate.onJoinScreenSharing(state: nState, message: sMessage)
  82. }
  83. case 88:
  84. if let delegate = DigiX.shared.screenSharingDelegate {
  85. delegate.onStartScreenSharing(state: nState, message: sMessage)
  86. }
  87. if let delegate = DigiX.shared.screenSharingDelegate {
  88. delegate.onJoinScreenSharing(state: nState, message: sMessage)
  89. }
  90. default:
  91. break
  92. }
  93. return 1
  94. }
  95. func incomingData(sPacketID: String!, oData: AnyObject!) throws {
  96. DigiX.incomingData(packetId: sPacketID!, data: oData!)
  97. }
  98. func lateResponse(sPacketID: String!, sResponse: String!) throws {
  99. }
  100. func asycnACKReceived(sPacketID: String!) throws {
  101. //print(("asycnACKReceived: \(sPacketID)")
  102. DispatchQueue.global().async {
  103. Database.shared.database?.inTransaction({ (fmdb, rollback) in
  104. OutgoingThread.default.delOutgoing(fmdb: fmdb, packageId: sPacketID)
  105. })
  106. }
  107. }
  108. func locationUpdated(lTime: Int64!, sLocationInfo: String!) {
  109. }
  110. func resetDB() {
  111. }
  112. }