<commit_before>
// this is not compiled by babel / webpack

var http = require('http');
var ws = require('ws');
var serveBackend = require('./node/serveBackend.js');

var server = http.createServer(function (req, res) {
  // console.log('req'+ req.url);
  if (req.url === '/backend') {
    return serveBackend(res);
  } else if (req.url === '/websocket') {
    return; // handled by wss
  }
  res.writeHead(404);
  res.end('Not found');
}).listen(8097, '::');

var wss = new ws.Server({
  server: server,
  path: '/websocket',
});

wss.on('connection', function (ws) {
  var listeners;
  ws.onerror = function (err) {
    window.onDisconnected();
    console.log('error connection', err);
  };
  ws.onclose = function () {
    window.onDisconnected();
    console.log('error things');
  };
  ws.onmessage = function (evt) {
    // console.log('<<--', evt.data);
    var data = JSON.parse(evt.data);
    listeners.forEach(function (fn) {fn(data)});
  };
  console.log('connected to react native');
  listeners = [];

  var wall = {
    listen(fn) {
      listeners.push(fn);
    },
    send(data) {
      // console.log('-->>' + JSON.stringify(data));
      ws.send(JSON.stringify(data));
    },
    disconnect() {
      ws.close();
    },
  };

  onConnected(wall);
});

window.onConnected = function () {
  console.error('No onConnected set');
};
window.onDisconnected = function () {
  console.error('No onDisconnected set');
};

<commit_msg>use packager as a proxy for electron-shell<commit_after>
// this is not compiled by babel / webpack
var ws = require('ws');
var fs = require('fs');

var socket = ws.connect('ws://localhost:8081/devtools');

socket.onmessage = initialMessage;

function initialMessage(evt) {
  if (evt.data === 'attach:agent') {
    initialize();
  }
};

socket.onerror = function (err) {
  window.onDisconnected();
  console.log('error connection', err);
};
socket.onclose = function () {
  window.onDisconnected();
  console.log('error things');
};

function initialize() {
  fs.readFile(__dirname + '/build/backend.js', function (err, data) {
    if (err) {
      return console.error('failed to load...', err);
    }
    socket.send('eval:' + data.toString('utf8'));
    socket.onmessage = function (evt) {
      // console.log('<<--', evt.data);
      var data = JSON.parse(evt.data);
      if (data.$close || data.$error) {
        console.log('Closing or Erroring')
        window.onDisconnected();
        socket.onmessage = initialMessage;
        return;
      }
      if (data.$open) {
        return; // ignore
      }
      listeners.forEach(function (fn) {fn(data)});
    };
    console.log('connected to react native');
    listeners = [];

    var wall = {
      listen(fn) {
        listeners.push(fn);
      },
      send(data) {
        // console.log('-->>' + JSON.stringify(data));
        socket.send(JSON.stringify(data));
      },
      disconnect() {
        socket.close();
      },
    };

    onConnected(wall);
  });
}

window.onConnected = function () {
  console.error('No onConnected set');
};
window.onDisconnected = function () {
  console.error('No onDisconnected set');
};

{'fraction_non_alphanumeric': 0.18309409888357256, 'fraction_numerical': 0.003827751196172249, 'mean_word_length': 2.900497512437811, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1529050', 'n_tokens_mistral': 1026, 'n_tokens_neox': 1021, 'n_words': 213}