return socketList;
}
+var INTERNAL_PREFIX = 'NODE_';
function handleMessage(target, message, handle) {
- //Filter out internal messages
- //if cmd property begin with "_NODE"
+ var eventName = 'message';
if (message !== null &&
typeof message === 'object' &&
typeof message.cmd === 'string' &&
- message.cmd.indexOf('NODE_') === 0) {
- target.emit('internalMessage', message, handle);
- }
- //Non-internal message
- else {
- target.emit('message', message, handle);
+ message.cmd.length > INTERNAL_PREFIX.length &&
+ message.cmd.slice(0, INTERNAL_PREFIX.length) === INTERNAL_PREFIX) {
+ eventName = 'internalMessage';
}
+ target.emit(eventName, message, handle);
}
function setupChannel(target, channel) {