Extend frappe socketio to handle messages from custom apps

Is there anyway to tap into and extend frappe/socketio.js, so that custom apps could publish messages, that could be handled by nodejs applications in the custom app?

I would like to publish events from custom app doc.js e.g.

frappe.realtime.publish('print_doc',{ doc: cur_frm.doc })

and have a node process running on server in the custom app, that handles this message

// custom_app/socketio.js
io.on('connection', function (socket) {
        socket.on('print_doc', function (doc) {
             // do something

Write you own node_utils.js and socketio.js and start it instead of the ones built by frappe. You can try to hack up something to import and extend existing js files instead of full copy-paste.

Changes will be needed in :

  • For manual production setup: supervisor.conf, change the node socketio.js part
  • For dev setup: Procfile
  • For container setup: replace image of websocket / frappe-socketio service with your own image.

Another alternative is to add additional nodejs app and reverse proxy it: How Add nodejs App to frappe & bench? - #5 by revant_one.


Understood. Just seems I’ll be recreating functionality that frappe is already doing good, unless there’s some disadvantage hitching on to frappe.

Yes, the reverse proxy way would actually be cleaner
as I don’t need a socket especially for this use case.