Callback.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 = Nexilis.dispatch, bConState {
  15. dispatch.leave()
  16. }
  17. if let delegate = Nexilis.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 == 21 || nState == 31 {
  29. if let delegate = Nexilis.shared.callDelegate {
  30. delegate.onIncomingCall(state: nState, message: sMessage)
  31. }
  32. } else {
  33. // if nState == 28 {
  34. // let pin = sMessage.split(separator: ",")[0]
  35. // if let call = Palio.shared.callManager.call(with: String(pin)), !call.hasVideo, !call.hasEnded {
  36. // call.reconnectingCall()
  37. // return 1
  38. // }
  39. // }
  40. if let delegate = Nexilis.shared.callDelegate {
  41. delegate.onStatusCall(state: nState, message: sMessage)
  42. }
  43. }
  44. return 1
  45. }
  46. func bcastStateChanged(nState: Int!, sMessage: String!) -> Int {
  47. print("LS CALLBACK ",nState,"/",sMessage)
  48. if let delegate = Nexilis.shared.streamingDelagate {
  49. delegate.onStartLS(state: nState, message: sMessage)
  50. }
  51. if let delegate = Nexilis.shared.streamingDelagate {
  52. delegate.onJoinLS(state: nState, message: sMessage)
  53. }
  54. return 1
  55. }
  56. func sshareStateChanged(nState: Int!, sMessage: String!) -> Int {
  57. print("Screen sharing state: ",nState,"/",sMessage)
  58. switch nState {
  59. case 0:
  60. if (sMessage.starts(with: "Initiating")){
  61. if let delegate = Nexilis.shared.screenSharingDelegate {
  62. delegate.onStartScreenSharing(state: nState, message: sMessage)
  63. }
  64. }
  65. case 12:
  66. if let delegate = Nexilis.shared.screenSharingDelegate {
  67. delegate.onStartScreenSharing(state: nState, message: sMessage)
  68. }
  69. case 22:
  70. if let delegate = Nexilis.shared.screenSharingDelegate {
  71. delegate.onJoinScreenSharing(state: nState, message: sMessage)
  72. }
  73. case 88:
  74. if let delegate = Nexilis.shared.screenSharingDelegate {
  75. delegate.onStartScreenSharing(state: nState, message: sMessage)
  76. }
  77. if let delegate = Nexilis.shared.screenSharingDelegate {
  78. delegate.onJoinScreenSharing(state: nState, message: sMessage)
  79. }
  80. default:
  81. break
  82. }
  83. return 1
  84. }
  85. func incomingData(sPacketID: String!, oData: AnyObject!) throws {
  86. Nexilis.incomingData(packetId: sPacketID!, data: oData!)
  87. }
  88. func lateResponse(sPacketID: String!, sResponse: String!) throws {
  89. }
  90. func asycnACKReceived(sPacketID: String!) throws {
  91. print("asycnACKReceived: \(sPacketID)")
  92. DispatchQueue.global().async {
  93. Database.shared.database?.inTransaction({ (fmdb, rollback) in
  94. OutgoingThread.default.delOutgoing(fmdb: fmdb, packageId: sPacketID)
  95. })
  96. }
  97. }
  98. func locationUpdated(lTime: Int64!, sLocationInfo: String!) {
  99. }
  100. func resetDB() {
  101. }
  102. }