Comparing version 0.0.16 to 0.0.17
@@ -7,3 +7,2 @@ var util = require('util'); | ||
function Ua() { | ||
this.clients = {}; | ||
this.t = new Map(); | ||
@@ -18,5 +17,5 @@ this.req = new Map(); | ||
Ua.prototype.setClient = function(name, client) { | ||
console.log('SET CLIENT:'+name); | ||
this.clients[name] = client; | ||
Ua.prototype.setClient = function(client) { | ||
console.log('SET CLIENT'); | ||
this.client = client; | ||
@@ -60,4 +59,4 @@ client.on('error', (...args) => { | ||
Ua.prototype.trans = function(client) { | ||
var trans = new Trans(this, this.clients[client]); | ||
Ua.prototype.trans = function() { | ||
var trans = new Trans(this); | ||
this.t.set(trans.id, trans); | ||
@@ -67,21 +66,17 @@ return trans; | ||
Ua.prototype.request = function(client, ttl, req) { | ||
var trans = this.trans(client); | ||
Ua.prototype.request = function(headers, content, ttl) { | ||
var trans = this.trans(this.client); | ||
ttl = ttl || undefined; | ||
if(!req) { | ||
req = ttl; | ||
ttl = undefined; | ||
} | ||
trans.use(async function(t, next) {t.request(req); await next()}) | ||
trans.use(async function(t, next) {t.request({headers, content}); await next()}) | ||
trans.use(trans.end); | ||
return trans.run(ttl).then(t => { | ||
return Promise.resolve(t.table.get(req.headers.id).resp); | ||
return Promise.resolve(t.table.get(headers.id).resp); | ||
}) | ||
} | ||
Ua.prototype.notification = function(client, req) { | ||
var trans = this.trans(client); | ||
trans.use(async function(t, next) {t.notification(req); await next()}); | ||
Ua.prototype.notification = function(headers, content) { | ||
var trans = this.trans(this.client); | ||
trans.use(async function(t, next) {t.notification({headers, content}); await next()}); | ||
trans.use(trans.end); | ||
@@ -92,5 +87,5 @@ return trans.run(); | ||
// transaction | ||
function Trans(ua, client) { | ||
function Trans(ua) { | ||
this.ua = ua; | ||
this.client = client; | ||
this.client = ua.client; | ||
this.id = utils.randomAscii(16); | ||
@@ -97,0 +92,0 @@ this.counter = 0; |
@@ -59,3 +59,3 @@ { | ||
"optionalDependencies": {}, | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"directories": { | ||
@@ -62,0 +62,0 @@ "lib": "lib" |
52942
591