Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func addHandlers() {
- socket.on(clientEvent: .connect) {data, ack in
- self.joinGroup()
- }
- socket.on("connect") {
- data, ack in
- print("Socket Connected....")
- print("Join group 2")
- self.isJoining = false
- self.joinGroup()
- }
- socket.on("disconnect") {
- data, ack in
- self.connectToHost()
- }
- socket.on("onReady")
- {
- data, ack in
- if self.delegate == nil
- {
- return
- }
- print("onReady:")
- let onReady = data[0] as! String
- self.delegate?.didReceiveOnReadyResponse!(response: onReady)
- return
- }
- ...................
- }
- func acceptRapidEmergency(_ emergencyID:String,_ senderID:String )
- {
- socket.emitWithAck("acceptCallbackRequest",emergencyID,userID!,senderID)
- self.delegate?.didReceiveRapidEmergencyChatResponse?(emergencyID)
- }
- class VideoChatViewController: UIViewController, RTCSessionDescriptionDelegate, RTCPeerConnectionDelegate, TiaChatManagerDelegate,WebRTCDelegate{
- override func viewDidLoad() {
- .........
- let iceServer: RTCICEServer = RTCICEServer(uri: URL(string: "turn:cprtcstg.tiamd.com"), username: "tiatech", password: "tiatech!123") // Staging
- .......
- TiaChatManager.sharedInstance.acceptRapidEmergency(thisEventModal.broadCastID,thisEventModal.senderId)
- TiaChatManager.sharedInstance.isincomigVoip == false
- .......
- }
- ............
- func setupWebRTC(){
- webRTCManager = WebRTCManager()
- let iceServer: RTCICEServer = RTCICEServer(uri: URL(string: "turn:cprtcstg.tiamd.com:3478"), username: "tiatech", password: "tiatech!123")//Recent changed Server
- webRTCManager!.iceServers!.append(iceServer)
- webRTCManager!.constraints = RTCMediaConstraints(mandatoryConstraints:[ RTCPair(key: "OfferToReceiveAudio", value: "true")], optionalConstraints: nil)
- TiaChatManager.sharedInstance.webrtcdelegate = self as! WebRTCDelegate
- myUserID = UtilitySwift.getStringFromUserDefaultUsingKey(key: USER_ID);
- }
- let newFrame: CGRect = CGRect(x: self.localVideo!.frame.origin.x, y: self.localVideo!.frame.origin.y, width: 0, height: 0)
- self.localVideo!.frame = newFrame
- let notificationCenter = NotificationCenter.default
- notificationCenter.addObserver(self, selector: #selector(appMovedToBackground), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
- print("SETUP WEBRTC")
- }
- ......
- func didReceiveRapidEmergencyChatResponse(_ status: String) {
- startCapturingWebRTC()
- print("START CAPTURING")
- }
- .....
- func startCapturingWebRTC(){
- print("READY FOR CALL START")
- isRemoteHangup = false
- RTCPeerConnectionFactory.initializeSSL()
- webRTCManager!.rtcFactory = RTCPeerConnectionFactory()
- TiaConEmergencyManager.sharedInstance.webRTCManager.videoViewController = self
- webRTCManager!.peerConnection = webRTCManager!.rtcFactory!.peerConnection(withICEServers: webRTCManager!.iceServers, constraints: nil, delegate: webRTCManager)
- webRTCManager!.localMediaStream = webRTCManager!.rtcFactory!.mediaStream(withLabel: "webRTCAVStream")
- let audioTrack: RTCAudioTrack = webRTCManager!.rtcFactory!.audioTrack(withID: "audio0")
- webRTCManager!.localMediaStream!.addAudioTrack(audioTrack)
- if isCallBack != false || isWebCall != false {
- isAudioMute = false
- isVideoMute = true
- //isSpeakermode = false
- }
- var captureDevice : AVCaptureDevice?
- ......
- }
- }
Add Comment
Please, Sign In to add comment