setup muxrpc over ipc with the browserwindow

This commit is contained in:
Paul Frazee 2015-06-25 18:47:11 -05:00
parent e64cf9e059
commit 7f5bb1ffb2
4 changed files with 40 additions and 30 deletions

View File

@ -1,29 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Scuttlebutt</title>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/png" href="../node_modules/scuttlebot/node_modules/ssbplug-phoenix/img/icon.png"/>
<link rel="stylesheet" type="text/css" href="../node_modules/scuttlebot/node_modules/ssbplug-phoenix/css/home.css">
<link rel="stylesheet" type="text/css" href="../node_modules/scuttlebot/node_modules/ssbplug-phoenix/css/sweet-alert.css">
</head>
<body>
<div id="app-status"></div>
<div id="please-wait">
<div class="spinner">
<div class="cube1"></div>
<div class="cube2"></div>
</div>
</div>
<div id="page-nav"></div>
<div id="page-container"></div>
<script src="http://localhost:8008/manifest.js"></script>
<script src="../node_modules/scuttlebot/node_modules/ssbplug-phoenix/js/sweet-alert.js"></script>
<script src="../node_modules/scuttlebot/node_modules/ssbplug-phoenix/js/canvas-to-blob.js"></script>
<script src="../node_modules/scuttlebot/node_modules/ssbplug-phoenix/js/sigma.min.js"></script>
<script src="../node_modules/scuttlebot/node_modules/ssbplug-phoenix/js/home.js"></script>
<script>
// require('../node_modules/scuttlebot/node_modules/ssbplug-phoenix/src/home')
</script>
</body>
</html>

View File

@ -5,6 +5,7 @@ var BrowserWindow = require('browser-window')
var path = require('path') var path = require('path')
var config = require('ssb-config') var config = require('ssb-config')
var setupRpc = require('./lib/muxrpc-ipc')
// Report crashes to our server. // Report crashes to our server.
//require('crash-reporter').start(); //require('crash-reporter').start();
@ -24,9 +25,10 @@ app.on('ready', function ready () {
// open the web app // open the web app
mainWindow = new BrowserWindow({width: 1000, height: 720}) mainWindow = new BrowserWindow({width: 1000, height: 720})
mainWindow.loadUrl('file://' + __dirname + '/index.html') mainWindow.loadUrl('file://' + path.join(__dirname, '../node_modules/ssbplug-phoenix/home.html'))
mainWindow.webContents.on('new-window', onNewWindow) mainWindow.webContents.on('new-window', onNewWindow)
mainWindow.on('closed', function() { mainWindow = null }) mainWindow.on('closed', function() { mainWindow = null })
setupRpc(sbot, mainWindow)
function onNewWindow (e, url) { function onNewWindow (e, url) {
e.preventDefault() // hell naw e.preventDefault() // hell naw

34
app/lib/muxrpc-ipc.js Normal file
View File

@ -0,0 +1,34 @@
var ipc = require('ipc')
var muxrpc = require('muxrpc')
var pull = require('pull-stream')
var Serializer = require('pull-serializer')
var pushable = require('pull-pushable')
var Api = require('scuttlebot/lib/api')
module.exports = function (sbot, window) {
// construct api
var api = Api(sbot)
for (var k in sbot.manifest) {
if (typeof sbot.manifest[k] == 'object')
api[k] = sbot[k] // copy over the plugin APIs
}
// create rpc object
var rpc = muxrpc(null, sbot.manifest, serialize)(api)
rpc.authorized = { id: sbot.feed.id, role: 'master' }
rpc.permissions({allow: null, deny: null})
function serialize (stream) {
return Serializer(stream, JSON, {split: '\n\n'})
}
// setup rpc stream over ipc
var rpcStream = rpc.createStream()
var ipcPush = pushable()
ipc.on('muxrpc-ssb', function (e, msg) {
if (e.sender == window.webContents)
ipcPush.push(msg)
})
pull(ipcPush, rpcStream, pull.drain(function (msg) {
window.webContents.send('muxrpc-ssb', msg)
}))
}

View File

@ -27,6 +27,9 @@
"dependencies": { "dependencies": {
"multiblob": "^1.4.3", "multiblob": "^1.4.3",
"multicb": "^1.1.0", "multicb": "^1.1.0",
"muxrpc": "^5.0.1",
"pull-pushable": "^1.1.4",
"pull-serializer": "^0.3.2",
"pull-stream": "^2.27.0", "pull-stream": "^2.27.0",
"scuttlebot": "^4.2.3", "scuttlebot": "^4.2.3",
"ssb-config": "^1.0.3", "ssb-config": "^1.0.3",