// Open the websocket connection var ws = new WebSocket((window.location.protocol === 'https:' ? 'wss://' : 'ws://') + window.location.host + '/ws'); // Open conection with Socket ws.onopen = function() { console.log('Connection opened!'); }; // Receive data from server ws.onmessage = function(message) { //console.log('Message received!'); var msg = JSON.parse(message.data); switch(msg['type']) { case 'trials': $('#load').removeClass('loader'); set_trials(msg['data']); break; case 'get_trial': console.log(msg['data']); GraphVisualization.import(convertJSON(msg['data']['graph']), msg['data']['models'], function() { $('#load').hide(); reset_configuration(); set_configuration(); reset_timeline(); set_timeline(msg['data']['graph']); }); break; case 'settings': //console.log(msg['data']); initGUI(msg['data']); break; case 'error': console.log(msg['error']); _socket.error(msg['error']); $('#load').removeClass('loader'); break; case 'log': $('.console').append('$ ' + msg['logger'] + ': ' + msg['logging'] + '
'); $('.console').animate({ scrollTop: $('.console')[0].scrollHeight }, 'slow'); break; default: console.log('Unexpected message!') } } var _socket = { send: function(message, type) { var json = {} json['type'] = type json['data'] = message ws.send(JSON.stringify(json)) }, error: function(message) { $('#error-message').text(message); $('.alert.alert-danger').show(); } }; var set_trials = function(trials) { for ( i in trials ) { $('