electron-websocket-stream
spawn browser windows connected to the main process via websocket-stream
usage
npm install electron-websocket-stream
var electrows = var options = debug: false // `debug` logs some connection details and controls whether errors// in the browser are sent to the http server for logging /******************************************************************** MAIN PROCESS `electron.BrowserifyWindow` is additionally supported and returns a "BrowserWindow instance" that supports the additional method: `.webContents.connectFunctionScript` with one parameter `scriptFn`. Calling `.webContents.connectFunctionScript(myScriptFn)` requires `myScriptFn` to have it's first parameter named `ws` and returns a `websocket-stream` instance. 1. The returned `ws` instance lives in the MAIN PROCESS. 2. The argument passed to the `ws` parameter of `myScriptFn` is the `websocket-stream` instance that lives in the RENDER PROCESS. 3. This constitutes a real time stream connection that allows communication between the main and render process********************************************************************/ { if error throw error var BrowserifyWindow = electronBrowserifyWindow var opts = width: 800 height: 600 show: true var win = win // win.openDevTools() var ws = winwebContents // listen to the 'data' event ws ws ws // ws.on('finish', function () {console.log('finish')}) // ws.on('close', function () {console.log('close')}) // ws.on('exit', function () {console.log('exit')}) // or pipe to another stream // ws.pipe(...) return ws // [optional] return a duplex stream}/******************************************************************** RENDER PROCESS * `scriptFn` will be stringified and browserified to run in a BrowserWindow * `ws` parameter will be passed a websocket-stream instance arguments for communication with the main process * ending `ws` exits the browser window********************************************************************/ { var bel = var element = bel`<h1> hello world </h1>` documentbodyinnerHTML = '' documentbody var data = title : documenttitle url : locationhref content : documentinnerText ws ws // sende data to the main process // ws.end() // closes the websocket stream & exits the BrowserifyWindow `win` }