From 025e7c5d3932344c24b6b95ea25ed64f70751126 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Sat, 22 Aug 2015 18:24:12 -0500 Subject: [PATCH] use pull-ipc to communicate with browserwindow --- app/lib/muxrpc-ipc.js | 31 ++++--------------------------- package.json | 1 + 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/app/lib/muxrpc-ipc.js b/app/lib/muxrpc-ipc.js index e2bf31c..4472536 100644 --- a/app/lib/muxrpc-ipc.js +++ b/app/lib/muxrpc-ipc.js @@ -1,7 +1,7 @@ var ipc = require('ipc') var muxrpc = require('muxrpc') var pull = require('pull-stream') -var pushable = require('pull-pushable') +var pullipc = require('pull-ipc') var clientApi = { navigate: 'async', @@ -19,33 +19,10 @@ module.exports = function (window, sbot, params) { // start the stream window.rpcStream = rpc.createStream() - var ipcPush = pushable() - ipc.on('muxrpc-ssb', function (e, msg) { - if (e.sender == window.webContents) { - try { - if (typeof msg == 'string') - msg = JSON.parse(msg) - } catch (e) { - return - } - if (msg.bvalue) { - msg.value = new Buffer(msg.bvalue, 'base64') - delete msg.bvalue - } - ipcPush.push(msg) - } + var ipcStream = pullipc('ssb-muxrpc', ipc, window, function (err) { + console.log('ipc-stream ended', err) }) - pull(ipcPush, window.rpcStream, pull.drain( - function (msg) { - if (msg.value && Buffer.isBuffer(msg.value)) { - // convert buffers to base64 - msg.bvalue = msg.value.toString('base64') - delete msg.value - } - window.webContents.send('muxrpc-ssb', JSON.stringify(msg)) - }, - function (err) { if (err) { console.error(err) } } - )) + pull(ipcStream, window.rpcStream, ipcStream) } window.resetRpc = function () { console.log('close rpc') diff --git a/package.json b/package.json index b77c1f2..bcd4b50 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "multiblob": "^1.5.0", "multicb": "^1.1.0", "muxrpc": "^5.0.1", + "pull-ipc": "0.0.1", "pull-pushable": "^1.1.4", "pull-stream": "^2.27.0", "scuttlebot": "~7.0.2",