You can now specify custom event handlers for SocketIO.
Usage:
1. In your app's hooks.py add `has_realtime_event_handlers=True` so
Framework can assume your app contains custom handler and import them.
2. Create a file called `/app/realtime/handlers.js` with single module
export a function that will setup handlers using socket.
Here's sample code:
```js
// This is /app_root/realtime/handler.js`
function chat_app_handlers(socket) {
socket.on("hello_chat") {
console.log("hello world!");
}
}
module.exports = chat_app_handlers;
```
3. Restart SocketIO server and see if it worked by sending event from
client. In desk based app you can do
`frappe.realtime.socket.emit("hello_chat")`
Middlewares are not yet possible... will be worked upon __some other day__ [tm]
closes https://github.com/frappe/frappe/issues/21528
Earlier socketio only worked in browser where browser would send cookie
(cause same domain) and hence socketio server used it to auth
connection.
This however is limited and doesn't allow simply creating socket
connection from apps.
Authorization headers on other hand are simple to implement.
Establishing 1 connection for every website visit is too much.
Only after calling frappe.realtime.on(...) for ANY event, we will
establish a websocket connection.
This is used for handful of things:
- Discussion component
- File upload
Socketio was initially added here: https://github.com/frappe/frappe/pull/6866 this use case no longer exists.
Rarely anywhere website uses realtime.