{"size": 1234, "ext": "js", "max_stars_repo_path": "tests/js_source/src/App.js", "max_stars_repo_name": "cromulencellc/asn1tools", "max_stars_repo_stars_event_min_datetime": "2017-08-04T21:49:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T10:11:21.000Z", "max_issues_repo_path": "tests/js_source/src/App.js", "max_issues_repo_name": "cromulencellc/asn1tools", "max_issues_repo_issues_event_min_datetime": "2017-09-29T12:06:51.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T13:04:44.000Z", "max_forks_repo_path": "tests/js_source/src/App.js", "max_forks_repo_name": "cromulencellc/asn1tools", "max_forks_repo_forks_event_min_datetime": "2017-10-09T13:33:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T01:35:22.000Z"}
{"max_stars_count": 198, "max_issues_count": 144, "max_forks_count": 73, "avg_line_length": 23.7307692308, "max_line_length": 80, "alphanum_fraction": 0.6450567261}
import React from 'react';
import './App.css';
import { CSourceB } from './c_source';

function App() {
    return (
        <div>
            <div>Sending messages to the server and waiting for responses.</div>
            <ul id="list"></ul>
        </div>
  );
}

var websocket = new WebSocket("ws://127.0.0.1:8765/");
websocket.binaryType = "arraybuffer";
websocket.onmessage = function (event) {
    var message = new CSourceB();
    message.fromUint8Array(new Uint8Array(event.data));
    console.log(message);

    if (message.choice === CSourceB.CHOICE_A) {
        appendList("Received: " + message.value.a);
    }
};

function appendList(text) {
    var node = document.createElement("li");
    var textnode = document.createTextNode(text);
    node.appendChild(textnode);
    document.getElementById("list").appendChild(node);
    window.scrollTo(0, document.body.scrollHeight);
}

var message = new CSourceB();
message.choice = CSourceB.CHOICE_A;
message.value.a = 0;

function tick() {
    message.value.a++;

    if (message.value.a > 127) {
        message.value.a = -128;
    }

    appendList("Sending: " + message.value.a);
    websocket.send(message.toUint8Array());
}

setInterval(tick, 500);

export default App;
