use pull-ipc to communicate with browserwindow

This commit is contained in:
Paul Frazee 2015-08-22 18:24:12 -05:00
parent e0e030daf0
commit 025e7c5d39
2 changed files with 5 additions and 27 deletions

View File

@ -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')

View File

@ -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",