2015-06-26 10:47:11 +11:00
|
|
|
var ipc = require('ipc')
|
|
|
|
var muxrpc = require('muxrpc')
|
|
|
|
var pull = require('pull-stream')
|
2015-08-23 10:24:12 +11:00
|
|
|
var pullipc = require('pull-ipc')
|
2015-06-26 10:47:11 +11:00
|
|
|
|
2015-07-20 03:42:19 +11:00
|
|
|
var clientApi = {
|
2015-07-20 04:16:12 +11:00
|
|
|
navigate: 'async',
|
2015-08-28 05:56:18 +11:00
|
|
|
contextualToggleDevTools: 'async',
|
|
|
|
triggerFind: 'async'
|
2015-07-20 03:42:19 +11:00
|
|
|
}
|
|
|
|
|
2015-06-27 05:30:34 +11:00
|
|
|
module.exports = function (window, sbot, params) {
|
2015-07-09 06:43:20 +11:00
|
|
|
// add rpc APIs to window
|
|
|
|
window.createRpc = function () {
|
|
|
|
// create rpc object
|
2015-08-04 11:54:30 +11:00
|
|
|
var rpc = window.rpc = muxrpc(clientApi, sbot.manifest(), serialize)(sbot)
|
|
|
|
rpc.authorized = { id: sbot.id, role: 'master' }
|
2015-07-09 06:43:20 +11:00
|
|
|
function serialize (stream) { return stream }
|
|
|
|
|
|
|
|
// start the stream
|
|
|
|
window.rpcStream = rpc.createStream()
|
2015-08-23 10:24:12 +11:00
|
|
|
var ipcStream = pullipc('ssb-muxrpc', ipc, window, function (err) {
|
|
|
|
console.log('ipc-stream ended', err)
|
2015-07-09 06:43:20 +11:00
|
|
|
})
|
2015-08-23 10:24:12 +11:00
|
|
|
pull(ipcStream, window.rpcStream, ipcStream)
|
2015-07-09 06:43:20 +11:00
|
|
|
}
|
|
|
|
window.resetRpc = function () {
|
|
|
|
console.log('close rpc')
|
2015-08-25 07:47:49 +11:00
|
|
|
window.rpcStream.source('close')
|
2015-07-09 06:43:20 +11:00
|
|
|
window.rpc.close()
|
|
|
|
window.createRpc()
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup default stream
|
|
|
|
window.createRpc()
|
2015-06-26 10:53:06 +11:00
|
|
|
|
|
|
|
// setup helper messages
|
2015-07-02 14:07:27 +11:00
|
|
|
ipc.on('fetch-manifest', function(e) {
|
2015-06-26 10:53:06 +11:00
|
|
|
if (e.sender == window.webContents)
|
2015-08-04 11:54:30 +11:00
|
|
|
e.returnValue = sbot.manifest()
|
2015-06-26 10:53:06 +11:00
|
|
|
});
|
2015-06-27 05:30:34 +11:00
|
|
|
ipc.on('fetch-params', function(e) {
|
|
|
|
if (e.sender == window.webContents)
|
|
|
|
e.returnValue = params
|
|
|
|
});
|
2015-06-26 10:47:11 +11:00
|
|
|
}
|