Skip to content

Commit

Permalink
Improve Debug Stats Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacakakpo1 committed Aug 28, 2024
1 parent a7a56f5 commit 455ada9
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 39 deletions.
4 changes: 3 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 => '.'
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions TelnyxRTC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
3B0F56CA2C7F15830011A48A /* StatsMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatsMessage.swift; sourceTree = "<group>"; };
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 = "<group>"; };
3B1F43EE2AE0B01E00A610BA /* Params.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Params.swift; sourceTree = "<group>"; };
3B49B7142AA9B0A20026D36D /* AttachCallMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachCallMessage.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -208,6 +212,7 @@
buildActionMask = 2147483647;
files = (
1B0B82F8E58A096FBA0FB9CC /* (null) in Frameworks */,
3B0F56CD2C7F1CCA0011A48A /* Reachability.framework in Frameworks */,
9578D6261E82279EDEDFA516 /* Pods_TelnyxWebRTCDemo.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -231,6 +236,7 @@
B309D1D425F020A300A2AADF /* Verto */ = {
isa = PBXGroup;
children = (
3B0F56CA2C7F15830011A48A /* StatsMessage.swift */,
B309D1DA25F020D400A2AADF /* Method.swift */,
B309D1D525F020B300A2AADF /* Message.swift */,
B309D1EB25F024B900A2AADF /* LoginMessage.swift */,
Expand Down Expand Up @@ -443,6 +449,7 @@
EA45B40E24738E41F9F44AA0 /* Frameworks */ = {
isa = PBXGroup;
children = (
3B0F56CC2C7F1CCA0011A48A /* Reachability.framework */,
B309D11125EF107F00A2AADF /* Starscream.framework */,
8A11DAA0171B02D67683620E /* Pods_TelnyxRTC.framework */,
65B0B19B5206EECCAE2E29CA /* Pods_TelnyxRTC_TelnyxRTCTests.framework */,
Expand Down Expand Up @@ -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 */,
Expand Down
4 changes: 4 additions & 0 deletions TelnyxRTC/Telnyx/Utils/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class Timestamp {
func printTimestamp() {
print(dateFormatter.string(from: Date()))
}

func getTimestamp() -> String {
return dateFormatter.string(from: Date())
}
}

enum VertoDirection: Int {
Expand Down
2 changes: 1 addition & 1 deletion TelnyxRTC/Telnyx/WebRTC/Call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public class Call {
self.peer?.startTimer()
}

public func stopDebugStats() {
private func stopDebugStats() {
self.peer?.stopTimer()
}

Expand Down
41 changes: 6 additions & 35 deletions TelnyxRTC/Telnyx/WebRTC/Peer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"
Expand All @@ -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
}

Expand All @@ -565,7 +537,6 @@ class InitiateOrStopStats {
Logger.log.e(message: "Message:: encode() error")
return nil
}
Logger.log.i(message: "Message:: encode() " + jsonString)
return jsonString
}
}
Expand Down
2 changes: 2 additions & 0 deletions TelnyxWebRTCDemo/Extensions/AppDelegateCallKitExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions TelnyxWebRTCDemo/Extensions/ViewControllerVoIPExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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("")
} else {
print("Reachable via Cellular")
self.connectButtonTapped("")
}
}
}

}

Expand Down

0 comments on commit 455ada9

Please sign in to comment.