MCPcopy
hub / github.com/rrweb-io/rrweb / initMoveObserver

Function initMoveObserver

packages/rrweb/src/record/observer.ts:106–190  ·  view source on GitHub ↗
({
  mousemoveCb,
  sampling,
  doc,
  mirror,
}: observerParam)

Source from the content-addressed store, hash-verified

104}
105
106function initMoveObserver({
107 mousemoveCb,
108 sampling,
109 doc,
110 mirror,
111}: observerParam): listenerHandler {
112 if (sampling.mousemove === false) {
113 return () => {
114 //
115 };
116 }
117
118 const threshold =
119 typeof sampling.mousemove === 'number' ? sampling.mousemove : 50;
120 const callbackThreshold =
121 typeof sampling.mousemoveCallback === 'number'
122 ? sampling.mousemoveCallback
123 : 500;
124
125 let positions: mousePosition[] = [];
126 let timeBaseline: number | null;
127 const wrappedCb = throttle(
128 callbackWrapper(
129 (
130 source:
131 | IncrementalSource.MouseMove
132 | IncrementalSource.TouchMove
133 | IncrementalSource.Drag,
134 ) => {
135 const totalOffset = Date.now() - timeBaseline!;
136 mousemoveCb(
137 positions.map((p) => {
138 p.timeOffset -= totalOffset;
139 return p;
140 }),
141 source,
142 );
143 positions = [];
144 timeBaseline = null;
145 },
146 ),
147 callbackThreshold,
148 );
149 const updatePosition = callbackWrapper(
150 throttle<MouseEvent | TouchEvent | DragEvent>(
151 callbackWrapper((evt) => {
152 const target = getEventTarget(evt);
153 // 'legacy' here as we could switch to https://developer.mozilla.org/en-US/docs/Web/API/Element/pointermove_event
154 const { clientX, clientY } = legacy_isTouchEvent(evt)
155 ? evt.changedTouches[0]
156 : evt;
157 if (!timeBaseline) {
158 timeBaseline = nowTimestamp();
159 }
160 positions.push({
161 x: clientX,
162 y: clientY,
163 id: mirror.getId(target as Node),

Callers 1

initObserversFunction · 0.85

Calls 6

throttleFunction · 0.90
callbackWrapperFunction · 0.90
legacy_isTouchEventFunction · 0.90
onFunction · 0.90
getEventTargetFunction · 0.85
getIdMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…