How to connect mobile app with frappe socketio?

I am developing a Flutter app which connects to frappe via REST API. For messaging purpose i need to integrate frappe socket as server and flutter socket as client. Is there any one having experience regarding this? I am having trouble in connecting sockets. My frappe app is running in url ‘http://jobs.xxxxxxxx.com’. I am using “flutter_socket_io” dart package to connect server.
Following dart code to connect to frappe.

socketIO = SocketIOManager().createSocketIO('http://jobs.xxxxxxxx.com', '/' );
socketIO.init();
socketIO.subscribe('message', (jsonData) {
  Map<String, dynamic> data = json.decode(jsonData);
  this.setState(() => messages.add(data['message']));
});

What i did wrong?

1 Like

hi @Kirubakaran_Thillaia, do you have the solution for this?
tank you

Hi, I have done the flutter app as frontend and ERPNext as Backend. What is your issue?

1 Like

Hi. Thank you for raising this thread. We are also planning same method. Flutter app for ios and Android with ERPNext as backbone for all data. Would you be able to document how you went about integrating app with ERPNext and have 2 way synchronization.

Hi Muzzy,

I used Frappe’s RestApi to integrate flutter app with ERPNext.
This is well documented by Frappe team. Thanks to Frappe team.

Follow the below link.

3 Likes

hi @Kirubakaran_Thillaia, @Muzzy , yes rest api is for connection with doctypes… and methods… etc.,
but for socket.io server, do you have some examples ( flutter ) ? … i need it for real time messaging… , thanks…

I used Firebase Cloud Messaging service to push notifications to flutter app via frappe app.
You can use “pyfcm”, fcm’s python module inside frappe app’s server side script to send messaged to flutter app.

1 Like

Thanks, @Kirubakaran_Thillaia , i’ll tray it…

Hi @Kirubakaran_Thillaia,

So did you find what was wrong? And what was the updated code that eventually worked?

Kind regards,

@wale
We are interested in this. @Kirubakaran_Thillaia can you throw more light as requested

I don’t find a way to connect to frappe socket from external applications.
So i am utilizing firebase FCM solution.

Okay, many thanks!

hi, someone has tried with this … article? https://medium.com/@joshiparthin/how-to-get-realtime-updates-in-your-app-from-erpnext-via-socket-io-and-redis-42075bbc3479

Hi, I’ve made an app based on the tutorial above, now you can connect external clients to erpnext via socket io. here’s the link https://github.com/pifabs/fsocket

Hi @Kirubakaran_Thillaia
Are you able to share your code for push notifications?

Hi, You can refer FCM Firebase Documentation website for more details.
In erpnext python script you can import “from pyfcm import FCMNotification” and by calling you method.

> def spokes_message_socketio(doc, method):
    if doc.msg_from == "Admin":
        push_service = FCMNotification(
            api_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
        user = frappe.get_doc('xyz', doc.mobile_no)
        registration_id = user.fcm_id
        message_title = "Message from Portal"
        message_body = doc.message_from_admin
        result = push_service.notify_single_device(
            registration_id=registration_id, message_title=message_title, message_body=message_body)

For this you need to store fcm_id while accepting user for the first time.