diff --git a/Podfile b/Podfile index 42ffac16..12fa0839 100644 --- a/Podfile +++ b/Podfile @@ -4,6 +4,8 @@ platform :ios, '12.0' target 'TelnyxWebRTCDemo' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! + + pod 'ReachabilitySwift', '~> 5.2.1' # Pods for TelnyxWebRTCDemo pod 'TelnyxRTC', :path => '.' @@ -18,7 +20,7 @@ target 'TelnyxRTC' do pod 'Bugsnag', '~> 6.28.1' pod 'Starscream', '~> 4.0.6' pod 'WebRTC-lib', "~> 124.0.0" - pod 'ReachabilitySwift', '~> 5.2.1' + target 'TelnyxRTCTests' do diff --git a/TelnyxRTC.xcodeproj/project.pbxproj b/TelnyxRTC.xcodeproj/project.pbxproj index a565d65b..8db67d3a 100644 --- a/TelnyxRTC.xcodeproj/project.pbxproj +++ b/TelnyxRTC.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 1B0B82F8E58A096FBA0FB9CC /* (null) in Frameworks */ = {isa = PBXBuildFile; }; + 3B0F56CB2C7F15830011A48A /* StatsMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B0F56CA2C7F15830011A48A /* StatsMessage.swift */; }; + 3B0F56CD2C7F1CCA0011A48A /* Reachability.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B0F56CC2C7F1CCA0011A48A /* Reachability.framework */; }; 3B1BE6F72AA9A467000B7962 /* TxPushIPConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B1BE6F62AA9A467000B7962 /* TxPushIPConfig.swift */; }; 3B1F43EF2AE0B01E00A610BA /* Params.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B1F43EE2AE0B01E00A610BA /* Params.swift */; }; 3B49B7152AA9B0A20026D36D /* AttachCallMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B49B7142AA9B0A20026D36D /* AttachCallMessage.swift */; }; @@ -106,6 +108,8 @@ 00B066EA7AECA1E61F1CC13D /* Pods-TelnyxRTC-TelnyxRTCTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TelnyxRTC-TelnyxRTCTests.debug.xcconfig"; path = "Target Support Files/Pods-TelnyxRTC-TelnyxRTCTests/Pods-TelnyxRTC-TelnyxRTCTests.debug.xcconfig"; sourceTree = ""; }; 064620D5372C98975322D84C /* Pods-TelnyxRTC.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TelnyxRTC.release.xcconfig"; path = "Target Support Files/Pods-TelnyxRTC/Pods-TelnyxRTC.release.xcconfig"; sourceTree = ""; }; 0BC0EF15A80C9BA767873075 /* Pods-TelnyxWebRTCDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TelnyxWebRTCDemo.debug.xcconfig"; path = "Target Support Files/Pods-TelnyxWebRTCDemo/Pods-TelnyxWebRTCDemo.debug.xcconfig"; sourceTree = ""; }; + 3B0F56CA2C7F15830011A48A /* StatsMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatsMessage.swift; sourceTree = ""; }; + 3B0F56CC2C7F1CCA0011A48A /* Reachability.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Reachability.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3B1BE6F62AA9A467000B7962 /* TxPushIPConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TxPushIPConfig.swift; sourceTree = ""; }; 3B1F43EE2AE0B01E00A610BA /* Params.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Params.swift; sourceTree = ""; }; 3B49B7142AA9B0A20026D36D /* AttachCallMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachCallMessage.swift; sourceTree = ""; }; @@ -208,6 +212,7 @@ buildActionMask = 2147483647; files = ( 1B0B82F8E58A096FBA0FB9CC /* (null) in Frameworks */, + 3B0F56CD2C7F1CCA0011A48A /* Reachability.framework in Frameworks */, 9578D6261E82279EDEDFA516 /* Pods_TelnyxWebRTCDemo.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -231,6 +236,7 @@ B309D1D425F020A300A2AADF /* Verto */ = { isa = PBXGroup; children = ( + 3B0F56CA2C7F15830011A48A /* StatsMessage.swift */, B309D1DA25F020D400A2AADF /* Method.swift */, B309D1D525F020B300A2AADF /* Message.swift */, B309D1EB25F024B900A2AADF /* LoginMessage.swift */, @@ -443,6 +449,7 @@ EA45B40E24738E41F9F44AA0 /* Frameworks */ = { isa = PBXGroup; children = ( + 3B0F56CC2C7F1CCA0011A48A /* Reachability.framework */, B309D11125EF107F00A2AADF /* Starscream.framework */, 8A11DAA0171B02D67683620E /* Pods_TelnyxRTC.framework */, 65B0B19B5206EECCAE2E29CA /* Pods_TelnyxRTC_TelnyxRTCTests.framework */, @@ -709,6 +716,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 3B0F56CB2C7F15830011A48A /* StatsMessage.swift in Sources */, 3B49B7152AA9B0A20026D36D /* AttachCallMessage.swift in Sources */, B36FC8C02612794A00A30BC4 /* Logger.swift in Sources */, B3AF248B25EE7C350062EDA9 /* Socket.swift in Sources */, diff --git a/TelnyxRTC/Telnyx/Utils/Logger.swift b/TelnyxRTC/Telnyx/Utils/Logger.swift index d0302494..9dd50eac 100644 --- a/TelnyxRTC/Telnyx/Utils/Logger.swift +++ b/TelnyxRTC/Telnyx/Utils/Logger.swift @@ -43,6 +43,10 @@ class Timestamp { func printTimestamp() { print(dateFormatter.string(from: Date())) } + + func getTimestamp() -> String { + return dateFormatter.string(from: Date()) + } } enum VertoDirection: Int { diff --git a/TelnyxRTC/Telnyx/WebRTC/Call.swift b/TelnyxRTC/Telnyx/WebRTC/Call.swift index bebce883..3d3f87e1 100644 --- a/TelnyxRTC/Telnyx/WebRTC/Call.swift +++ b/TelnyxRTC/Telnyx/WebRTC/Call.swift @@ -189,7 +189,7 @@ public class Call { self.peer?.startTimer() } - public func stopDebugStats() { + private func stopDebugStats() { self.peer?.stopTimer() } diff --git a/TelnyxRTC/Telnyx/WebRTC/Peer.swift b/TelnyxRTC/Telnyx/WebRTC/Peer.swift index 1cb66862..b372f72e 100644 --- a/TelnyxRTC/Telnyx/WebRTC/Peer.swift +++ b/TelnyxRTC/Telnyx/WebRTC/Peer.swift @@ -236,14 +236,14 @@ class Peer : NSObject { /// To receive INVITE message after Push Noficiation is Received. Send attachCall Command fileprivate func sendStats(id:UUID,data:[String:Any]) { - Logger.log.e(message: "TxClient:: PN Recieved.. Sending reattach call ") - let statsMessage = StatsMessage(reportID: id.uuidString, reportData: data) + Logger.log.e(message: "TxClient:: Sending Stats") + let statsMessage = StatsMessage(reportID: id.uuidString.lowercased(), reportData: data) self.socket?.sendMessage(message: statsMessage.encode()) } fileprivate func sendStatsType(id:UUID,type:String) { - Logger.log.e(message: "TxClient:: PN Recieved.. Sending reattach call ") - let statsMessage = InitiateOrStopStats(type: type, reportID: id.uuidString) + Logger.log.e(message: "TxClient:: Sending Stats \(type)") + let statsMessage = InitiateOrStopStats(type: type, reportID: id.uuidString.lowercased()) self.socket?.sendMessage(message: statsMessage.encode()) } @@ -287,7 +287,7 @@ class Peer : NSObject { audio["inbound"] = inboundStats statsData["audio"] = audio statsEvent["data"] = statsData - statsEvent["timestamp"] = timeStamp.printTimestamp() + statsEvent["timestamp"] = timeStamp.getTimestamp() if(inboundStats.count > 0 && outBoundStats.count > 0 && candidatePairs.count > 0){ inboundStats.removeAll() @@ -509,35 +509,7 @@ extension Dictionary { private let PROTOCOL_VERSION: String = "2.0" -class StatsMessage { - - private var jsonMessage: [String: Any] = [String: Any]() - let jsonrpc = PROTOCOL_VERSION - var id: String = UUID.init().uuidString.lowercased() - - init(reportID:String,reportData:[String:Any]) { - self.jsonMessage = [String: Any]() - self.jsonMessage["jsonrpc"] = self.jsonrpc - self.jsonMessage["id"] = self.id - self.jsonMessage["debug_report_version"] = 1 - self.jsonMessage["debug_report_data"] = reportData - self.jsonMessage["type"] = "debug_report_data" - self.jsonMessage["debug_report_id"] = reportID - } - - func encode() -> String? { - guard let jsonData = try? JSONSerialization.data(withJSONObject: jsonMessage, options: []), - let jsonString = String(data: jsonData, encoding: .utf8) else { - Logger.log.e(message: "Message:: encode() error") - return nil - } - Logger.log.i(message: "Message:: encode() " + jsonString) - return jsonString - } - - -} enum StatsType : String { case STOP_STARTS = "debug_report_stop" @@ -555,7 +527,7 @@ class InitiateOrStopStats { self.jsonMessage["jsonrpc"] = self.jsonrpc self.jsonMessage["id"] = self.id self.jsonMessage["debug_report_version"] = 1 - self.jsonMessage["type"] = "debug_report_stop" + self.jsonMessage["type"] = type self.jsonMessage["debug_report_id"] = reportID } @@ -565,7 +537,6 @@ class InitiateOrStopStats { Logger.log.e(message: "Message:: encode() error") return nil } - Logger.log.i(message: "Message:: encode() " + jsonString) return jsonString } } diff --git a/TelnyxWebRTCDemo/Extensions/AppDelegateCallKitExtension.swift b/TelnyxWebRTCDemo/Extensions/AppDelegateCallKitExtension.swift index 47481e98..cb2cde8b 100644 --- a/TelnyxWebRTCDemo/Extensions/AppDelegateCallKitExtension.swift +++ b/TelnyxWebRTCDemo/Extensions/AppDelegateCallKitExtension.swift @@ -152,11 +152,13 @@ extension AppDelegate : CXProviderDelegate { } } action.fulfill() + self.currentCall?.startDebugStats() } func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) { print("AppDelegate:: ANSWER call action: callKitUUID [\(String(describing: self.callKitUUID))] action [\(action.callUUID)]") self.telnyxClient?.answerFromCallkit(answerAction: action, customHeaders: ["X-test-answer":"ios-test"]) + self.currentCall?.startDebugStats() } func provider(_ provider: CXProvider, perform action: CXEndCallAction) { diff --git a/TelnyxWebRTCDemo/Extensions/ViewControllerVoIPExtension.swift b/TelnyxWebRTCDemo/Extensions/ViewControllerVoIPExtension.swift index cb90f63b..d2e65b46 100644 --- a/TelnyxWebRTCDemo/Extensions/ViewControllerVoIPExtension.swift +++ b/TelnyxWebRTCDemo/Extensions/ViewControllerVoIPExtension.swift @@ -37,7 +37,7 @@ extension ViewController : VoIPDelegate { self.incomingCallView.isHidden = true } - self.reachability.whenReachable = { reachability in + self.reachability.whenReachable = { reachability in if reachability.connection == .wifi { print("Reachable via WiFi") self.connectButtonTapped("") @@ -45,7 +45,7 @@ extension ViewController : VoIPDelegate { print("Reachable via Cellular") self.connectButtonTapped("") } - } + } }