<commit_before>import 'dart:html';
import 'dart:async';
import 'dart:json' as json;
import 'package:web_ui/web_ui.dart';

typedef void MessageCallback(String data);

class ReconnectingSocket {
  WebSocket webSocket;
  String url;
  MessageCallback callback;
  bool connected = false;

  ReconnectingSocket(this.url, this.callback) {
    _init();
  }

  _init([int retrySeconds = 2]) {
    bool reconnectScheduled = false;
    webSocket = new WebSocket(url);

    scheduleReconnect() {
      if (!reconnectScheduled) {
        print('web socket closed, retrying in $retrySeconds seconds');
        new Timer(new Duration(seconds: retrySeconds),
            () => _init(retrySeconds * 2));
      }
      reconnectScheduled = true;
    }

    webSocket.onOpen.listen((e) {
      connected = true;
      print('Connected');
      retrySeconds = 2;
    });

    webSocket.onClose.listen((e) => scheduleReconnect());
    webSocket.onError.listen((e) => scheduleReconnect());
    webSocket.onMessage.listen((e) => callback(e.data));
  }

  send(String data) {
    webSocket.send(data);
  }
}

class TarabishSocket {
  // TODO: add logged_in, and queue for messages while not logged_in
  ReconnectingSocket webSocket;
  int cookie;
  Map<String, dynamic> eventMap;

  TarabishSocket(url) {
    eventMap = new Map();
    webSocket = new ReconnectingSocket(url, _receiveEvent);
  }
<commit_msg>Make TarabishSocket more of a proxy to WebSocket.<commit_after>import 'dart:html';
import 'dart:async';
import 'dart:json' as json;
import 'package:web_ui/web_ui.dart';

typedef void MessageCallback(String data);

class ReconnectingSocket {
  WebSocket webSocket;
  String url;

  ReconnectingSocket(this.url) {
    _init();
  }

  _init([int retrySeconds = 2]) {
    bool reconnectScheduled = false;
    webSocket = new WebSocket(url);

    scheduleReconnect() {
      if (!reconnectScheduled) {
        print('web socket closed, retrying in $retrySeconds seconds');
        new Timer(new Duration(seconds: retrySeconds),
            () => _init(retrySeconds * 2));
      }
      reconnectScheduled = true;
    }

    webSocket.onOpen.listen((e) {
      print('Connected');
      retrySeconds = 2;
    });

    webSocket.onClose.listen((e) => scheduleReconnect());
    webSocket.onError.listen((e) => scheduleReconnect());
  }

  send(String data) {
    webSocket.send(data);
  }

  // There's probably a better way to proxy these, I don't know it.
  Stream<Event> get onOpen => webSocket.onOpen;
  Stream<CloseEvent> get onClose => webSocket.onClose;
  Stream<Event> get onError => webSocket.onError;
  Stream<MessageEvent> get onMessage => webSocket.onMessage;

}

class TarabishSocket {
  // TODO: add logged_in, and queue for messages while not logged_in
  ReconnectingSocket webSocket;
  int cookie;
  Map<String, dynamic> eventMap;

  TarabishSocket(url) {
    eventMap = new Map();
    webSocket = new ReconnectingSocket(url);
    webSocket.onMessage.listen((e) => _receiveEvent(e.data));
  }

{'fraction_non_alphanumeric': 0.12160804020100502, 'fraction_numerical': 0.0020100502512562816, 'mean_word_length': 3.615146831530139, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '2825944', 'n_tokens_mistral': 962, 'n_tokens_neox': 936, 'n_words': 220}