Skip to content
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

Pointer type fixups #1201

Merged
merged 7 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/fair-dragons-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
18 changes: 9 additions & 9 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,19 @@ function initMouseInteractionObserver({
: sampling.mouseInteraction;

const handlers: listenerHandler[] = [];
let currentPointerType = null;
let currentPointerType: PointerTypes | null = null;
const getHandler = (eventKey: keyof typeof MouseInteractions) => {
return (event: MouseEvent | TouchEvent | PointerEvent) => {
const target = getEventTarget(event) as Node;
if (isBlocked(target, blockClass, blockSelector, true)) {
return;
}
let pointerType: PointerTypes | null = null;
let e = event;
if ('pointerType' in e) {
let thisEventKey = eventKey;
if ('pointerType' in event) {
Object.keys(PointerTypes).forEach(
(pointerKey: keyof typeof PointerKeys) => {
if ((e as PointerEvent).pointerType === pointerKey.toLowerCase()) {
(pointerKey: keyof typeof PointerTypes) => {
if (event.pointerType === pointerKey.toLowerCase()) {
pointerType = PointerTypes[pointerKey];
return;
}
Expand All @@ -251,18 +251,17 @@ function initMouseInteractionObserver({
if (pointerType === PointerTypes.Touch) {
if (MouseInteractions[eventKey] === MouseInteractions.MouseDown) {
// we are actually listening on 'pointerdown'
eventKey = 'TouchStart';
thisEventKey = 'TouchStart';
} else if (
MouseInteractions[eventKey] === MouseInteractions.MouseUp
) {
// we are actually listening on 'pointerup'
eventKey = 'TouchEnd';
thisEventKey = 'TouchEnd';
}
} else if (pointerType == PointerTypes.Pen) {
// TODO: these will get incorrectly emitted as MouseDown/MouseUp
}
} else if (legacy_isTouchEvent(event)) {
e = event.changedTouches[0];
pointerType = PointerTypes.Touch;
}
if (pointerType !== null) {
Expand All @@ -271,13 +270,14 @@ function initMouseInteractionObserver({
pointerType = currentPointerType;
currentPointerType = null; // cleanup as we've used it
}
const e = legacy_isTouchEvent(event) ? event.changedTouches[0] : event;
if (!e) {
return;
}
const id = mirror.getId(target);
const { clientX, clientY } = e;
callbackWrapper(mouseInteractionCb)({
type: MouseInteractions[eventKey],
type: MouseInteractions[thisEventKey],
id,
x: clientX,
y: clientY,
Expand Down
Loading