Comparing version 0.4.24 to 0.4.26
const debug = require('debug') ('sipware:transaction') | ||
class TransResp extends require('stream').Transform { | ||
constructor(resps = []) { | ||
class SipwareTransContainer extends require('stream').Transform { | ||
constructor(pkts = []) { | ||
super({ | ||
@@ -12,3 +12,3 @@ //writableHighWaterMark: 3, | ||
this.resps = resps; | ||
this.pkts = pkts; | ||
this.chunks = []; | ||
@@ -21,9 +21,9 @@ this.bogus = []; | ||
idx: 0, | ||
resps: this.resps, | ||
pkts: this.pkts, | ||
next() { | ||
debug('Iterator', this.idx, this.resps.length); | ||
debug('Iterator', this.idx, this.pkts.length); | ||
if(this.idx < this.resps.length) { | ||
debug('Item', this.resps[this.idx]) | ||
return {done: false, value: this.resps[this.idx++]} | ||
if(this.idx < this.pkts.length) { | ||
debug('Item', this.pkts[this.idx]) | ||
return {done: false, value: this.pkts[this.idx++]} | ||
} else { | ||
@@ -38,19 +38,19 @@ debug('Item done'); | ||
get length() { | ||
return this.resps.length; | ||
return this.pkts.length; | ||
} | ||
forEach(callback) { | ||
return this.resps.forEach(callback); | ||
return this.pkts.forEach(callback); | ||
} | ||
filter(callback) { | ||
return this.resps.filter(callback); | ||
return this.pkts.filter(callback); | ||
} | ||
find(callback) { | ||
return this.resps.find(callback); | ||
return this.pkts.find(callback); | ||
} | ||
getResp(resp) { | ||
return this.resps.find(r => resp.From.address == resp.From.address); | ||
getPkt(resp) { | ||
return this.pkts.find(r => resp.From.address == resp.From.address); | ||
} | ||
@@ -60,3 +60,3 @@ | ||
debug('Input', resp.from, resp.seq); | ||
this.resps.push(resp); | ||
this.pkts.push(resp); | ||
} | ||
@@ -70,3 +70,3 @@ | ||
class Transaction { | ||
module.exports = class SipwareTransaction { | ||
constructor({id, seq, counter, persist = false, ttl = 10000}) { | ||
@@ -80,15 +80,15 @@ this.id = id; | ||
this.ts = Math.floor(new Date().getTime()/1000); | ||
this.response = this.generator(); | ||
this.rx = this.createResponses(); | ||
this.input = this.generator(); | ||
this.container = this.createContainer(); | ||
this.flushed = 0; | ||
} | ||
createResponses() { | ||
return new TransResp(); | ||
createContainer() { | ||
return new SipwareTransContainer(); | ||
} | ||
flush() { | ||
var chunks = this.rx.chunks || []; | ||
var chunks = this.container.chunks || []; | ||
this.rx.chunks = []; | ||
this.container.chunks = []; | ||
debug('Flush', this.flushed, chunks.length); | ||
@@ -100,3 +100,3 @@ this.flushed++; | ||
debug('Flush item', i, chunks[i].resp.seq, chunks[i].resp.from); | ||
this.rx.emit('chunk', chunks[i]); | ||
this.container.emit('chunk', chunks[i]); | ||
} | ||
@@ -125,6 +125,6 @@ }) | ||
add(chunk) { | ||
var resp = this.rx.getResp(chunk); | ||
var resp = this.container.getPkt(chunk); | ||
if(resp) { | ||
this.rx.add({resp, chunk}); | ||
this.container.add({resp, chunk}); | ||
@@ -136,14 +136,14 @@ if(this.exited) { | ||
debug('Bogus chunk'); | ||
this.rx.bogus.push(chunk); | ||
this.container.bogus.push(chunk); | ||
} | ||
} | ||
input(resp) { | ||
dispatch(resp) { | ||
if(resp.seq == undefined) { | ||
this.counter--; | ||
this.rx.input(resp); | ||
this.container.input(resp); | ||
} else if(resp.seq == '0') { | ||
this.counter--; | ||
this.dialogs++; | ||
this.rx.input(resp); | ||
this.container.input(resp); | ||
this.persist = this.persist || true; | ||
@@ -177,3 +177,3 @@ } else if(resp.seq == '*') { | ||
if(resp) { | ||
this.input(resp); | ||
this.dispatch(resp); | ||
} else { | ||
@@ -199,3 +199,3 @@ break; | ||
this.save(() => { | ||
res(this.rx); | ||
res(this.container); | ||
this.flush(); | ||
@@ -205,3 +205,3 @@ }) | ||
this.timer = setTimeout(() => { | ||
res(this.rx); | ||
res(this.container); | ||
this.flush(); | ||
@@ -222,3 +222,3 @@ }, ttl) | ||
this.exited = true; | ||
this.restore(this.rx); | ||
this.restore(this.container); | ||
} | ||
@@ -231,7 +231,5 @@ } | ||
this.response.next(); | ||
// delete this.response; | ||
this.input.next(); | ||
// delete this.input; | ||
} | ||
} | ||
module.exports = Transaction; |
@@ -53,3 +53,3 @@ const debug = require('debug') ('sipware:ua') | ||
debug('Sipware: incoming transaction', id, ctx.headers); | ||
trans.response.next(ctx); | ||
trans.input.next(ctx); | ||
} else if(ctx.headers.code) { | ||
@@ -86,3 +86,3 @@ debug('Sipware: invalid packet', ctx.headers); | ||
return ctx.trans.rx; | ||
return ctx.trans.container; | ||
} | ||
@@ -89,0 +89,0 @@ |
@@ -67,3 +67,3 @@ { | ||
"optionalDependencies": {}, | ||
"version": "0.4.24", | ||
"version": "0.4.26", | ||
"directories": { | ||
@@ -70,0 +70,0 @@ "lib": "lib" |
123552
2984