How can I call a Javascript function from Python (severside)

i have a function in init__.py file , i have crated custom javascript file in the app folder called library_management.js,

app folder

.js file

init.py file

Unfortunately there are no push notifications implemented in ERPNext.

You can keep pollling from javascript every 3-4 seconds to check if there is a call.

actually my py function is in _init.py, am not able to connect a javascript file from python, thats what my qstion how i can link a javascript file to init.py file.

using below script for polling the python function, but whitelist python function is not passing any value to java script.

(function poll(){

$.ajax({

url: "/api/method/library_management.library_management.doctype.library_customers.library_customers.callfrom_asterisk",
success: function (data) {
  alert(data);
},
dataType: "json",
complete: poll,
timeout: 30000

});
})();

Check your network tab. There should be a result, or there could be an error.