<commit_before>/**
 * Client.
 * This should be loaded by the client html page.
 *
 * Connect to server via websocket and handle push messages from server.
 */

#import('dart:html');
#import('dart:io');
#import('dart:json');

class PresendartClient {

  bool _sync;
  Socket _socket;

  void connect() {
    String host = document.query('#host_id').attributes['value'];
    int port = Math.parseInt(document.query('#port_id').attributes['value']);
    Element canvas = document.query('#canvas');
    canvas.innerHTML = 'Connecting to $host:$port.. (Slide goes here)';

    _socket = new Socket(host, port);

    _socket.onData = () {
      Map data = JSON.parse(_socket.inputStream.read().toString());
      updateSlides(data);
    };
  }

  void updateSlides(Map data) {
  }

}

void main()
{
  PresendartClient pc = new PresendartClient();
  document.query('#startbutton').on.click.add(
    (e) { pc.connect(); }
  );
}<commit_msg>Use WebSocket from dart:html instead of dart:io<commit_after>/**
 * Client.
 * This should be loaded by the client html page.
 *
 * Connect to server via websocket and handle push messages from server.
 */

#import('dart:html');
#import('dart:json');

class PresendartClient {

  bool _sync;
  WebSocket _ws;

  PresendartClient() {
    _sync = false;
  }

  void connect() {
    String host = document.query('#host_id').value;
    String path = document.query('#path_id').value;
    String url  = 'ws://$host/$path';
    Element canvas = document.query('#canvas');
    canvas.innerHTML = 'Connecting to $url.. (Slide goes here)';

    _ws = new WebSocket(url);
    // TODO: Check that _ws is valid
    _ws.on.message.add(
      (e) {
        Map msg = JSON.parse(e.data);
        updateSlides(msg);
      }
    );

  }

  void updateSlides(Map msg) {
    if (_sync && msg['state']) {
      window.location.hash = msg['state'];
    }

    if (msg['refresh']) {
      window.location.reload();
    }
  }

}

void main()
{
  PresendartClient pc = new PresendartClient();
  document.query('#startbutton').on.click.add(
    (e) {
      pc.connect();
    });
}
{'fraction_non_alphanumeric': 0.15900383141762453, 'fraction_numerical': 0.0, 'mean_word_length': 3.1284584980237153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2590108', 'n_tokens_mistral': 689, 'n_tokens_neox': 672, 'n_words': 165}