Socket events listeners in android

Hey,

So, I created one event listener on my client using socket.io-client module, to listen events from trudesk when ticket is created.

import openSocket from 'socket.io-client'
const socket = openSocket(`http://192.168.0.146:8118`)

When I am running my client on PC, the socket object contains a key “connection” with value as “true”.
But when I am running on andriod, the connection key is “false” and “disconnected : true”.

Looks like it’s not able to create connections with trudesk from mobile. Can you help me to sort this out?

This is by design. What is the client you are using/building?
The socket requires authentication with the authentication server in order to accept the socket connection.

On the mobile site and mobile app the socket is joined once you click on the messages tab to connect to the chat server. The authentication is in place to prevent sockets from connecting to the server without properly identify the user associated with the socket.

I am using react 16.7 to build my client.
So, you are saying socket connection requires authentication when the client in mobile tries to connect?
I am able to connect to socket of trudesk when I am running my client in mobile view of chrome debugger. It just doesn’t connect when I actually use chrome in my android. The socket object shows {connected: false, disconnected: true}

This is something custom that is outside the scope of trudesk. I cannot debug your custom client. I can only support the clients within trudesk. (web & mobile).

I do not know what you’re sending to the server or why “your” client isn’t working correctly. My mobile client works fine on android, ios, or just plain ol’ chrome on mobile.

I have not seen any code from your client so its nearly impossible to debug it.

Let me explain what I am doing, maybe it’ll help me.
So, I am not sending any events to trudesk. I am just listening to events that trudesk emits.
For example, when I am creating a ticket in trudesk, it emits one event as “ticket:created”. So, I am just listening to that event.
So, to listen events I created one socket connection on my client.

import openSocket from 'socket.io-client'
const socket = openSocket(`http://192.168.0.146:8118`);
const subscribeToTaskEvents = (cb) => {
   socket.on('task:created', task => {
      console.log('task created')
      return cb(null, task, 'task created')
   })
}

export {
  subscribeToTaskEvents
}

I am just importing "subscribeToTaskEvents in the constructor of my class.
Now, when creating a socket connection with openSocket(http://192.168.0.146:8118); It creates one object. That object has two keys connected and disconnected.
So, when I am running it in my chrome debugger, in mobile view, it works perfectly. I get “connected”: true and I am able to get “ticket:created” event.
But when I am using that in android chrome the socket object contains “connected”: false.

Try this. On your desktop on chrome. Goto your instance of trudesk (http://192.168.0.146:8118) and then click your profile picture (top right) and then logout. Then using your client from Chrome on the desktop, see if you still get the event.

Okay, I starting to see the problem. Now I understood what you meant when you said the socket requires authentication. So, when I am logging out on desktop chrome, my client is unable to establish socket connection.

So, I tried to do the same on my mobile. I opened trudesk client on my mobile, logged in with my account and on the next tab I opened my client. But it failed to establish socket connect.

Can you tell me where have you configured the authentication for socket connection, please?

You need to send the api key as a query option when connecting.

See https://socket.io/docs/client-api/#With-query-option

1 Like

Finally, I did it. Thank you for your help. Now I can listen to events and I changed a bit to authenticate using id and created a new section for “Tasks” along with “Ticket”. I know, I sound like a noob, I just started learning these things.

Again, thanks for your help. Keep up your amazing work.:slightly_smiling_face: