<commit_before>/*
///////////////////////
// WEBSOCKET SERVICE //
///////////////////////
*/

// TODO: these could be moved to config file.
const wsEndpoint = 'crisis';
const scheme = window.location.protocol === 'https:' ? 'wss' : 'ws';
const url = `${window.location.host}/${wsEndpoint}`;
const ws = new WebSocket(`${scheme}://${url}`);


export const connect = (store) => {
  console.debug('[WEBSOCKET] ====> connect');
  ws.onmessage = ({ data }) => store.dispatch(data);
};

export const send = (data) => {
  console.debug('[WEBSOCKET] ====> sending', data);
  ws.send(JSON.stringify(data));
};

export const close = () => ws.close();<commit_msg>Updated client-side websocket implementation<commit_after>/*
///////////////////////
// WEBSOCKET SERVICE //
///////////////////////
*/

// TODO: these could be moved to config file.
const wsPort = 8000;
const wsEndpoint = 'cms';
const scheme = window.location.protocol === 'https:' ? 'wss' : 'ws';
const url = `localhost:${wsPort}/${wsEndpoint}`;
const ws = new WebSocket(`${scheme}://${url}`);


export const connect = (store) => {
  console.debug('[WEBSOCKET] ====> connect');
  ws.onmessage = ({ data }) => {
    console.debug('[WEBSOCKET] ====> receive', data);
    try {
      const json = JSON.parse(data);
      if (data.type && data.payload) store.dispatch(data);
      else console.error('Websocket data in wrong format!', json);
    } catch (e) {
      console.error(e);
    }
  };
};

export const send = (data) => {
  console.debug('[WEBSOCKET] ====> sending', data);
  ws.send(JSON.stringify(data));
};

export const close = () => ws.close();
{'fraction_non_alphanumeric': 0.253889234598631, 'fraction_numerical': 0.002489110143123833, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '3801323', 'n_tokens_mistral': 519, 'n_tokens_neox': 511, 'n_words': 121}