diff --git a/app/index.html b/app/index.html deleted file mode 100644 index 277b271..0000000 --- a/app/index.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - Scuttlebutt - - - - - - -
-
-
-
-
-
-
- -
- - - - - - - - diff --git a/app/index.js b/app/index.js index ef53167..5911830 100644 --- a/app/index.js +++ b/app/index.js @@ -5,6 +5,7 @@ var BrowserWindow = require('browser-window') var path = require('path') var config = require('ssb-config') +var setupRpc = require('./lib/muxrpc-ipc') // Report crashes to our server. //require('crash-reporter').start(); @@ -24,9 +25,10 @@ app.on('ready', function ready () { // open the web app 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.on('closed', function() { mainWindow = null }) + setupRpc(sbot, mainWindow) function onNewWindow (e, url) { e.preventDefault() // hell naw diff --git a/app/lib/muxrpc-ipc.js b/app/lib/muxrpc-ipc.js new file mode 100644 index 0000000..4d24f48 --- /dev/null +++ b/app/lib/muxrpc-ipc.js @@ -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) + })) +} \ No newline at end of file diff --git a/package.json b/package.json index 24f35ae..de8d01e 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,9 @@ "dependencies": { "multiblob": "^1.4.3", "multicb": "^1.1.0", + "muxrpc": "^5.0.1", + "pull-pushable": "^1.1.4", + "pull-serializer": "^0.3.2", "pull-stream": "^2.27.0", "scuttlebot": "^4.2.3", "ssb-config": "^1.0.3",