-
Notifications
You must be signed in to change notification settings - Fork 0
fix: touch throttle #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
d19b225
ea7c82a
fb73ef4
59244e7
830c0e0
ee313e0
0cc123d
7c767b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| import UIKit | ||
|
|
||
| private enum TouchConstants { | ||
| static let tapMaxDistance = 12.0 | ||
| static let tapMaxDistance = 4.0 | ||
| static let tapMaxDistanceSquared: CGFloat = tapMaxDistance * tapMaxDistance | ||
| static let touchMoveMaxDuration: TimeInterval = 0.11 | ||
| static let touchMoveThrottle: TimeInterval = 0.05 // From RRWeb code | ||
| static let touchPathDuration: TimeInterval = 0.18 // found through testing | ||
| } | ||
|
|
||
| final class TouchIntepreter { | ||
|
|
@@ -47,26 +48,41 @@ final class TouchIntepreter { | |
| track.end = touchSample.timestamp | ||
| track.target = touchSample.target | ||
|
|
||
| let trackDuration = track.end - track.start | ||
| guard trackDuration <= TouchConstants.touchPathDuration else { | ||
| // flush movements of long touch path do not have dead time in the replay player | ||
| let lastPoint = TouchPoint(position: touchSample.location, timestamp: touchSample.timestamp + uptimeDifference) | ||
| track.points.append(lastPoint) | ||
|
|
||
| let moveInteraction = TouchInteraction(id: incrementingId, | ||
| kind: .touchPath(points: track.points), | ||
| startTimestamp: track.start + uptimeDifference, | ||
| timestamp: touchSample.timestamp + uptimeDifference, | ||
| target: touchSample.target) | ||
| track.points.removeAll() | ||
| track.start = lastPoint.timestamp - uptimeDifference | ||
| track.startPoint = touchSample.location | ||
| tracks[touchSample.id] = track | ||
| yield(moveInteraction) | ||
| return | ||
| } | ||
|
|
||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let previousTimestamp = (track.points.last?.timestamp ?? track.start) | ||
| let duration = touchSample.timestamp + uptimeDifference - previousTimestamp | ||
| guard duration >= TouchConstants.touchMoveMaxDuration else { | ||
| guard duration >= TouchConstants.touchMoveThrottle else { | ||
| return | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Inconsistent Throttle Timing Post-FlushAfter flushing touch points when track duration exceeds
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want that more frequently |
||
|
|
||
abelonogov-ld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let distance = squaredDistance(from: track.startPoint, to: touchSample.location) | ||
| guard distance >= TouchConstants.tapMaxDistanceSquared else { | ||
| return | ||
| if let lastPoint = tracks[touchSample.id]?.points.last { | ||
| let distance = squaredDistance(from: lastPoint.position, to: touchSample.location) | ||
| guard distance >= TouchConstants.tapMaxDistanceSquared else { | ||
| return | ||
| } | ||
| } | ||
|
|
||
| track.points.append(TouchPoint(position: touchSample.location, timestamp: touchSample.timestamp + uptimeDifference)) | ||
| tracks[touchSample.id] = track | ||
|
|
||
| let trackDuration = track.end - track.start | ||
| if trackDuration > 0.9 { | ||
| // flush movements of long touch path do not have dead time in the replay player | ||
| flushMovements(touchSample: touchSample, uptimeDifference: uptimeDifference, startTimestamp: track.start, yield: yield) | ||
| } | ||
|
|
||
| case .ended, .cancelled: | ||
| // touchUp | ||
| let startTimestamp = tracks[touchSample.id]?.start ?? touchSample.timestamp | ||
|
|
@@ -97,13 +113,13 @@ final class TouchIntepreter { | |
| startTimestamp: startTimestamp + uptimeDifference, | ||
| timestamp: touchSample.timestamp + uptimeDifference, | ||
| target: touchSample.target) | ||
| track.points.removeAll() | ||
| tracks[touchSample.id] = track | ||
| yield(moveInteraction) | ||
| } | ||
|
|
||
| func flushTrack(touchSample: TouchSample, uptimeDifference: TimeInterval, yield: TouchInteractionYield) { | ||
|
|
||
| if let lastPoint = track.points.last { | ||
| print("touchPath.points: \(track.points.count)", touchSample.id) | ||
cursor[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| track.points.removeAll() | ||
| track.start = lastPoint.timestamp - uptimeDifference | ||
| tracks[touchSample.id] = track | ||
| yield(moveInteraction) | ||
| } | ||
| } | ||
|
|
||
| func squaredDistance(from: CGPoint, to: CGPoint) -> CGFloat { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.