Comparing version 0.0.9 to 0.0.10
@@ -15,18 +15,19 @@ var net = require('net'); | ||
var client = this.client = srv.connect(options, function() { | ||
consumer.connect(client); | ||
this.client = srv.connect(options, () => { | ||
consumer.connect(this.client); | ||
}) | ||
this.client.on('data', data => { | ||
client.pause(); | ||
this.client.pause(); | ||
data = buf + data.toString(); | ||
consumer.read({data, trunk: client}).then(waste => { | ||
consumer.read({data, trunk: this.client, options}).then(waste => { | ||
buf = waste || buf; | ||
client.resume(); | ||
this.client.resume(); | ||
}) | ||
}) | ||
this.client.on('end', () => { | ||
this.client.destroy(); | ||
this.client.on('end', (...args) => { | ||
this.emit('end', ...args) | ||
// this.client.destroy(); | ||
}) | ||
@@ -36,2 +37,3 @@ | ||
console.log('client error: '+error); | ||
this.emit('error', error) | ||
@@ -38,0 +40,0 @@ process.nextTick(() => { |
@@ -62,3 +62,8 @@ var util = require('util'); | ||
if(len + idx + 2 <= data.length) { | ||
result.content = data.slice(idx + 2, idx + 2 + len); | ||
var content = data.slice(idx + 2, idx + 2 + len); | ||
if(content.length) { | ||
result.content = content; | ||
} | ||
result.waste = data.slice(idx + 2 + len); | ||
@@ -65,0 +70,0 @@ done = true; |
var net = require('net'); | ||
var util = require('util'); | ||
var EventEmitter = require('events'); | ||
var Server = require('./server'); | ||
@@ -8,3 +9,6 @@ function Router() { | ||
this.routes = {}; | ||
this.handlers = []; | ||
this.$accept = []; | ||
this.$decline = []; | ||
@@ -24,2 +28,6 @@ this.enqueue = this.queue(); | ||
Router.prototype.listen = function(name, options) { | ||
this.addServer(name, new Server(this, options)); | ||
} | ||
// get route data | ||
@@ -76,20 +84,11 @@ Router.prototype.set = function(name, data) { | ||
// default accept handler | ||
Router.prototype.$accept = async function(msg) { | ||
return msg; | ||
} | ||
// set accept handler | ||
Router.prototype.accept = function(accept) { | ||
this.$accept = accept; | ||
this.$accept.push(accept); | ||
this.acceptChain = this.createChain(this.$accept); | ||
} | ||
// default decline handler | ||
Router.prototype.$decline = async function(msg) { | ||
return msg; | ||
} | ||
// set decline handler | ||
Router.prototype.decline = function(decline) { | ||
this.$decline = decline; | ||
this.$decline.push(decline); | ||
this.declineChain = this.createChain(this.$decline); | ||
} | ||
@@ -96,0 +95,0 @@ |
@@ -17,5 +17,5 @@ var path = require('path'); | ||
var buf = '', id = utils.randomAscii(12); | ||
var trunk = {id, socket, end: () => {socket.destroy()}}; | ||
var trunk = {id, socket, options, end: () => {socket.destroy()}}; | ||
consumer.$accept(trunk).then(result => { | ||
consumer.acceptChain(trunk).then(result => { | ||
socket.on('data', function(data) { | ||
@@ -25,3 +25,3 @@ socket.pause(); | ||
trunk.read({data, trunk}).then(waste => { | ||
trunk.read({data, trunk, options}).then(waste => { | ||
buf = waste || buf; | ||
@@ -37,3 +37,3 @@ socket.resume(); | ||
socket.on('end', function() { | ||
consumer.$decline(trunk); | ||
consumer.declineChain(trunk); | ||
}) | ||
@@ -40,0 +40,0 @@ }).catch(err => { |
@@ -18,3 +18,12 @@ var util = require('util'); | ||
Ua.prototype.setClient = function(name, trunk) { | ||
console.log('SET CLIENT:'+name); | ||
this.clients[name] = trunk; | ||
trunk.on('error', (...args) => { | ||
this.emit('error', trunk, ...args); | ||
}) | ||
trunk.on('end', (...args) => { | ||
this.emit('end', trunk, ...args); | ||
}) | ||
} | ||
@@ -21,0 +30,0 @@ |
{ | ||
"name": "sipware", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48018
479