pr
This commit is contained in:
parent
4b5f95a337
commit
15e628b528
3 changed files with 49 additions and 18 deletions
|
@ -3,17 +3,13 @@
|
|||
const net = require('net'),
|
||||
tls = require('tls'),
|
||||
eventParser = require('./eventParser.js'),
|
||||
Events = require('event-pubsub'),
|
||||
Message = require('js-message'),
|
||||
fs = require('fs'),
|
||||
Queue = require('js-queue');
|
||||
|
||||
let Events = require('event-pubsub/es5');
|
||||
if(process.version[1]>4){
|
||||
Events = require('event-pubsub');
|
||||
}
|
||||
|
||||
class Client extends Events{
|
||||
constructor(config,log){
|
||||
constructor(config,log,socket){
|
||||
super();
|
||||
Object.assign(
|
||||
this,
|
||||
|
@ -21,7 +17,7 @@ class Client extends Events{
|
|||
Client : Client,
|
||||
config : config,
|
||||
queue : new Queue,
|
||||
socket : false,
|
||||
socket : typeof socket == 'undefined' ? false : socket,
|
||||
connect : connect,
|
||||
emit : emit,
|
||||
log : log,
|
||||
|
@ -70,6 +66,12 @@ function connect(){
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO: Typeof + is connection up check
|
||||
if (client.socket !== false) {
|
||||
client.log('Connection already set');
|
||||
return;
|
||||
}
|
||||
|
||||
if(!client.port){
|
||||
client.log('Connecting client on Unix Socket :', client.path);
|
||||
|
||||
|
@ -218,6 +220,14 @@ function connect(){
|
|||
let message=new Message;
|
||||
message.load(events[i]);
|
||||
|
||||
if (message.type === '__identify') {
|
||||
client.emit('__identify', {
|
||||
id: client.id,
|
||||
path: client.path
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
client.log('detected event', message.type, message.data);
|
||||
client.publish(
|
||||
message.type,
|
||||
|
|
|
@ -5,12 +5,9 @@ const net = require('net'),
|
|||
fs = require('fs'),
|
||||
dgram = require('dgram'),
|
||||
eventParser = require('./eventParser.js'),
|
||||
Message = require('js-message');
|
||||
|
||||
let Events = require('event-pubsub/es5');
|
||||
if(process.version[1]>4){
|
||||
Events = require('event-pubsub');
|
||||
}
|
||||
Events = require('event-pubsub'),
|
||||
Message = require('js-message'),
|
||||
Client = require('../dao/client.js');
|
||||
|
||||
class Server extends Events{
|
||||
constructor(path,config,log,port){
|
||||
|
@ -27,7 +24,8 @@ class Server extends Events{
|
|||
server : false,
|
||||
sockets : [],
|
||||
emit : emit,
|
||||
broadcast : broadcast
|
||||
broadcast : broadcast,
|
||||
of : {}
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -243,10 +241,28 @@ function serverCreated(socket) {
|
|||
}.bind(this)
|
||||
);
|
||||
|
||||
this.publish(
|
||||
'connect',
|
||||
socket
|
||||
);
|
||||
if (this.config.noHandshake) {
|
||||
this.publish(
|
||||
'connect',
|
||||
socket
|
||||
);
|
||||
} else {
|
||||
this.on('__identify', function(clientDetails) {
|
||||
var id = clientDetails.id;
|
||||
|
||||
this.of[id] = new Client(this.config, this.log, socket);
|
||||
this.of[id].id = id;
|
||||
this.of[id].path = clientDetails.path;
|
||||
|
||||
this.of[id].on('disconnect', function() {
|
||||
delete this.of[id];
|
||||
});
|
||||
|
||||
this.publish('connect', socket, this.of[id]);
|
||||
}.bind(this));
|
||||
|
||||
this.emit(socket, '__identify');
|
||||
}
|
||||
|
||||
if(this.config.rawBuffer){
|
||||
return;
|
||||
|
|
|
@ -108,6 +108,11 @@ class Defaults{
|
|||
enumerable:true,
|
||||
writable:true,
|
||||
value:false
|
||||
},
|
||||
noHandshake : {
|
||||
enumerable:true,
|
||||
writable:true,
|
||||
value:false
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue