Commit graph

15 commits

Author SHA1 Message Date
Ankush Menat
4778090024 refactor!: Frappe handlers using same extensible socketio 2024-04-06 18:39:16 +05:30
Ankush Menat
a313fb90cb fix(DX): no need to specify separate hook for socketio 2024-04-06 18:28:49 +05:30
Ankush Menat
39f7e4e92e fix: avoid crashing on handler import/execution
Can't do much for events, but at least here we can ignore the errors.
2024-04-06 18:17:27 +05:30
Ankush Menat
b7f2073380 feat: Extensible SocketIO
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
2024-04-06 18:17:27 +05:30
David Arnold
640e7d79b3
feat: prepare redis subsystem for unix domain socket connections 2024-03-29 10:12:19 +01:00
Ankush Menat
84188587fa fix: clean up socketio dynamic namespaces
While serving many sites it's best to close down namespace when last
connection is closed.

refer https://github.com/socketio/socket.io/pull/4602
2023-07-29 20:35:59 +05:30
David Arnold
7780670ae4
build(deps): update node redis client to v4 (#21797)
* build(deps): update redis client to v4 in legacy mode

* fix: node17+ - prefer ipv4

* chore: use redis client v4 api (async) and adapt error handling

* fix: timeout by exiting if not in watch mode

* fix: parse message before republishing

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
2023-07-25 14:07:46 +05:30
David Arnold
98d38e7333
fix: gently log the port on which the realtime service listens (#21575)
* fix: gently log the port on which the realtime service listens

without this, the service remains completely silent (e.g. in overmind) and it is hard to tell if it is even running

* Revert "fix: gently log the port on which the realtime service listens"

This reverts commit 14a21989c6767520d8e1b9d46cc9f58a45768563.

* refactor(socketio): explicitly listen on port

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
2023-07-14 11:36:31 +05:30
Ankush Menat
bdaed29ef2 refactor: move handlers to separate file 2023-07-01 12:43:47 +05:30
Ankush Menat
d59e499418 refactor!: Use SocketIO namespaces for multitenancy 2023-07-01 10:53:34 +05:30
Ankush Menat
dad1d57b90 chore: move redis sub setup 2023-07-01 10:53:34 +05:30
Ankush Menat
d13cb116bc refactor: use existing redis client 2023-07-01 10:53:34 +05:30
Ankush Menat
7320d2d020 refactor: move middleware out 2023-07-01 10:53:34 +05:30
Ankush Menat
164840c32e refactor: explicitly import socketio 2023-07-01 10:53:34 +05:30
Ankush Menat
5e4e60b509 refactor: Split socketio in multiple logical files 2023-07-01 10:53:34 +05:30