Frappe.publish_realtime() not working

Hi,

I can’t get frappe.publish_realtime() to do anything. I’ve been browsing the forums for the last several hours, but I haven’t uncovered any leads that help me figure out what’s going wrong.

I have this code on the server:

frappe.publish_realtime('gang_process',
                        {'task_id': 1, 'foo': 'bar'},
                        user=frappe.session.user)
frappe.msgprint('done')

On the client, I have this:

console.log('setup realtime');
frappe.realtime.on('gang_process', (data) => {
    console.log('data', data);
});

Both code blocks trigger when I press a button. I expect to see this in the browser console:

setup realtime
data {'task_id': 1, 'foo': 'bar'}

in the browser console, as well as a frappe message box with the word “past” in it. All I see is setup realtime and the messagebox, with no indication error or indication of any kind that frappe.publish_realtime() did anything at all.

Environment

I’m running ERPNext 12 in development mode. On the suggestion from one of the forums, I ran

bench setup socketio
bench build

after which I restarted the server and refreshed the page. Nothing changed.

Any help would be appreciated!

1 Like

Is anyone familiar with the publish_realtime API able to help me? This is a bit of a mystery to me, especially since the notifications appear that indicate when other people are viewing a document you have open.

I don’t have anything useful to say other than that I’ve also really struggled to get this working. I’m following this thread with interest!

I also have not successfully used publish_realtime, but would like to.

As per my knowledge, it doesn’t work in developer mode.

That’s a dead link:
https://discuss.frappe.io/t/how-to-setup-socketio-for-development-mode/187

The old developer forums were either completely removed, or exist somewhere I don’t know about.

remove sites/currentsite.txt file

rm sites/currentsite.txt

add site names to /etc/hosts, or just use sites ending with .localhost.

And it’ll work. It needs to identify site name from request headers for socketio to work

3 Likes