Browse Source

use pull-ipc to communicate with browserwindow

Paul Frazee 4 years ago
parent
commit
025e7c5d39
2 changed files with 5 additions and 27 deletions
  1. 4
    27
      app/lib/muxrpc-ipc.js
  2. 1
    0
      package.json

+ 4
- 27
app/lib/muxrpc-ipc.js View File

@@ -1,7 +1,7 @@
1 1
 var ipc        = require('ipc')
2 2
 var muxrpc     = require('muxrpc')
3 3
 var pull       = require('pull-stream')
4
-var pushable   = require('pull-pushable')
4
+var pullipc    = require('pull-ipc')
5 5
 
6 6
 var clientApi = {
7 7
   navigate: 'async',
@@ -19,33 +19,10 @@ module.exports = function (window, sbot, params) {
19 19
 
20 20
     // start the stream
21 21
     window.rpcStream = rpc.createStream()
22
-    var ipcPush = pushable()
23
-    ipc.on('muxrpc-ssb', function (e, msg) {
24
-      if (e.sender == window.webContents) {
25
-        try {
26
-          if (typeof msg == 'string')
27
-            msg = JSON.parse(msg)
28
-        } catch (e) {
29
-          return
30
-        }
31
-        if (msg.bvalue) {
32
-          msg.value = new Buffer(msg.bvalue, 'base64')
33
-          delete msg.bvalue
34
-        }
35
-        ipcPush.push(msg)
36
-      }
22
+    var ipcStream = pullipc('ssb-muxrpc', ipc, window, function (err) {
23
+      console.log('ipc-stream ended', err)
37 24
     })
38
-    pull(ipcPush, window.rpcStream, pull.drain(
39
-      function (msg) { 
40
-        if (msg.value && Buffer.isBuffer(msg.value)) {
41
-          // convert buffers to base64
42
-          msg.bvalue = msg.value.toString('base64')
43
-          delete msg.value
44
-        }
45
-        window.webContents.send('muxrpc-ssb', JSON.stringify(msg))
46
-      },
47
-      function (err) { if (err) { console.error(err) } }
48
-    ))
25
+    pull(ipcStream, window.rpcStream, ipcStream)
49 26
   }
50 27
   window.resetRpc = function () {
51 28
     console.log('close rpc')

+ 1
- 0
package.json View File

@@ -28,6 +28,7 @@
28 28
     "multiblob": "^1.5.0",
29 29
     "multicb": "^1.1.0",
30 30
     "muxrpc": "^5.0.1",
31
+    "pull-ipc": "0.0.1",
31 32
     "pull-pushable": "^1.1.4",
32 33
     "pull-stream": "^2.27.0",
33 34
     "scuttlebot": "~7.0.2",

Loading…
Cancel
Save