File tree 5 files changed +37
-17
lines changed
test/platform/swift/unit_integration
5 files changed +37
-17
lines changed Original file line number Diff line number Diff line change @@ -87,9 +87,10 @@ extension CoreLogger: CoreLogging {
87
87
)
88
88
}
89
89
90
- func logSessionReplayScreenshot( screen: SessionReplayCapture , duration: TimeInterval ) {
90
+ func logSessionReplayScreenshot( screen: SessionReplayCapture ? , duration: TimeInterval ) {
91
+ let fields = screen. flatMap { screen in self . convertFields ( fields: [ " screen_px " : screen] ) } ?? [ ]
91
92
self . underlyingLogger. logSessionReplayScreenshot (
92
- fields: self . convertFields ( fields: [ " screen " : screen ] ) ,
93
+ fields: fields,
93
94
duration: duration
94
95
)
95
96
}
Original file line number Diff line number Diff line change @@ -55,9 +55,9 @@ protocol CoreLogging: AnyObject {
55
55
56
56
/// Writes a session replay screen log.
57
57
///
58
- /// - parameter screen: The captured screenshot.
58
+ /// - parameter screen: The captured screenshot. `nil` if screenshot couldn't be taken.
59
59
/// - parameter duration: The duration of time the preparation of the log took.
60
- func logSessionReplayScreenshot( screen: SessionReplayCapture , duration: TimeInterval )
60
+ func logSessionReplayScreenshot( screen: SessionReplayCapture ? , duration: TimeInterval )
61
61
62
62
/// Writes a resource utilization log.
63
63
///
Original file line number Diff line number Diff line change 7
7
8
8
@_implementationOnly import CapturePassable
9
9
import Foundation
10
+ import UIKit
10
11
11
12
final class SessionReplayTarget {
12
13
private let queue = DispatchQueue . serial ( withLabelSuffix: " ReplayController " , target: . default)
@@ -41,14 +42,32 @@ extension SessionReplayTarget: CapturePassable.SessionReplayTarget {
41
42
}
42
43
43
44
func captureScreenshot( ) {
44
- // TODO: Implement
45
- // DispatchQueue.main.async { [weak self] in
46
- // self?.queue.async {
47
- // self?.logger?.logSessionReplayScreenshot(
48
- // screen: SessionReplayCapture(data: Data()),
49
- // duration: 0
50
- // )
51
- // }
52
- // }
45
+ DispatchQueue . main. async {
46
+ guard let window = UIApplication . shared. sessionReplayWindows ( ) . first else {
47
+ self . logger? . logSessionReplayScreenshot (
48
+ screen: nil ,
49
+ duration: 0
50
+ )
51
+ return
52
+ }
53
+
54
+ let layer = window. layer
55
+ let bounds = UIScreen . main. bounds. size
56
+
57
+ self . queue. async { [ weak self] in
58
+ let start = Uptime ( )
59
+ let format = UIGraphicsImageRendererFormat ( )
60
+ format. scale = 1.0
61
+
62
+ let renderer = UIGraphicsImageRenderer ( size: bounds, format: format)
63
+ let jpeg = renderer. jpegData ( withCompressionQuality: 0.1 ) { context in
64
+ layer. render ( in: context. cgContext)
65
+ }
66
+ self ? . logger? . logSessionReplayScreenshot (
67
+ screen: SessionReplayCapture ( data: jpeg) ,
68
+ duration: Uptime ( ) . timeIntervalSince ( start)
69
+ )
70
+ }
71
+ }
53
72
}
54
73
}
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ final class SessionReplayTargetTests: XCTestCase {
30
30
func testEmitsSessionReplayScreenLog( ) {
31
31
let expectation = self . expectation ( description: " screen log is emitted " )
32
32
33
- self . logger. logSessionReplayScreen = expectation
33
+ self . logger. logSessionReplayScreenExpectation = expectation
34
34
self . target. captureScreen ( )
35
35
36
36
XCTAssertEqual ( . completed, XCTWaiter ( ) . wait ( for: [ expectation] , timeout: 0.5 ) )
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ public final class MockCoreLogging {
44
44
public var logResourceUtilizationExpectation : XCTestExpectation ?
45
45
46
46
public private( set) var sessionReplayScreenLogs = [ SessionReplayScreenLog] ( )
47
- public var logSessionReplayScreen : XCTestExpectation ?
47
+ public var logSessionReplayScreenExpectation : XCTestExpectation ?
48
48
49
49
public var shouldLogAppUpdateEvent = false
50
50
@@ -115,10 +115,10 @@ extension MockCoreLogging: CoreLogging {
115
115
self . sessionReplayScreenLogs. append ( SessionReplayScreenLog (
116
116
screen: screen, duration: duration)
117
117
)
118
- self . logSessionReplayScreen ? . fulfill ( )
118
+ self . logSessionReplayScreenExpectation ? . fulfill ( )
119
119
}
120
120
121
- public func logSessionReplayScreenshot( screen _: SessionReplayCapture , duration _: TimeInterval ) { }
121
+ public func logSessionReplayScreenshot( screen _: SessionReplayCapture ? , duration _: TimeInterval ) { }
122
122
123
123
public func logResourceUtilization( fields: Fields , duration: TimeInterval ) {
124
124
self . resourceUtilizationLogs. append ( ResourceUtilizationLog ( fields: fields, duration: duration) )
You can’t perform that action at this time.
0 commit comments