<commit_before>import STORE from "store";
import RENDERER from "renderer";

export default class OfflinePlaybackWebSocketEndpoint {
    constructor(serverAddr) {
        this.serverAddr = serverAddr;
        this.websocket = null;
        this.lastUpdateTimestamp = 0;
        this.lastSeqNum = -1;
        this.requestTimer = null;
        this.processTimer = null;
        this.frameData = {}; // cache frames
    }

    initialize(params) {
        if (params && params.id && params.map) {
            STORE.playback.setJobId(params.id);
            STORE.playback.setMapId(params.map);
        } else {
            console.error("ERROR: missing required parameter(s)");
            return;
        }

        if (params.url) {
            this.serverUrl = `${location.protocol}//${params.url}`;
        }

        try {
            this.websocket = new WebSocket(this.serverAddr);
        } catch (error) {
            console.error("Failed to establish a connection: " + error);
            setTimeout(() => {
                this.initialize(params);
            }, 1000);
            return;
        }
        this.websocket.onopen = event => {
            this.requestGroundMeta(STORE.playback.mapId);
        };
        this.websocket.onmessage = event => {
            const message = JSON.parse(event.data);

            switch (message.type) {
                case "GroundMetadata":
                    RENDERER.updateGroundMetadata(this.serverUrl, message.data);
                    this.requstFrameCount(STORE.playback.jobId);
                    break;
                case "FrameCount":
                    STORE.playback.setNumFrames(message.data);
                    this.requestSimulationWorld(STORE.playback.jobId, STORE.playback.next());
                    break;
                case "SimWorldUpdate":
                    this.checkMessage(message);
                    STORE.setInitializationStatus(true);

                    const world = (typeof message.world) === "string"
                        ? JSON.parse(message.world): message.world;
                    if (STORE.playback.isSeeking) {
                        this.processSimWorld(world);
                    }

                    if (world.sequenceNum && !(world.sequenceNum in this.frameData)) {
                        this.frameData[world.sequenceNum] = world;
                    }
<commit_msg>Offlineview: adding frame range check after receiving frame count (#3868)<commit_after>import STORE from "store";
import RENDERER from "renderer";

export default class OfflinePlaybackWebSocketEndpoint {
    constructor(serverAddr) {
        this.serverAddr = serverAddr;
        this.websocket = null;
        this.lastUpdateTimestamp = 0;
        this.lastSeqNum = -1;
        this.requestTimer = null;
        this.processTimer = null;
        this.frameData = {}; // cache frames
    }

    initialize(params) {
        if (params && params.id && params.map) {
            STORE.playback.setJobId(params.id);
            STORE.playback.setMapId(params.map);
        } else {
            console.error("ERROR: missing required parameter(s)");
            return;
        }

        if (params.url) {
            this.serverUrl = `${location.protocol}//${params.url}`;
        }

        try {
            this.websocket = new WebSocket(this.serverAddr);
        } catch (error) {
            console.error("Failed to establish a connection: " + error);
            setTimeout(() => {
                this.initialize(params);
            }, 1000);
            return;
        }
        this.websocket.onopen = event => {
            this.requestGroundMeta(STORE.playback.mapId);
        };
        this.websocket.onmessage = event => {
            const message = JSON.parse(event.data);

            switch (message.type) {
                case "GroundMetadata":
                    RENDERER.updateGroundMetadata(this.serverUrl, message.data);
                    this.requstFrameCount(STORE.playback.jobId);
                    break;
                case "FrameCount":
                    STORE.playback.setNumFrames(message.data);
                    if (STORE.playback.hasNext()) {
                        this.requestSimulationWorld(STORE.playback.jobId, STORE.playback.next());
                    }
                    break;
                case "SimWorldUpdate":
                    this.checkMessage(message);
                    STORE.setInitializationStatus(true);

                    const world = (typeof message.world) === "string"
                        ? JSON.parse(message.world): message.world;
                    if (STORE.playback.isSeeking) {
                        this.processSimWorld(world);
                    }

                    if (world.sequenceNum && !(world.sequenceNum in this.frameData)) {
                        this.frameData[world.sequenceNum] = world;
                    }

{'fraction_non_alphanumeric': 0.10676446617766912, 'fraction_numerical': 0.0032599837000814994, 'mean_word_length': 1.5408902691511388, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2892896', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1241, 'n_words': 219}