Skip to content

Commit

Permalink
fix messagecollector; rename message types
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-delirium committed Jul 30, 2024
1 parent 1f5740e commit 3f59ba1
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 178 deletions.
20 changes: 10 additions & 10 deletions Sources/OpenReplay/Listeners/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ open class Analytics: NSObject {
}

@objc public func sendClick(label: String, x: UInt64, y: UInt64) {
let message = ORIOSClickEvent(label: label, x: x, y: y)
let message = ORMobileClickEvent(label: label, x: x, y: y)

if Analytics.shared.enabled {
MessageCollector.shared.sendMessage(message)
}
}

@objc public func sendSwipe(label: String, x: UInt64, y: UInt64, direction: String) {
let message = ORIOSSwipeEvent(label: label, x: x,y: y, direction: direction)
let message = ORMobileSwipeEvent(label: label, x: x,y: y, direction: direction)

if Analytics.shared.enabled {
MessageCollector.shared.sendMessage(message)
Expand All @@ -64,7 +64,7 @@ open class Analytics: NSObject {
if sender.isSecureTextEntry {
sentText = "***"
}
MessageCollector.shared.sendMessage(ORIOSInputEvent(value: sentText ?? "", valueMasked: sender.isSecureTextEntry, label: sender.placeholder ?? ""))
MessageCollector.shared.sendMessage(ORMobileInputEvent(value: sentText ?? "", valueMasked: sender.isSecureTextEntry, label: sender.placeholder ?? ""))
}
}

Expand All @@ -88,7 +88,7 @@ extension UIViewController {
self.swizzledViewDidAppear(animated)

if let (screenName, viewName) = isViewOrSubviewObservedEnter() {
let message = ORIOSViewComponentEvent(screenName: screenName, viewName: viewName, visible: true)
let message = ORMobileViewComponentEvent(screenName: screenName, viewName: viewName, visible: true)
if Analytics.shared.enabled {
MessageCollector.shared.sendMessage(message)
}
Expand All @@ -99,7 +99,7 @@ extension UIViewController {
self.swizzledViewDidDisappear(animated)

if let (screenName, viewName) = isViewOrSubviewObservedEnter() {
let message = ORIOSViewComponentEvent(screenName: screenName, viewName: viewName, visible: false)
let message = ORMobileViewComponentEvent(screenName: screenName, viewName: viewName, visible: false)
if Analytics.shared.enabled {
MessageCollector.shared.sendMessage(message)
}
Expand Down Expand Up @@ -141,9 +141,9 @@ public class TouchTrackingWindow: UIWindow {
let description = getViewDescription(touch.view) ?? "UIView"
if isSwipe {
DebugUtils.log("Swipe from \(touchStart ?? CGPoint(x: 0, y: 0)) to \(location)")
event = ORIOSSwipeEvent(label: description, x: UInt64(location.x),y: UInt64(location.y), direction: detectSwipeDirection(from: touchStart!, to: location))
event = ORMobileSwipeEvent(label: description, x: UInt64(location.x),y: UInt64(location.y), direction: detectSwipeDirection(from: touchStart!, to: location))
} else {
event = ORIOSClickEvent(label: description, x: UInt64(location.x), y: UInt64(location.y))
event = ORMobileClickEvent(label: description, x: UInt64(location.x), y: UInt64(location.y))
DebugUtils.log("Touch from \(touchStart ?? CGPoint(x: 0, y: 0)) to \(location)")
}
touchStart = nil
Expand Down Expand Up @@ -223,7 +223,7 @@ public struct ObservedInputModifier: ViewModifier {
if masked ?? false {
sentValue = "****"
}
MessageCollector.shared.sendDebouncedMessage(ORIOSInputEvent(value: sentValue, valueMasked: masked ?? false, label: label ?? ""))
MessageCollector.shared.sendDebouncedMessage(ORMobileInputEvent(value: sentValue, valueMasked: masked ?? false, label: label ?? ""))
}
}

Expand All @@ -235,15 +235,15 @@ public struct ViewLifecycleModifier: ViewModifier {
content
.onAppear {
DebugUtils.log("<><><>view appear \(viewName)")
let message = ORIOSViewComponentEvent(screenName: screenName, viewName: viewName, visible: true)
let message = ORMobileViewComponentEvent(screenName: screenName, viewName: viewName, visible: true)
if Analytics.shared.enabled {
MessageCollector.shared.sendMessage(message)
}

}
.onDisappear {
DebugUtils.log("<><><>disappear view \(viewName)")
let message = ORIOSViewComponentEvent(screenName: screenName, viewName: viewName, visible: false)
let message = ORMobileViewComponentEvent(screenName: screenName, viewName: viewName, visible: false)
if Analytics.shared.enabled {
MessageCollector.shared.sendMessage(message)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenReplay/Listeners/Crash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Crashs: NSObject {
public func start() {
NSSetUncaughtExceptionHandler { (exception) in
DebugUtils.log("<><> captured crash \(exception)")
let message = ORIOSCrash(name: exception.name.rawValue,
let message = ORMobileCrash(name: exception.name.rawValue,
reason: exception.reason ?? "",
stacktrace: exception.callStackSymbols.joined(separator: "\n"))
let messageData = message.contentData()
Expand All @@ -41,7 +41,7 @@ public class Crashs: NSObject {
}

public func sendLateError(exception: NSException) {
let message = ORIOSCrash(name: exception.name.rawValue,
let message = ORMobileCrash(name: exception.name.rawValue,
reason: exception.reason ?? "",
stacktrace: exception.callStackSymbols.joined(separator: "\n")
)
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenReplay/Listeners/LogsListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LogsListener: NSObject {

let data = fileHandle.availableData
if let string = String(data: data, encoding: String.Encoding.utf8) {
let message = ORIOSLog(severity: severity, content: string)
let message = ORMobileLog(severity: severity, content: string)
MessageCollector.shared.sendMessage(message)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenReplay/Listeners/NetworkListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func convertDictionaryToJSONString(dictionary: [String: Any?]) -> String? {
}

public func sendNetworkMessage(url: String, method: String, requestJSON: String, responseJSON: String, status: Int, duration: UInt64) {
let message = ORIOSNetworkCall(
let message = ORMobileNetworkCall(
type: "request",
method: method,
URL: url,
Expand Down
30 changes: 15 additions & 15 deletions Sources/OpenReplay/Listeners/PerformanceListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ open class PerformanceListener: NSObject {
}
getCpuMessage()
getMemoryMessage()
MessageCollector.shared.sendMessage(ORIOSPerformanceEvent(name: "background", value: UInt64(0)))
MessageCollector.shared.sendMessage(ORMobilePerformanceEvent(name: "background", value: UInt64(0)))
}

@objc func pause() {
if (Openreplay.shared.options.debugLogs) {
DebugUtils.log("Background")
}
MessageCollector.shared.sendMessage(ORIOSPerformanceEvent(name: "background", value: UInt64(1)))
MessageCollector.shared.sendMessage(ORMobilePerformanceEvent(name: "background", value: UInt64(1)))
}

func getCpuMessage() {
if let cpu = self.cpuUsage() {
MessageCollector.shared.sendMessage(ORIOSPerformanceEvent(name: "mainThreadCPU", value: UInt64(cpu)))
MessageCollector.shared.sendMessage(ORMobilePerformanceEvent(name: "mainThreadCPU", value: UInt64(cpu)))
}
}

func getMemoryMessage() {
if let mem = self.memoryUsage() {
MessageCollector.shared.sendMessage(ORIOSPerformanceEvent(name: "memoryUsage", value: UInt64(mem)))
MessageCollector.shared.sendMessage(ORMobilePerformanceEvent(name: "memoryUsage", value: UInt64(mem)))
}
}

Expand Down Expand Up @@ -93,33 +93,33 @@ open class PerformanceListener: NSObject {
}

public func sendBattery() {
let message = ORIOSPerformanceEvent(name: "batteryLevel", value: 20)
let message = ORMobilePerformanceEvent(name: "batteryLevel", value: 20)

MessageCollector.shared.sendMessage(message)
}

public func sendThermal() {
let message2 = ORIOSPerformanceEvent(name: "thermalState", value: 2)
let message2 = ORMobilePerformanceEvent(name: "thermalState", value: 2)
MessageCollector.shared.sendMessage(message2)
}

@objc func notified(_ notification: Notification) {
var message: ORIOSPerformanceEvent? = nil
var message: ORMobilePerformanceEvent? = nil
switch notification.name {
case .NSBundleResourceRequestLowDiskSpace:
message = ORIOSPerformanceEvent(name: "lowDiskSpace", value: 0)
message = ORMobilePerformanceEvent(name: "lowDiskSpace", value: 0)
case .NSProcessInfoPowerStateDidChange:
message = ORIOSPerformanceEvent(name: "isLowPowerModeEnabled", value: ProcessInfo.processInfo.isLowPowerModeEnabled ? 1 : 0)
message = ORMobilePerformanceEvent(name: "isLowPowerModeEnabled", value: ProcessInfo.processInfo.isLowPowerModeEnabled ? 1 : 0)
case ProcessInfo.thermalStateDidChangeNotification:
message = ORIOSPerformanceEvent(name: "thermalState", value: UInt64(ProcessInfo.processInfo.thermalState.rawValue))
message = ORMobilePerformanceEvent(name: "thermalState", value: UInt64(ProcessInfo.processInfo.thermalState.rawValue))
case UIApplication.didReceiveMemoryWarningNotification:
message = ORIOSPerformanceEvent(name: "memoryWarning", value: 0)
message = ORMobilePerformanceEvent(name: "memoryWarning", value: 0)
case UIDevice.batteryLevelDidChangeNotification:
message = ORIOSPerformanceEvent(name: "batteryLevel", value: UInt64(max(0.0, UIDevice.current.batteryLevel)*100))
message = ORMobilePerformanceEvent(name: "batteryLevel", value: UInt64(max(0.0, UIDevice.current.batteryLevel)*100))
case UIDevice.batteryStateDidChangeNotification:
message = ORIOSPerformanceEvent(name: "batteryState", value: UInt64(UIDevice.current.batteryState.rawValue))
message = ORMobilePerformanceEvent(name: "batteryState", value: UInt64(UIDevice.current.batteryState.rawValue))
case UIDevice.orientationDidChangeNotification:
message = ORIOSPerformanceEvent(name: "orientation", value: UInt64(UIDevice.current.orientation.rawValue))
message = ORMobilePerformanceEvent(name: "orientation", value: UInt64(UIDevice.current.orientation.rawValue))
default: break
}
if let message = message {
Expand All @@ -128,7 +128,7 @@ open class PerformanceListener: NSObject {
}

func networkStateChange(_ state: UInt64) {
let message = ORIOSPerformanceEvent(name: "networkState", value: state)
let message = ORMobilePerformanceEvent(name: "networkState", value: state)
MessageCollector.shared.sendMessage(message)
}

Expand Down
34 changes: 17 additions & 17 deletions Sources/OpenReplay/Managers/ConditionsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ConditionsManager: NSObject {
let matchingConditions = mappedConditions.filter { $0.tp == messageType }
for activeCon in matchingConditions {
switch msg {
case let networkMsg as ORIOSNetworkCall:
case let networkMsg as ORMobileNetworkCall:
if let matchingNetworkConditions = activeCon.subConditions {
// we simply check that ALL conditions match
var networkConditionsMet = true
Expand All @@ -56,35 +56,35 @@ class ConditionsManager: NSObject {
} else {
continue
}
case let viewMsg as ORIOSViewComponentEvent:
case let viewMsg as ORMobileViewComponentEvent:
if (activeCon.op(viewMsg.viewName) || activeCon.op(viewMsg.screenName)) {
return activeCon.name
}
case let clickMsg as ORIOSClickEvent:
case let clickMsg as ORMobileClickEvent:
if activeCon.op(clickMsg.label) {
return activeCon.name
}
case let metaMsg as ORIOSMetadata:
case let metaMsg as ORMobileMetadata:
if (activeCon.op(metaMsg.value) || activeCon.op(metaMsg.key)) {
return activeCon.name
}
case let eventMsg as ORIOSEvent:
case let eventMsg as ORMobileEvent:
if (activeCon.op(eventMsg.payload) || activeCon.op(eventMsg.name)) {
return activeCon.name
}
case let logMsg as ORIOSLog:
case let logMsg as ORMobileLog:
if activeCon.op(logMsg.content) {
return activeCon.name
}
case let idMsg as ORIOSUserID:
case let idMsg as ORMobileUserID:
if activeCon.op(idMsg.iD) {
return activeCon.name
}
// thermalState (0:nominal 1:fair 2:serious 3:critical)
// batteryLevel (0..100)
// "mainThreadCPU": Possible values (0 .. 100)
// "memoryUsage": Used memory in bytes, so we divide by total
case let perfMsg as ORIOSPerformanceEvent:
case let perfMsg as ORMobilePerformanceEvent:
if perfMsg.name == "memoryUsage" {
if activeCon.op(String(perfMsg.value / UInt64(ProcessInfo.processInfo.physicalMemory))) {
return activeCon.name
Expand Down Expand Up @@ -157,7 +157,7 @@ class ConditionsManager: NSObject {
target: [],
op: { _ in true },
type: "network_message",
tp: ORMessageType.iOSNetworkCall,
tp: ORMessageType.mobileNetworkCall,
subConditions: networkConditions
)
conds.append(combinedCondition)
Expand Down Expand Up @@ -282,63 +282,63 @@ class OperatorsManager: NSObject {
target: cond.value,
op: { val in opFn(val, cond.value) },
type: cond.type,
tp: ORMessageType.iOSEvent
tp: ORMessageType.mobileEvent
)
case "metadata":
return Condition(
name: "metadata",
target: cond.value,
op: { val in opFn(val, cond.value) },
type: cond.type,
tp: ORMessageType.iOSMetadata
tp: ORMessageType.mobileMetadata
)
case "userId":
return Condition(
name: "user_id",
target: cond.value,
op: { val in opFn(val, cond.value) },
type: cond.type,
tp: ORMessageType.iOSUserID
tp: ORMessageType.mobileUserID
)
case "viewComponent":
return Condition(
name: "view_component",
target: cond.value,
op: { val in opFn(val, cond.value) },
type: cond.type,
tp: ORMessageType.iOSViewComponentEvent
tp: ORMessageType.mobileViewComponentEvent
)
case "clickEvent":
return Condition(
name: "click",
target: cond.value,
op: { val in opFn(val, cond.value) },
type: cond.type,
tp: ORMessageType.iOSClickEvent
tp: ORMessageType.mobileClickEvent
)
case "logEvent":
return Condition(
name: "log",
target: cond.value,
op: { val in opFn(val, cond.value) },
type: cond.type,
tp: ORMessageType.iOSLog
tp: ORMessageType.mobileLog
)
case "fetchUrl", "fetchStatusCode", "fetchMethod", "fetchDuration":
return Condition(
name: cond.type,
target: cond.value,
op: { val in opFn(val, cond.value) },
type: cond.type,
tp: ORMessageType.iOSNetworkCall
tp: ORMessageType.mobileNetworkCall
)
case "thermalState", "mainThreadCpu", "memoryUsage":
return Condition(
name: cond.type,
target: cond.value,
op: { val in opFn(val, cond.value) },
type: cond.type,
tp: ORMessageType.iOSPerformanceEvent
tp: ORMessageType.mobilePerformanceEvent
)
default:
return nil
Expand Down
Loading

0 comments on commit 3f59ba1

Please sign in to comment.