'use strict'

let ReactDOM = require('react-dom');
let React = require('react');
let FlightTable = require('./flight-table');

let data = [
    {
        icao: "471f7f",
        flight: "WZZ7HP",
        squawk: "6212",
        altitude: "3200",
        speed: "175",
        distance: "11.6",
        track: "48",
        msgs: "768",
        age: "0"
    },
    {
        icao: "3c6752",
        flight: "EWG7Y",
        squawk: "0460",
        altitude: "39025",
        speed: "399",
        distance: "96.2",
        track: "49",
        msgs: "868",
        age: "0"
    }
];

ReactDOM.render(
    <FlightTable data={data} />, 
    document.getElementById('content')
);


'use strict'

let wsUrl = 'ws://192.168.0.12:8888';

let webSocket = new WebSocket(wsUrl, ['binary', 'base64']);

let translateMessage = message => {
    return {
        icao: message.hex_ident,
        flight: message.callsign,
        squawk: message.squawk,
        altitude: message.altitude,
        speed: message.ground_speed,
        distance: '',
        track: message.track
    }
};



webSocket.onmessage = evt => {
    let reader = new FileReader();

    reader.onloadend = () => {
        let messages = reader.result.split('\n');
        messages.slice(0,-1).forEach((message, index) => messages[index] = translateMessage(parseSbs1Message(message)));

        flightTableComponent.setState({data: messages});
    };
    

    reader.readAsText(evt.data);
}

let ReactDOM = require('react-dom');
let React = require('react');
let FlightTable = require('./flight-table');


let flightTableComponent = ReactDOM.render(
    <FlightTable />, 
    document.getElementById('content')
);


Implement a prototype loading data from websocket and rendering it in a table
Implement a prototype loading data from websocket and rendering it in a table
