Skip to content

Commit

Permalink
conditional stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-delirium committed Mar 12, 2024
1 parent 19c59d9 commit 1f5740e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Sources/OpenReplay/Listeners/Crash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Crashs: NSObject {

public func start() {
NSSetUncaughtExceptionHandler { (exception) in
print("<><> captured crash \(exception)")
DebugUtils.log("<><> captured crash \(exception)")
let message = ORIOSCrash(name: exception.name.rawValue,
reason: exception.reason ?? "",
stacktrace: exception.callStackSymbols.joined(separator: "\n"))
Expand Down
17 changes: 5 additions & 12 deletions Sources/OpenReplay/Managers/ConditionsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ class ConditionsManager: NSObject {
guard let messageType = msg.message else { return nil }

let matchingConditions = mappedConditions.filter { $0.tp == messageType }
if msg is ORIOSLog {
// todo
} else {
print(msg, matchingConditions)
}
for activeCon in matchingConditions {
switch msg {
case let networkMsg as ORIOSNetworkCall:
Expand Down Expand Up @@ -110,7 +105,7 @@ class ConditionsManager: NSObject {

func getConditions(projectId: String, token: String) {
guard let url = URL(string: "\(Openreplay.shared.serverURL)/v1/mobile/conditions/\(projectId)") else {
print("Invalid URL")
DebugUtils.error("Invalid URL")
return
}

Expand All @@ -120,28 +115,26 @@ class ConditionsManager: NSObject {

let task = URLSession.shared.dataTask(with: request) { [weak self] data, response, error in
guard let self = self, let data = data, error == nil else {
print("Network request failed: \(error?.localizedDescription ?? "No error")")
DebugUtils.error("Network request to get conditions failed: \(error?.localizedDescription ?? "No error")")
return
}

do {
let jsonResponse = try JSONDecoder().decode([String: [ApiResponse]].self, from: data)
guard let conditions = jsonResponse["conditions"] else {
print("Conditions key not found in JSON")
DebugUtils.error("Conditions key not found in JSON")
return
}
print("got api \(conditions)")
self.mapConditions(resp: conditions)
} catch {
DebugUtils.error("JSON parsing error: \(error)")
DebugUtils.error("Openreplay: Conditions JSON parsing error: \(error)")
}
}

task.resume()
}

func mapConditions(resp: [ApiResponse]) {
print(resp)
var conds: [Condition] = []
resp.forEach({ condition in
let filters = condition.filters
Expand Down Expand Up @@ -176,7 +169,7 @@ class ConditionsManager: NSObject {
}
})
})
print(conds)
DebugUtils.log("conditions \(conds)")
if !conds.isEmpty {
self.mappedConditions = conds
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenReplay/Managers/DebugUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class DebugUtils: NSObject {

static func error(_ str: String) {
// TODO: fix this one
// MessageCollector.shared.sendMessage(ASIOSInternalError(content: str))
// MessageCollector.shared.sendMessage(ASIOSInternalError(content: str))
print("OpenReplay Error: \(str)")
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenReplay/Managers/MessageCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class MessageCollector: NSObject {
let data = message.contentData()
if (Openreplay.shared.options.debugLogs) {
if !message.description.contains("IOSLog") && !message.description.contains("IOSNetworkCall") {
// DebugUtils.log(message.description)
DebugUtils.log(message.description)
}
if let networkCallMessage = message as? ORIOSNetworkCall {
DebugUtils.log("-->> IOSNetworkCall(105): \(networkCallMessage.method) \(networkCallMessage.URL)")
Expand Down
11 changes: 3 additions & 8 deletions Sources/OpenReplay/Managers/NetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ class NetworkManager: NSObject {
onSuccess: @escaping (Data) -> Void,
onError: @escaping (Error?) -> Void) {
guard !writeToFile else { return }
print("call api")
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
print("test")
DebugUtils.log(">>>\(request.httpMethod ?? ""):\(request.url?.absoluteString ?? "")\n<<<\(String(data: data ?? Data(), encoding: .utf8) ?? "")")

DispatchQueue.main.async {
Expand Down Expand Up @@ -67,10 +65,9 @@ class NetworkManager: NSObject {
var request = createRequest(method: "POST", path: START_URL)
guard let jsonData = try? JSONSerialization.data(withJSONObject: params, options: []) else {
completion(nil)
print("no params data")
DebugUtils.error("no params data")
return
}
print("test req")
request.httpBody = jsonData
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
callAPI(request: request) { (data) in
Expand All @@ -80,13 +77,12 @@ class NetworkManager: NSObject {
self.token = session.token
self.sessionId = session.sessionID
ORUserDefaults.shared.lastToken = self.token
print("got session")
completion(session)
} catch {
DebugUtils.log("Can't unwrap session start resp: \(error)")
}
} onError: { _ in
print("err")
} onError: { err in
DebugUtils.error(err.debugDescription)
completion(nil)
}
}
Expand Down Expand Up @@ -135,7 +131,6 @@ class NetworkManager: NSObject {
DebugUtils.log("! No last token found")
return
}
print(token)
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
request.httpBody = content
callAPI(request: request) { (data) in
Expand Down
4 changes: 1 addition & 3 deletions Sources/OpenReplay/ORTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ open class Openreplay: NSObject {
@objc public static let shared = Openreplay()
public let userDefaults = UserDefaults(suiteName: "io.asayer.AsayerSDK-defaults")
public var projectKey: String?
public var pkgVersion = "1.0.10"
public var pkgVersion = "1.1.10"
public var sessionStartTs: UInt64 = 0
public var trackerState = CheckState.unchecked
private var networkCheckTimer: Timer?
Expand Down Expand Up @@ -99,11 +99,9 @@ open class Openreplay: NSObject {
self.options = options
self.projectKey = projectKey
self.bufferingMode = true
print("cold start")
ORSessionRequest.create(doNotRecord: true) { sessionResponse in
guard let sessionResponse = sessionResponse else { return print("Openreplay: no response from /start request") }
self.sessionStartTs = UInt64(Date().timeIntervalSince1970 * 1000)
print("getting conds \(sessionResponse)")
ConditionsManager.shared.getConditions(projectId: sessionResponse.projectID, token: sessionResponse.token)
let captureSettings = getCaptureSettings(fps: sessionResponse.fps, quality: sessionResponse.quality)

Expand Down

0 comments on commit 1f5740e

Please sign in to comment.