add buffer-transfer support to muxrpc-ipc

This commit is contained in:
Paul Frazee 2015-07-02 11:47:35 -05:00
parent d03f7ab2c2
commit fadfda353d

View File

@ -22,11 +22,23 @@ module.exports = function (window, sbot, params) {
var rpcStream = rpc.createStream()
var ipcPush = pushable()
ipc.on('muxrpc-ssb', function (e, msg) {
if (e.sender == window.webContents)
if (e.sender == window.webContents) {
if (msg.bvalue) {
msg.value = new Buffer(msg.bvalue, 'base64')
delete msg.bvalue
}
ipcPush.push(msg)
}
})
pull(ipcPush, rpcStream, pull.drain(
function (msg) { window.webContents.send('muxrpc-ssb', msg) },
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', msg)
},
function (err) { if (err) { console.error(err) } }
))