Add client side event handlers for update-* events.

This commit is contained in:
Patrick Jentsch 2019-08-29 11:37:00 +02:00
parent cf56394441
commit 876eb465b8
2 changed files with 15 additions and 5 deletions

View File

@ -49,14 +49,14 @@ def background_task(user_id, session_id):
jobs = list(map(lambda x: x.to_dict(), user.jobs)) jobs = list(map(lambda x: x.to_dict(), user.jobs))
''' Send initial values. ''' ''' Send initial values. '''
socketio.emit('init-corpora', socketio.emit('init-corpora',
{'data': json.dumps(corpora)}, json.dumps(corpora),
room=session_id) room=session_id)
socketio.emit('init-jobs', socketio.emit('init-jobs',
{'data': json.dumps(jobs)}, json.dumps(jobs),
room=session_id) room=session_id)
''' TODO: Implement maximum runtime for this loop. ''' ''' TODO: Implement maximum runtime for this loop. '''
while session_id not in disconnected: while session_id not in disconnected:
print(session_id + ' running') # print(session_id + ' running')
# socketio.emit('message', 'heartbeat', room=session_id) # socketio.emit('message', 'heartbeat', room=session_id)
''' Get current values from the database ''' ''' Get current values from the database '''
new_corpora = list(map(lambda x: x.to_dict(), user.corpora)) new_corpora = list(map(lambda x: x.to_dict(), user.corpora))

View File

@ -26,17 +26,27 @@
var socket = io(); var socket = io();
socket.on('init-corpora', function(msg) { socket.on('init-corpora', function(msg) {
corpora = JSON.parse(msg.data); corpora = JSON.parse(msg);
for (subscriber of corporaSubscribers) {subscriber.init();} for (subscriber of corporaSubscribers) {subscriber.init();}
}); });
socket.on('init-jobs', function(msg) { socket.on('init-jobs', function(msg) {
jobs = JSON.parse(msg.data); jobs = JSON.parse(msg);
for (subscriber of jobsSubscribers) {subscriber.init();} for (subscriber of jobsSubscribers) {subscriber.init();}
}); });
socket.on('update-corpora', function(msg) {
console.log(msg);
});
socket.on('update-jobs', function(msg) {
console.log(msg);
});
socket.on('message', function(msg) { socket.on('message', function(msg) {
console.log(msg); console.log(msg);
}); });