use pull-ipc to communicate with browserwindow
This commit is contained in:
parent
e0e030daf0
commit
025e7c5d39
@ -1,7 +1,7 @@
|
|||||||
var ipc = require('ipc')
|
var ipc = require('ipc')
|
||||||
var muxrpc = require('muxrpc')
|
var muxrpc = require('muxrpc')
|
||||||
var pull = require('pull-stream')
|
var pull = require('pull-stream')
|
||||||
var pushable = require('pull-pushable')
|
var pullipc = require('pull-ipc')
|
||||||
|
|
||||||
var clientApi = {
|
var clientApi = {
|
||||||
navigate: 'async',
|
navigate: 'async',
|
||||||
@ -19,33 +19,10 @@ module.exports = function (window, sbot, params) {
|
|||||||
|
|
||||||
// start the stream
|
// start the stream
|
||||||
window.rpcStream = rpc.createStream()
|
window.rpcStream = rpc.createStream()
|
||||||
var ipcPush = pushable()
|
var ipcStream = pullipc('ssb-muxrpc', ipc, window, function (err) {
|
||||||
ipc.on('muxrpc-ssb', function (e, msg) {
|
console.log('ipc-stream ended', err)
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
pull(ipcPush, window.rpcStream, pull.drain(
|
pull(ipcStream, window.rpcStream, ipcStream)
|
||||||
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) } }
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
window.resetRpc = function () {
|
window.resetRpc = function () {
|
||||||
console.log('close rpc')
|
console.log('close rpc')
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
"multiblob": "^1.5.0",
|
"multiblob": "^1.5.0",
|
||||||
"multicb": "^1.1.0",
|
"multicb": "^1.1.0",
|
||||||
"muxrpc": "^5.0.1",
|
"muxrpc": "^5.0.1",
|
||||||
|
"pull-ipc": "0.0.1",
|
||||||
"pull-pushable": "^1.1.4",
|
"pull-pushable": "^1.1.4",
|
||||||
"pull-stream": "^2.27.0",
|
"pull-stream": "^2.27.0",
|
||||||
"scuttlebot": "~7.0.2",
|
"scuttlebot": "~7.0.2",
|
||||||
|
Loading…
Reference in New Issue
Block a user