Comparing version 0.4.26 to 0.4.30
@@ -66,4 +66,5 @@ const debug = require('debug') ('sipware:transaction') | ||
module.exports = class SipwareTransaction { | ||
module.exports = class SipwareTransaction extends require('events') { | ||
constructor({id, seq, counter, persist = false, ttl = 10000}) { | ||
super(); | ||
this.id = id; | ||
@@ -89,11 +90,7 @@ this.seq = seq; | ||
this.container.chunks = []; | ||
debug('Flush', this.flushed, chunks.length); | ||
this.flushed++; | ||
process.nextTick(() => { | ||
for(var i = 0; i < chunks.length; i++) { | ||
debug('Flush item', i, chunks[i].resp.seq, chunks[i].resp.from); | ||
this.container.emit('chunk', chunks[i]); | ||
} | ||
}) | ||
for(var i = 0; i < chunks.length; i++) { | ||
debug('Flush item', i, chunks[i].resp.seq, chunks[i].resp.from); | ||
this.container.emit('chunk', chunks[i]); | ||
} | ||
} | ||
@@ -125,5 +122,5 @@ | ||
if(this.exited) { | ||
process.nextTick(() => { | ||
this.flush() | ||
} | ||
}) | ||
} else { | ||
@@ -191,2 +188,6 @@ debug('Bogus chunk'); | ||
return new Promise((res, rej) => { | ||
if(this.timer) { | ||
clearTimeout(this.timer); | ||
} | ||
this.save(() => { | ||
@@ -205,4 +206,2 @@ res(this.container); | ||
leave() { | ||
debug('Trans leave', this.id, this.seq) | ||
if(this.timer) { | ||
@@ -213,6 +212,7 @@ clearTimeout(this.timer); | ||
if(!this.exited) { | ||
this.exited = true; | ||
this.restore(this.container); | ||
} | ||
this.exited = true; | ||
this.restore(this.container); | ||
process.nextTick(() => { | ||
this.flush(); | ||
}) | ||
} | ||
@@ -223,3 +223,2 @@ | ||
this.leave(); | ||
this.input.next(); | ||
@@ -226,0 +225,0 @@ // delete this.input; |
@@ -70,2 +70,3 @@ const debug = require('debug') ('sipware:ua') | ||
ctx.createTrans(ctx.lookup); | ||
this.t.set(ctx.lookup.id, ctx.trans); | ||
} | ||
@@ -75,6 +76,7 @@ | ||
if(ctx.lookup.counter <= 0) return []; | ||
if(ctx.lookup.counter <= 0) { | ||
ctx.trans.destroy(); | ||
return ctx.trans.container; | ||
} | ||
this.t.set(ctx.lookup.id, ctx.trans); | ||
if(ctx.lookup.loopback.length) this.loopback(ctx); | ||
@@ -81,0 +83,0 @@ if(ctx.lookup.proxy) this.client.socket.write(this.write2(ctx)); |
@@ -67,3 +67,3 @@ { | ||
"optionalDependencies": {}, | ||
"version": "0.4.26", | ||
"version": "0.4.30", | ||
"directories": { | ||
@@ -70,0 +70,0 @@ "lib": "lib" |
123588
2987