Using socket.io in a custom web page

Can someone point to me to an example on how to achieve this: I want to create a custom web dashboard that display events happening on doctype in real time. For example, a notification is displayed automatically when a new invoice is created. Thank you!

Try this :

[How To] Enable Socketio on web pages

Thank. Sorry I have not been working on this for a while.
The link you gave helped. However, it only works in production setup.

I followed the same but it runs if I initialize on the console not else, can you tell me how you did this?

You have to add your site name to hosts file and use site name in the browser then test

mysite name is localhost and it is in hosts file but still this does not works

this error returns

basically how can I call emit functions from js file?

it was synchronization issue
frappe.ready(function() {
const assets = [
“assets/frappe/js/lib/socket.io.min.js”,
“assets/frappe/js/frappe/socketio_client.js”
]
frappe.require(assets, () => {
if (window.dev_server) {
frappe.boot.socketio_port = ‘9000’ //use socketio port shown when bench starts
}
frappe.socketio.init();
console.log(frappe.socketio)
frappe.socketio.emittedDemo(‘mydata’);
})
});

now it works