openreplay/frontend/app/player/web/messages/JSONRawMessageReader.ts
Andrey Babushkin fd5c0c9747
Add lokalisation (#3092)
* applied eslint

* add locales and lint the project

* removed error boundary

* updated locales

* fix min files

* fix locales
2025-03-06 17:43:15 +01:00

36 lines
1,003 B
TypeScript

import type { RawMessage } from './raw.gen';
import type { TrackerMessage } from './tracker.gen';
import translate from './tracker.gen';
import { TP_MAP } from './tracker-legacy.gen';
import rewriteMessage from './rewriter/rewriteMessage';
function legacyTranslate(msg: any): RawMessage | null {
const type = TP_MAP[msg._id as keyof typeof TP_MAP];
if (!type) {
// msg._id can be other than keyof TP_MAP, in fact
return null;
}
msg.tp = type;
delete msg._id;
return msg as RawMessage;
}
export default class JSONRawMessageReader {
constructor(private messages: TrackerMessage[] = []) {}
append(messages: TrackerMessage[]) {
this.messages = this.messages.concat(messages);
}
readMessage(): RawMessage | null {
const msg = this.messages.shift();
if (!msg) {
return null;
}
const rawMsg = Array.isArray(msg) ? translate(msg) : legacyTranslate(msg);
if (!rawMsg) {
return this.readMessage();
}
return rewriteMessage(rawMsg);
}
}