Add initial version of frontend

This commit is contained in:
Bálint Bokros
2017-11-17 15:42:39 +01:00
parent 8e6b432719
commit 4c4d1ac8ab
3 changed files with 67 additions and 0 deletions

28
static/ws_listener.js Normal file
View File

@ -0,0 +1,28 @@
let ws = new WebSocket('ws://' + document.location.host + '/ws');
// ws.onopen = function() {
// ws.send(JSON.stringify({
// 'anchor': '',
// 'data': 'Hello, World!'
// }));
// };
// TODO: annotate objects that can fire events
// TODO: annotate objects that should receive response from events
// TODO: work out object notation for events that are fired
// TODO: work out object notation for responses
$('#container').on('click', '.anchor', ( function (event) {
let anchorName = $(this).attr('id').replace('_event', '');
let data = JSON.stringify({
'anchor': anchorName,
'data': $('#' + anchorName).text()
});
console.log("Sending: " + data);
ws.send(data);
}));
ws.onmessage = function (messageEvent) {
let message = JSON.parse(messageEvent.data);
$('#' + message['anchor']).text(message['data']);
};