diff --git a/dao/client.js b/dao/client.js index 6213cec..cac4d22 100644 --- a/dao/client.js +++ b/dao/client.js @@ -149,8 +149,8 @@ function connect(){ 'close', function connectionClosed(){ client.log('connection closed' ,client.id , client.path, - client.retriesRemaining, 'tries remaining of', client.config.maxRetries - ); + client.retriesRemaining, 'tries remaining of', client.config.maxRetries + ); if( client.config.stopRetrying || @@ -190,8 +190,8 @@ function connect(){ client.log('## received events ##'); if(client.config.rawBuffer){ client.publish( - 'data', - new Buffer(data,client.config.encoding) + 'data', + new Buffer(data,client.config.encoding) ); if(!client.config.sync){ return; @@ -222,16 +222,18 @@ function connect(){ if (message.type === '__identify') { client.emit('__identify', { - id: client.config.id - //path: client.path + id: client.config.id, + + // TODO: This can't be right.... + path: client.config.socketRoot + client.config.appspace + client.config.id }); continue; } client.log('detected event', message.type, message.data); client.publish( - message.type, - message.data + message.type, + message.data ); } @@ -244,4 +246,4 @@ function connect(){ ); } -module.exports=Client; +module.exports=Client; \ No newline at end of file diff --git a/dao/socketServer.js b/dao/socketServer.js index dd60e76..ebf64fa 100644 --- a/dao/socketServer.js +++ b/dao/socketServer.js @@ -247,7 +247,22 @@ function serverCreated(socket) { socket ); } else { - this.on('__identify', function(clientDetails) { + + // Wait for handshake + var t = setTimeout(() => this.publish('error', 'Child connection did not finish handshake in time'), 2000); + + // Handhake callback function + // Checks if its the same socket instance + var __identifyCb = (clientDetails, _socket) => { + if (_socket !== socket) + return; + + // Clear handhake timeout + clearTimeout(t); + + // Make sure event is removed + this.off('__identify', __identifyCb); + let id = clientDetails.id, path = clientDetails.path, clientConfig = Object.assign(this.config, {id: id, path: path}); @@ -261,7 +276,9 @@ function serverCreated(socket) { }); this.publish('connect', socket, this.of[id]); - }.bind(this)); + }; + + this.on('__identify', __identifyCb); this.emit(socket, '__identify'); }