Skip AH-related information in on message handler

18 views
Skip to first unread message

whizz...@gmail.com

unread,
Apr 16, 2014, 5:04:53 PM4/16/14
to action...@googlegroups.com
Hello,
I'm experimenting with AH connections/messages/etc and I stumbled across an issue. After enabling this line in the chat.html file:
client.on('message', function(message){ alert(JSON.stringify(message)); })

I call a simple action through actionheroClient and I get four alert messages (after disabling the welcome one):

{}

{"status":"OK","context":"response","data":{"id":"xx","remoteIP":"0.0.0.0","remotePort":0,"params":{},"connectedAt":xx,"room":null,"totalActions":0,"pendingActions":0} ,"messageCount":1}

{"params":{"action":"userInfo"}}

{"info":"user info","context":"response","messageCount":2}

However, I want to receive only one second and the fourth messages (the ones that contain messageCount) that are the actual messages.

Evan Tahler

unread,
Apr 16, 2014, 9:31:45 PM4/16/14
to action...@googlegroups.com, whizz...@gmail.com
I don’t know if I would call that a bug.  on(‘message’) is really a ‘debug’ command that will emit *every* message the client receives from the server, which includes welcome messages, chat stuff, action responses, etc.   

The first status message is the response of connection.details() which you can always call on your own.  It’s called upon connection to setup some of the client’s data. 

The second message you want is the response of calling an action (client.action(‘actionName', function()), and you get that response message in the callback as well.

If you want only chat messages, listen to on(‘say’).

What are you trying to capture by collecting all the messages?

--
You received this message because you are subscribed to the Google Groups "actionHero.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to actionhero-j...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

whizz...@gmail.com

unread,
Apr 17, 2014, 6:02:48 AM4/17/14
to action...@googlegroups.com, whizz...@gmail.com
I'm saving all connection in a pool and then depending on some things I need to send a message to some connections. I do that using connection.sendMessage, so I assumed that I'd have to listen for the on('message') event.
What is more important to me is that I want to use AH in a mobile app and I want to limit the network requests as much as possible. That's why I'm conserned with the four messages (instead of the ideal case in which I get only one, the one I have sent with connection.sendMessage).

Evan Tahler

unread,
Apr 17, 2014, 11:55:47 AM4/17/14
to action...@googlegroups.com, whizz...@gmail.com, whizz...@gmail.com
The messages you are looking at are specific to the websocket protocol.  connection.sendMessage is lower-level than either an action or a chat room.  I would still suggest that you use the chat features to message groups of clients from the server, but if you are intent on intent on truly minimizing data sent, you can always right a new server.  Keep in mind that the “chat” features don’t have to be used for client-client communication, and you can lock-down room access.  You can also have your clients listen to multiple rooms, so you can have broadcast groups based on room membership. 

Keep in mind that there is networking overhead to keep a persistent (websocket, tcp, etc) connection open.  Depending on the frequency of transmit, you may actually save power connecting over HTTP rather than socket. 

Reply all
Reply to author
Forward
0 new messages