|
|
@ -11,7 +11,7 @@ function StreamProvider(){ |
|
|
|
objectMode: true, |
|
|
|
objectMode: true, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
this._handlers = {} |
|
|
|
this._payloads = {} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// public
|
|
|
|
// public
|
|
|
@ -21,19 +21,29 @@ StreamProvider.prototype.send = function(payload){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
StreamProvider.prototype.sendAsync = function(payload, callback){ |
|
|
|
StreamProvider.prototype.sendAsync = function(payload, callback){ |
|
|
|
// console.log('StreamProvider - sending payload', payload)
|
|
|
|
// console.log('StreamProvider - sending payload', payload)
|
|
|
|
this._handlers[payload.id] = callback |
|
|
|
this._payloads[payload.id] = [payload, callback] |
|
|
|
|
|
|
|
// console.log('payload for plugin:', payload)
|
|
|
|
this.push(payload) |
|
|
|
this.push(payload) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// private
|
|
|
|
// private
|
|
|
|
|
|
|
|
|
|
|
|
StreamProvider.prototype._onResponse = function(payload){ |
|
|
|
StreamProvider.prototype._onResponse = function(response){ |
|
|
|
// console.log('StreamProvider - got response', payload)
|
|
|
|
// console.log('StreamProvider - got response', payload)
|
|
|
|
var callback = this._handlers[payload.id] |
|
|
|
var data = this._payloads[response.id] |
|
|
|
if (!callback) throw new Error('StreamProvider - Unknown response id') |
|
|
|
if (!data) throw new Error('StreamProvider - Unknown response id') |
|
|
|
delete this._handlers[payload.id] |
|
|
|
delete this._payloads[response.id] |
|
|
|
callback(null, payload) |
|
|
|
var payload = data[0] |
|
|
|
|
|
|
|
var callback = data[1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// logging
|
|
|
|
|
|
|
|
var res = Array.isArray(response) ? response : [response] |
|
|
|
|
|
|
|
;(Array.isArray(payload) ? payload : [payload]).forEach(function(payload, index){ |
|
|
|
|
|
|
|
console.log('plugin response:', payload.id, payload.method, payload.params, '->', res[index].result) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
callback(null, response) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// stream plumbing
|
|
|
|
// stream plumbing
|
|
|
|