mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2025-06-28 16:25:12 +00:00
Add initial version of frontend
This commit is contained in:
28
static/ws_listener.js
Normal file
28
static/ws_listener.js
Normal 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']);
|
||||
};
|
Reference in New Issue
Block a user