fix #565 add departed warning
This commit is contained in:
@@ -318,6 +318,10 @@ export class Replayer {
|
|||||||
return baselineTime - events[0].timestamp;
|
return baselineTime - events[0].timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getMirror(): Mirror {
|
||||||
|
return this.mirror;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This API was designed to be used as play at any time offset.
|
* This API was designed to be used as play at any time offset.
|
||||||
* Since we minimized the data collected from recorder, we do not
|
* Since we minimized the data collected from recorder, we do not
|
||||||
|
|||||||
37
src/utils.ts
37
src/utils.ts
@@ -34,7 +34,7 @@ export function on(
|
|||||||
return () => target.removeEventListener(type, fn, options);
|
return () => target.removeEventListener(type, fn, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createMirror (): Mirror {
|
export function createMirror(): Mirror {
|
||||||
return {
|
return {
|
||||||
map: {},
|
map: {},
|
||||||
getId(n) {
|
getId(n) {
|
||||||
@@ -66,7 +66,40 @@ export function createMirror (): Mirror {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mirror: Mirror = createMirror();
|
// https://github.com/rrweb-io/rrweb/pull/407
|
||||||
|
const DEPARTED_MIRROR_ACCESS_WARNING =
|
||||||
|
'Please stop import mirror directly. Instead of that, now you can use replayer.getMirror() to access the mirror instance of a replayer.';
|
||||||
|
export let mirror: Mirror = {
|
||||||
|
map: {},
|
||||||
|
getId() {
|
||||||
|
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
|
getNode() {
|
||||||
|
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
removeNodeFromMap() {
|
||||||
|
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
||||||
|
},
|
||||||
|
has() {
|
||||||
|
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
reset() {
|
||||||
|
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if (window.Proxy && window.Reflect) {
|
||||||
|
mirror = new Proxy(mirror, {
|
||||||
|
get(target, prop, receiver) {
|
||||||
|
if (prop === 'map') {
|
||||||
|
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
|
||||||
|
}
|
||||||
|
return Reflect.get(target, prop, receiver);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// copy from underscore and modified
|
// copy from underscore and modified
|
||||||
export function throttle<T>(
|
export function throttle<T>(
|
||||||
|
|||||||
4
typings/replay/index.d.ts
vendored
4
typings/replay/index.d.ts
vendored
@@ -1,6 +1,6 @@
|
|||||||
import { Timer } from './timer';
|
import { Timer } from './timer';
|
||||||
import { createPlayerService, createSpeedService } from './machine';
|
import { createPlayerService, createSpeedService } from './machine';
|
||||||
import { eventWithTime, playerConfig, playerMetaData, Handler } from '../types';
|
import { eventWithTime, playerConfig, playerMetaData, Handler, Mirror } from '../types';
|
||||||
import './styles/style.css';
|
import './styles/style.css';
|
||||||
export declare class Replayer {
|
export declare class Replayer {
|
||||||
wrapper: HTMLDivElement;
|
wrapper: HTMLDivElement;
|
||||||
@@ -19,6 +19,7 @@ export declare class Replayer {
|
|||||||
private fragmentParentMap;
|
private fragmentParentMap;
|
||||||
private elementStateMap;
|
private elementStateMap;
|
||||||
private imageMap;
|
private imageMap;
|
||||||
|
private mirror;
|
||||||
private firstPlayedEvent;
|
private firstPlayedEvent;
|
||||||
private newDocumentQueue;
|
private newDocumentQueue;
|
||||||
constructor(events: Array<eventWithTime | string>, config?: Partial<playerConfig>);
|
constructor(events: Array<eventWithTime | string>, config?: Partial<playerConfig>);
|
||||||
@@ -27,6 +28,7 @@ export declare class Replayer {
|
|||||||
getMetaData(): playerMetaData;
|
getMetaData(): playerMetaData;
|
||||||
getCurrentTime(): number;
|
getCurrentTime(): number;
|
||||||
getTimeOffset(): number;
|
getTimeOffset(): number;
|
||||||
|
getMirror(): Mirror;
|
||||||
play(timeOffset?: number): void;
|
play(timeOffset?: number): void;
|
||||||
pause(timeOffset?: number): void;
|
pause(timeOffset?: number): void;
|
||||||
resume(timeOffset?: number): void;
|
resume(timeOffset?: number): void;
|
||||||
|
|||||||
3
typings/utils.d.ts
vendored
3
typings/utils.d.ts
vendored
@@ -1,7 +1,8 @@
|
|||||||
import { Mirror, throttleOptions, listenerHandler, hookResetter, blockClass, eventWithTime, addedNodeMutation, removedNodeMutation, textMutation, attributeMutation, mutationData, scrollData, inputData, DocumentDimension } from './types';
|
import { Mirror, throttleOptions, listenerHandler, hookResetter, blockClass, eventWithTime, addedNodeMutation, removedNodeMutation, textMutation, attributeMutation, mutationData, scrollData, inputData, DocumentDimension } from './types';
|
||||||
import { INode, serializedNodeWithId } from 'rrweb-snapshot';
|
import { INode, serializedNodeWithId } from 'rrweb-snapshot';
|
||||||
export declare function on(type: string, fn: EventListenerOrEventListenerObject, target?: Document | Window): listenerHandler;
|
export declare function on(type: string, fn: EventListenerOrEventListenerObject, target?: Document | Window): listenerHandler;
|
||||||
export declare const mirror: Mirror;
|
export declare function createMirror(): Mirror;
|
||||||
|
export declare let mirror: Mirror;
|
||||||
export declare function throttle<T>(func: (arg: T) => void, wait: number, options?: throttleOptions): (arg: T) => void;
|
export declare function throttle<T>(func: (arg: T) => void, wait: number, options?: throttleOptions): (arg: T) => void;
|
||||||
export declare function hookSetter<T>(target: T, key: string | number | symbol, d: PropertyDescriptor, isRevoked?: boolean, win?: Window & typeof globalThis): hookResetter;
|
export declare function hookSetter<T>(target: T, key: string | number | symbol, d: PropertyDescriptor, isRevoked?: boolean, win?: Window & typeof globalThis): hookResetter;
|
||||||
export declare function patch(source: {
|
export declare function patch(source: {
|
||||||
|
|||||||
Reference in New Issue
Block a user