2

I'm writing some 'shield' code in my node websocket server, so that if the client tries to send events which are out of state, the socket is disconnected.

But since socket.io handles their native events (like 'connecting', 'disconnected' etc) similar to user defined events, I'm having a hard time differentiating between them in my generic handler

Is there a way to programatically retrieve a list of all built-in events from socket.io? I want to avoid hardcoding this list.

carpii
  • 1,917
  • 4
  • 20
  • 24
  • Please have a look at http://stackoverflow.com/q/4753957/52568 – Kurt Pattyn Aug 27 '13 at 09:40
  • Thanks, but Im not sure how this answers my question. I was just hoping to get a list of built-in events programatically (I know how to write event handlers and secure code). – carpii Aug 27 '13 at 16:15

1 Answers1

2

After some digging, find out there is internal list of packet names, and is easily accessible:

var io = require('socket.io');
var events = io.parser.packets;

It has a bit more than just three usual events, but can be usefull anyway.

moka
  • 22,846
  • 4
  • 51
  • 67
  • Awesome, this is very useful. It lets me write my code in a way that wont break if socket.io gets new events added :) Thankyou so much! – carpii Sep 01 '13 at 03:18
  • Bear in mind that there looks like will be new update soon to 1.0, it might actually change compatibility, but obviously you can still use present version as most will. – moka Sep 02 '13 at 09:04