Browse Source

Add socket.io functionality to the main.js file, including event listeners for various events and toastr notifications for success or error events

node16
Onja 1 year ago
parent
commit
5bac1a9945
  1. 36
      src/assets/js/main.js

36
src/assets/js/main.js

@ -1,6 +1,7 @@
import $ from 'jquery'; import $ from 'jquery';
import 'bootstrap'; import 'bootstrap';
import toastr from 'toastr'; import toastr from 'toastr';
import io from 'socket.io-client';
/*********************************************** /***********************************************
* MAIN JS FILE * MAIN JS FILE
@ -113,7 +114,42 @@ const initSubmitForm = () => {
}); });
} }
const initSocket = () => {
const socket = io();
socket.on('connect', function() {
console.log('Connected to server');
});
socket.on('disconnect', function() {
console.log('Disconnected from server');
});
const events = [
'download.start',
'download.started',
'download.end',
'download.error',
'download.progress',
'parse.start',
'parse.end',
'parse.error'
];
for(let event of events) {
socket.on(event, function(data) {
if (event.includes('error')) {
toastr.error(data.message);
return;
}
toastr.info(data.message);
});
}
};
$(document).ready(function() { $(document).ready(function() {
initColumnsChoices(); initColumnsChoices();
initSubmitForm(); initSubmitForm();
initSocket();
}); });

Loading…
Cancel
Save