wip
This commit is contained in:
parent
5177a71a40
commit
c48c203f43
2 changed files with 30 additions and 11 deletions
|
@ -149,8 +149,8 @@ function connect(){
|
||||||
'close',
|
'close',
|
||||||
function connectionClosed(){
|
function connectionClosed(){
|
||||||
client.log('connection closed' ,client.id , client.path,
|
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(
|
if(
|
||||||
client.config.stopRetrying ||
|
client.config.stopRetrying ||
|
||||||
|
@ -190,8 +190,8 @@ function connect(){
|
||||||
client.log('## received events ##');
|
client.log('## received events ##');
|
||||||
if(client.config.rawBuffer){
|
if(client.config.rawBuffer){
|
||||||
client.publish(
|
client.publish(
|
||||||
'data',
|
'data',
|
||||||
new Buffer(data,client.config.encoding)
|
new Buffer(data,client.config.encoding)
|
||||||
);
|
);
|
||||||
if(!client.config.sync){
|
if(!client.config.sync){
|
||||||
return;
|
return;
|
||||||
|
@ -222,16 +222,18 @@ function connect(){
|
||||||
|
|
||||||
if (message.type === '__identify') {
|
if (message.type === '__identify') {
|
||||||
client.emit('__identify', {
|
client.emit('__identify', {
|
||||||
id: client.config.id
|
id: client.config.id,
|
||||||
//path: client.path
|
|
||||||
|
// TODO: This can't be right....
|
||||||
|
path: client.config.socketRoot + client.config.appspace + client.config.id
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.log('detected event', message.type, message.data);
|
client.log('detected event', message.type, message.data);
|
||||||
client.publish(
|
client.publish(
|
||||||
message.type,
|
message.type,
|
||||||
message.data
|
message.data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,4 +246,4 @@ function connect(){
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports=Client;
|
module.exports=Client;
|
|
@ -247,7 +247,22 @@ function serverCreated(socket) {
|
||||||
socket
|
socket
|
||||||
);
|
);
|
||||||
} else {
|
} 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,
|
let id = clientDetails.id,
|
||||||
path = clientDetails.path,
|
path = clientDetails.path,
|
||||||
clientConfig = Object.assign(this.config, {id: id, path: path});
|
clientConfig = Object.assign(this.config, {id: id, path: path});
|
||||||
|
@ -261,7 +276,9 @@ function serverCreated(socket) {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.publish('connect', socket, this.of[id]);
|
this.publish('connect', socket, this.of[id]);
|
||||||
}.bind(this));
|
};
|
||||||
|
|
||||||
|
this.on('__identify', __identifyCb);
|
||||||
|
|
||||||
this.emit(socket, '__identify');
|
this.emit(socket, '__identify');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue