{
const serverLocation = "ws://127.0.0.1:8000/ws/output/"
const startWebSocketConnection = (websocketServerLocation) => {
console.log('Initializing Forja websocket connection')
const forjaSocket = new WebSocket(websocketServerLocation);
forjaSocket.onmessage = function(e) {
console.log(e.data)
const data = JSON.parse(e.data, (key, value) => JSON.parse(value))
document.querySelector('#data-display').innerHTML = JSON.stringify(data, null, "<br> ")
};
forjaSocket.onclose = function(){
console.error('Forja websocket closed unexpectedly')
setTimeout(function(){startWebSocketConnection(websocketServerLocation)}, 5000);
};
const buttons = document.getElementsByClassName('get-data')
Array.from(buttons).forEach((button) => {
button.onclick = null
button.onclick = function() {
forjaSocket.send(JSON.stringify({
'group': this.name
}))
}
})
}
startWebSocketConnection(serverLocation)
}