Guest User

Untitled

a guest
Aug 2nd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. func addHandlers() {
  2.  
  3. socket.on(clientEvent: .connect) {data, ack in
  4.  
  5. self.joinGroup()
  6. }
  7. socket.on("connect") {
  8. data, ack in
  9. print("Socket Connected....")
  10. print("Join group 2")
  11. self.isJoining = false
  12. self.joinGroup()
  13. }
  14. socket.on("disconnect") {
  15.  
  16. data, ack in
  17.  
  18. self.connectToHost()
  19. }
  20. socket.on("onReady")
  21. {
  22. data, ack in
  23. if self.delegate == nil
  24. {
  25. return
  26. }
  27. print("onReady:")
  28. let onReady = data[0] as! String
  29. self.delegate?.didReceiveOnReadyResponse!(response: onReady)
  30. return
  31. }
  32. ...................
  33. }
  34.  
  35. func acceptRapidEmergency(_ emergencyID:String,_ senderID:String )
  36. {
  37.  
  38. socket.emitWithAck("acceptCallbackRequest",emergencyID,userID!,senderID)
  39.  
  40. self.delegate?.didReceiveRapidEmergencyChatResponse?(emergencyID)
  41. }
  42.  
  43. class VideoChatViewController: UIViewController, RTCSessionDescriptionDelegate, RTCPeerConnectionDelegate, TiaChatManagerDelegate,WebRTCDelegate{
  44.  
  45. override func viewDidLoad() {
  46. .........
  47. let iceServer: RTCICEServer = RTCICEServer(uri: URL(string: "turn:cprtcstg.tiamd.com"), username: "tiatech", password: "tiatech!123") // Staging
  48. .......
  49. TiaChatManager.sharedInstance.acceptRapidEmergency(thisEventModal.broadCastID,thisEventModal.senderId)
  50. TiaChatManager.sharedInstance.isincomigVoip == false
  51.  
  52. .......
  53. }
  54. ............
  55. func setupWebRTC(){
  56.  
  57.  
  58. webRTCManager = WebRTCManager()
  59.  
  60. let iceServer: RTCICEServer = RTCICEServer(uri: URL(string: "turn:cprtcstg.tiamd.com:3478"), username: "tiatech", password: "tiatech!123")//Recent changed Server
  61.  
  62. webRTCManager!.iceServers!.append(iceServer)
  63. webRTCManager!.constraints = RTCMediaConstraints(mandatoryConstraints:[ RTCPair(key: "OfferToReceiveAudio", value: "true")], optionalConstraints: nil)
  64. TiaChatManager.sharedInstance.webrtcdelegate = self as! WebRTCDelegate
  65. myUserID = UtilitySwift.getStringFromUserDefaultUsingKey(key: USER_ID);
  66.  
  67. }
  68.  
  69. let newFrame: CGRect = CGRect(x: self.localVideo!.frame.origin.x, y: self.localVideo!.frame.origin.y, width: 0, height: 0)
  70. self.localVideo!.frame = newFrame
  71.  
  72.  
  73. let notificationCenter = NotificationCenter.default
  74. notificationCenter.addObserver(self, selector: #selector(appMovedToBackground), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
  75. print("SETUP WEBRTC")
  76. }
  77.  
  78. ......
  79. func didReceiveRapidEmergencyChatResponse(_ status: String) {
  80. startCapturingWebRTC()
  81. print("START CAPTURING")
  82. }
  83. .....
  84. func startCapturingWebRTC(){
  85. print("READY FOR CALL START")
  86. isRemoteHangup = false
  87. RTCPeerConnectionFactory.initializeSSL()
  88. webRTCManager!.rtcFactory = RTCPeerConnectionFactory()
  89. TiaConEmergencyManager.sharedInstance.webRTCManager.videoViewController = self
  90.  
  91. webRTCManager!.peerConnection = webRTCManager!.rtcFactory!.peerConnection(withICEServers: webRTCManager!.iceServers, constraints: nil, delegate: webRTCManager)
  92. webRTCManager!.localMediaStream = webRTCManager!.rtcFactory!.mediaStream(withLabel: "webRTCAVStream")
  93. let audioTrack: RTCAudioTrack = webRTCManager!.rtcFactory!.audioTrack(withID: "audio0")
  94. webRTCManager!.localMediaStream!.addAudioTrack(audioTrack)
  95. if isCallBack != false || isWebCall != false {
  96. isAudioMute = false
  97. isVideoMute = true
  98. //isSpeakermode = false
  99. }
  100.  
  101. var captureDevice : AVCaptureDevice?
  102. ......
  103. }
  104. }
Add Comment
Please, Sign In to add comment