fix(tracker):3.5.9:fixed webwoeker refactoring
This commit is contained in:
parent
9a35dcbc3e
commit
77e7ad4edb
4 changed files with 24 additions and 16 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@openreplay/tracker",
|
||||
"description": "The OpenReplay tracker main package",
|
||||
"version": "3.5.7",
|
||||
"version": "3.5.9",
|
||||
"keywords": [
|
||||
"logging",
|
||||
"replay"
|
||||
|
|
|
|||
|
|
@ -83,10 +83,6 @@ function _getTarget(target: Element): Element | null {
|
|||
}
|
||||
|
||||
export default function (app: App): void {
|
||||
// const options: Options = Object.assign(
|
||||
// {},
|
||||
// opts,
|
||||
// );
|
||||
|
||||
function getTargetLabel(target: Element): string {
|
||||
const dl = getLabelAttribute(target);
|
||||
|
|
|
|||
|
|
@ -28,9 +28,10 @@ export default class BatchWriter {
|
|||
this.beaconSizeLimit = limit
|
||||
}
|
||||
|
||||
// TODO: clear workflow
|
||||
writeMessage(message: Message) {
|
||||
if (message instanceof Timestamp) {
|
||||
this.timestamp = (<any>message).timestamp;
|
||||
this.timestamp = (<any>message).timestamp
|
||||
}
|
||||
|
||||
if (!message.encode(this.writer)) {
|
||||
|
|
@ -58,10 +59,11 @@ export default class BatchWriter {
|
|||
this.isEmpty = false
|
||||
}
|
||||
|
||||
flush(): Uint8Array | null {
|
||||
if (this.isEmpty) { return null }
|
||||
finaliseBatch() {
|
||||
if (this.isEmpty) { return }
|
||||
this.onBatch(this.writer.flush())
|
||||
this.prepareBatchMeta()
|
||||
this.isEmpty = true
|
||||
return this.writer.flush()
|
||||
}
|
||||
|
||||
clean() {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import Message from "../messages/message.js";
|
|||
import {
|
||||
classes,
|
||||
SetPageVisibility,
|
||||
MouseMove,
|
||||
} from "../messages/index.js";
|
||||
import QueueSender from "./QueueSender.js";
|
||||
import BatchWriter from "./BatchWriter.js";
|
||||
|
|
@ -15,11 +16,10 @@ let sender: QueueSender | null = null
|
|||
let writer: BatchWriter | null = null
|
||||
|
||||
function send(): void {
|
||||
if (!sender || !writer) {
|
||||
if (!writer) {
|
||||
return
|
||||
}
|
||||
const batch = writer.flush()
|
||||
batch && sender.push(batch)
|
||||
writer.finaliseBatch()
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -58,6 +58,10 @@ self.onmessage = ({ data }: MessageEvent<WorkerMessageData>) => {
|
|||
}
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
if (!writer) {
|
||||
throw new Error("WebWorker: writer not initialised.")
|
||||
}
|
||||
const w = writer
|
||||
// Message[]
|
||||
data.forEach((data) => {
|
||||
const message: Message = new (<any>classes.get(data._id))();
|
||||
|
|
@ -68,8 +72,8 @@ self.onmessage = ({ data }: MessageEvent<WorkerMessageData>) => {
|
|||
} else {
|
||||
clearTimeout(restartTimeoutID)
|
||||
}
|
||||
}
|
||||
writer && writer.writeMessage(message)
|
||||
}
|
||||
w.writeMessage(message)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
|
@ -100,8 +104,14 @@ self.onmessage = ({ data }: MessageEvent<WorkerMessageData>) => {
|
|||
}
|
||||
|
||||
if (data.type === "auth") {
|
||||
sender && sender.authorise(data.token)
|
||||
data.beaconSizeLimit && writer && writer.setBeaconSizeLimit(data.beaconSizeLimit)
|
||||
if (!sender) {
|
||||
throw new Error("WebWorker: sender not initialised. Recieved auth.")
|
||||
}
|
||||
if (!writer) {
|
||||
throw new Error("WebWorker: writer not initialised. Recieved auth.")
|
||||
}
|
||||
sender.authorise(data.token)
|
||||
data.beaconSizeLimit && writer.setBeaconSizeLimit(data.beaconSizeLimit)
|
||||
return
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue