How to push real time messages to a custom page

Hello Guys,

I am testing the possiblity to post real time updates to a custom page.

I have the following code:

from __future__ import unicode_literals
import frappe
from frappe.utils.data import nowtime
import time as tm

@frappe.whitelist()
def update_console():
    for t in range(0,10):
        try:
            print('publishing')   
            frappe.publish_realtime(
                'realtime_updates',
                message=str(nowtime()),
                room='my_room',
                user=frappe.session.user
            )
        except Exception as e:
            print(str(e))
        tm.sleep(1)
        frappe.msgprint("count:"+str(t))

and js :

frappe.require("assets/frappe/js/frappe/socketio_client.js");
frappe.pages['console-template'].on_page_load = function(wrapper) {
    var page = frappe.ui.make_app_page({
        parent: wrapper,
        title: 'Console Template',
        single_column: true
    });
    frappe.breadcrumbs.add("Healthcare");
    page.main.html(frappe.render_template("console-template", {}));
}
frappe.realtime.on('realtime_updates', function(data) {
    console.log( "REALTIME ENGAGED!" );
    if (data.room == 'my_room'){
        console.log( "DATA RECEIVED!" );
        var room = data.room;
    }else{
        console.log( "NO DATA RECEIVED!" );
        var room = 'zilch';
    }
    console.log( "realtime works!" );
    frappe.msgprint(room);
});
console.log( "ready!" );
frappe.call({
    method: 'evmchis.evmc.page.console_template.console_template.update_console',
    callback: function(r) {
        console.log(r.message);
    }
})
console.log( "called!" ); 

The above code only outputs the msgprint function in the python method.

Realtime updates are not being received.

Please advise.
@revant_one , @netchampfaris or any one else

Currently running:

ERPNext: v12.x.x-develop () (develop)
Frappe Framework: v12.x.x-develop () (develop)

Thanks

many days later I realised my problem was with firewall restriction on ip…

silly me.

I can relate don’t think you’re the only one who is forgetful…

1 Like

FWIW these pointers may appeal to you if you have not already seen them: