Node.ACS Websockets Disconnect event - What is passed to the callback? MVC

41 views
Skip to first unread message

Robin Williams

unread,
Apr 10, 2014, 3:01:23 AM4/10/14
to node...@googlegroups.com

Hi all, the title pretty much says it all!

Under the MVC framework for most websocket events I have found so far the callbacks are all passed (data, socket)

{ "event": "connect", "callback": "socketcontroller#sockit"}
.
.
.
sockit = function(data,socket){
    //stuff
};
What is passed on a disconnect event?

The biggest issue is that there are TWO disconnect scenarios - intentional... and accidental! It is mostly the accidental scenario I am concerned about.

I am guessing an intentional disconnect is handled in the normal way.

What is passed to the callback after an accidental disconnection (eg client loses signal)

Many thanks in advance,

Robin


PS - Sorry, I've cross posted this with the Appcelerator Q&A, I'm just trying to get AN answer from anyone who knows! Cheers!

Yuping Jin

unread,
Apr 11, 2014, 2:41:36 AM4/11/14
to node...@googlegroups.com
The MVC framework does not listen on any disconnect event which should be on a socket base. According to socket.io a reason will be passed to the callback for 'disconnect' event. Please try it and consult socket.io documentation for details.

Robin Williams

unread,
Apr 12, 2014, 1:51:15 AM4/12/14
to node...@googlegroups.com
Thanks for your reply!


I've finally found this (it appears you coded it!!) is this what I need? To put my own listener on the 'third object' passed to start?

https://jira.appcelerator.org/browse/TIDOC-1367?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel


Many thanks,

Robin

Robin Williams

unread,
Apr 12, 2014, 4:11:32 AM4/12/14
to node...@googlegroups.com


I've tried this:

function start(app, express, io) {

app.use(express.favicon(__dirname + '/public/images/favicon.ico')); //set favicon
io.on('disconnect', function(){
console.log("DISCONNECT!");
});
(etc)
}

...but nothing is logged to the tail logs (I've double checked that console.log works and it works fine) so I can only conclude that nothing is fired?

Thinking it through however, surely 'start()' is fired at the intialisation of the server, not the creation of a new socket? So whatever is passed to it would only ever occur once at startup, not on each new socket?

Many thanks for your time.

Robin

Robin Williams

unread,
Apr 15, 2014, 12:42:24 AM4/15/14
to node...@googlegroups.com

Hi all! Okay, I've worked this out...

{ "event": "disconnect", "callback": "socketcontroller#disconnect" }
DOES get called and passes both 'data' AND 'socket' as usual...

From what I can gather, data is a string containing the reason for disconnection.

I've only found 2 values so far:


- "booted" (when calling socket.disconnect(); from the client)

and

- "heartbeat timeout" when the client is closed without specifically sending a disconnect instruction. It also seems to take about 30 seconds for the timeout, so you may need to bear that in mind.

Yuping Jin

unread,
Apr 15, 2014, 9:44:45 PM4/15/14
to node...@googlegroups.com
Awesome! Thanks for your update!
Reply all
Reply to author
Forward
0 new messages