diff --git a/Sources/Observability/UIInteractions/ObservabilityEvents.swift b/Sources/Observability/UIInteractions/ObservabilityEvents.swift index 688d4f2d..00464276 100644 --- a/Sources/Observability/UIInteractions/ObservabilityEvents.swift +++ b/Sources/Observability/UIInteractions/ObservabilityEvents.swift @@ -1,7 +1,7 @@ import Foundation import Common -extension UIInteraction: EventQueueItemPayload { +extension TouchInteraction: EventQueueItemPayload { public func cost() -> Int { 300 } diff --git a/Sources/Observability/UIInteractions/TouchCaptureCoordinator.swift b/Sources/Observability/UIInteractions/TouchCaptureCoordinator.swift index f885cab2..89b0bb2e 100644 --- a/Sources/Observability/UIInteractions/TouchCaptureCoordinator.swift +++ b/Sources/Observability/UIInteractions/TouchCaptureCoordinator.swift @@ -31,7 +31,7 @@ public struct TouchSample: Sendable { } } -typealias UIInteractionYield = @Sendable (UIInteraction) -> Void +typealias UIInteractionYield = @Sendable (TouchInteraction) -> Void final class TouchCaptureCoordinator { private let source: UIEventSource diff --git a/Sources/Observability/UIInteractions/TouchIntepreter.swift b/Sources/Observability/UIInteractions/TouchIntepreter.swift index 87abc992..64ebb69c 100644 --- a/Sources/Observability/UIInteractions/TouchIntepreter.swift +++ b/Sources/Observability/UIInteractions/TouchIntepreter.swift @@ -35,7 +35,7 @@ final class TouchIntepreter { target: touchSample.target) tracks[touchSample.id] = track - let downInteraction = UIInteraction(id: incrementingId, + let downInteraction = TouchInteraction(id: incrementingId, kind: .touchDown(touchSample.location), timestamp: touchSample.timestamp + uptimeDifference, target: touchSample.target) @@ -67,7 +67,7 @@ final class TouchIntepreter { } case .ended, .cancelled: - let upInteraction = UIInteraction(id: incrementingId, + let upInteraction = TouchInteraction(id: incrementingId, kind: .touchUp(touchSample.location), timestamp: touchSample.timestamp + uptimeDifference, target: touchSample.target) @@ -80,7 +80,7 @@ final class TouchIntepreter { func flushMovements(touchSample: TouchSample, uptimeDifference: TimeInterval, yield: UIInteractionYield) { guard var track = tracks[touchSample.id], track.points.isNotEmpty else { return } - let moveInteraction = UIInteraction(id: incrementingId, + let moveInteraction = TouchInteraction(id: incrementingId, kind: .touchPath(points: track.points), timestamp: touchSample.timestamp + uptimeDifference, target: touchSample.target) @@ -92,7 +92,7 @@ final class TouchIntepreter { func flushTrack(touchSample: TouchSample, uptimeDifference: TimeInterval, yield: UIInteractionYield) { guard let track = tracks.removeValue(forKey: touchSample.id), track.points.isNotEmpty else { return } - let moveInteraction = UIInteraction(id: incrementingId, + let moveInteraction = TouchInteraction(id: incrementingId, kind: .touchPath(points: track.points), timestamp: touchSample.timestamp + uptimeDifference, target: touchSample.target) diff --git a/Sources/Observability/UIInteractions/UIInteraction.swift b/Sources/Observability/UIInteractions/TouchInteraction.swift similarity index 84% rename from Sources/Observability/UIInteractions/UIInteraction.swift rename to Sources/Observability/UIInteractions/TouchInteraction.swift index a0253fdf..7260191c 100644 --- a/Sources/Observability/UIInteractions/UIInteraction.swift +++ b/Sources/Observability/UIInteractions/TouchInteraction.swift @@ -6,7 +6,7 @@ public struct TouchPoint: Sendable { public let timestamp: TimeInterval } -public enum UIInteractionKind: Sendable { +public enum TouchKind: Sendable { case touchDown(CGPoint) case touchUp(CGPoint) case swipe(from: CGPoint, to: CGPoint, swipeDirection: SwipeDirection) @@ -20,9 +20,9 @@ public enum UIInteractionKind: Sendable { } } -public struct UIInteraction: Sendable { +public struct TouchInteraction: Sendable { public let id: Int - public let kind: UIInteractionKind + public let kind: TouchKind public let timestamp: TimeInterval public let target: TouchTarget? } diff --git a/Sources/Observability/UIInteractions/UIEventSource.swift b/Sources/Observability/UIInteractions/UIEventSource.swift index 25ffcd64..cf157325 100644 --- a/Sources/Observability/UIInteractions/UIEventSource.swift +++ b/Sources/Observability/UIInteractions/UIEventSource.swift @@ -6,5 +6,5 @@ public protocol UIEventSource: AnyObject { } public protocol UIEventBus: Sendable { - func publish(_ event: UIInteraction) + func publish(_ event: TouchInteraction) } diff --git a/Sources/Observability/UIInteractions/UInteraction+Span.swift b/Sources/Observability/UIInteractions/UInteraction+Span.swift index 716cb3bf..95cb3f9d 100644 --- a/Sources/Observability/UIInteractions/UInteraction+Span.swift +++ b/Sources/Observability/UIInteractions/UInteraction+Span.swift @@ -5,7 +5,7 @@ struct UIInteractionSpan { let name: String } -extension UIInteraction { +extension TouchInteraction { func span() -> UIInteractionSpan? { guard kind.isTapLike else { return nil } diff --git a/Sources/SessionReplay/Exporter/SessionReplayEventGenerator.swift b/Sources/SessionReplay/Exporter/SessionReplayEventGenerator.swift index 7cc931bb..ccd63463 100644 --- a/Sources/SessionReplay/Exporter/SessionReplayEventGenerator.swift +++ b/Sources/SessionReplay/Exporter/SessionReplayEventGenerator.swift @@ -1,4 +1,7 @@ import Foundation +#if canImport(UIKit) +import UIKit +#endif import Common import Observability @@ -62,14 +65,14 @@ actor SessionReplayEventGenerator { appendFullSnapshotEvents(exportImage, timestamp, &events) } - case let interaction as UIInteraction: + case let interaction as TouchInteraction: appendTouchInteraction(interaction: interaction, events: &events) default: () // } } - fileprivate func appendTouchInteraction(interaction: UIInteraction, events: inout [Event]) { + fileprivate func appendTouchInteraction(interaction: TouchInteraction, events: inout [Event]) { if let touchEventData: EventDataProtocol = switch interaction.kind { case .touchDown(let point): EventData(source: .mouseInteraction, @@ -109,7 +112,7 @@ actor SessionReplayEventGenerator { } } - func clickEvent(interaction: UIInteraction) -> Event? { + func clickEvent(interaction: TouchInteraction) -> Event? { guard case .touchDown = interaction.kind else { return nil } let viewName = interaction.target?.className @@ -145,13 +148,18 @@ actor SessionReplayEventGenerator { } func viewPortEvent(exportImage: ExportImage, timestamp: TimeInterval) -> Event { + #if os(iOS) + let currentOrientation = UIDevice.current.orientation.isLandscape ? 1 : 0 + #else + let currentOrientation = 0 + #endif let payload = ViewportPayload(width: exportImage.originalWidth, height: exportImage.originalHeight, availWidth: exportImage.originalWidth, availHeight: exportImage.originalHeight, colorDepth: 30, pixelDepth: 30, - orientation: Int.random(in: 0...1)) + orientation: currentOrientation) let eventData = CustomEventData(tag: .viewport, payload: payload) let event = Event(type: .Custom, data: AnyEventData(eventData),