@ -76,7 +76,11 @@ function onRpcRequest(remotePort, payload){
zeroClient.sendAsync(payload, function onPayloadHandled(err, response){
if (err) throw err
// console.log('MetaMaskPlugin - RPC complete:', payload, '->', response)
try {
remotePort.postMessage(response)
} catch (_) {
// port disconnected
}
})
@ -20,3 +20,7 @@ var pluginStream = new PortStream(pluginPort)
// forward communication across
pageStream.pipe(pluginStream)
pluginStream.pipe(pageStream)
// log errors
pageStream.on('error', console.error.bind(console))
pluginStream.on('error', console.error.bind(console))
@ -12,6 +12,9 @@ var pluginStream = new LocalMessageDuplexStream({
var remoteProvider = new StreamProvider()
remoteProvider.pipe(pluginStream).pipe(remoteProvider)
remoteProvider.on('error', console.error.bind(console))
// handle synchronous methods remotely
// handle accounts cache
@ -37,8 +37,13 @@ PortDuplexStream.prototype._read = noop
PortDuplexStream.prototype._write = function(msg, encoding, cb){
// console.log('PortDuplexStream - sent message', msg)
this._port.postMessage(msg)
cb()
} catch(err){
// this.emit('error', err)
cb(new Error('PortDuplexStream - disconnected'))
// util