All Projects → krimlabs → eiphop

krimlabs / eiphop

Licence: other
A fetch like wrapper for elecron's ipc.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to eiphop

Ruby Dbus
A Ruby binding for DBus
Stars: ✭ 142 (+373.33%)
Mutual labels:  ipc
Tosdatabridge
A collection of resources for pulling real-time streaming data off of TDAmeritrade's ThinkOrSwim(TOS) platform; providing C, C++, Java and Python interfaces.
Stars: ✭ 229 (+663.33%)
Mutual labels:  ipc
background-service-lib
Essential classes for reliable background services.
Stars: ✭ 24 (-20%)
Mutual labels:  ipc
Ipcinvoker
A IPC Invoker for Android Development.
Stars: ✭ 176 (+486.67%)
Mutual labels:  ipc
Ohsce
PHP HI-REL SOCKET TCP/UDP/ICMP/Serial .高可靠性PHP通信&控制框架SOCKET-TCP/UDP/ICMP/硬件Serial-RS232/RS422/RS485 AND MORE!
Stars: ✭ 206 (+586.67%)
Mutual labels:  ipc
FactoryOrchestrator
A cross-platform system service which provides a simple way to run and manage factory line validation, developer inner-loop, diagnostics, and fault analysis workflows.
Stars: ✭ 36 (+20%)
Mutual labels:  ipc
Shadesmar
Fast C++ IPC using shared memory (with msgpack)
Stars: ✭ 126 (+320%)
Mutual labels:  ipc
discoIPC
Connect to the local Discord IPC Socket, for features like Rich Presence.
Stars: ✭ 19 (-36.67%)
Mutual labels:  ipc
Iceoryx
iceoryx - true zero-copy inter-process-communication
Stars: ✭ 208 (+593.33%)
Mutual labels:  ipc
persway
Small Sway IPC Daemon
Stars: ✭ 51 (+70%)
Mutual labels:  ipc
Andromeda
Andromeda simplifies local/remote communication for Android modularization
Stars: ✭ 2,203 (+7243.33%)
Mutual labels:  ipc
Gear Lib
Gear-Lib, C library for IOT Embedded Multimedia and Network
Stars: ✭ 2,381 (+7836.67%)
Mutual labels:  ipc
wat
How fast are computers?
Stars: ✭ 26 (-13.33%)
Mutual labels:  ipc
Kalm.js
The socket manager
Stars: ✭ 155 (+416.67%)
Mutual labels:  ipc
libvarlink
C implementation of the Varlink protocol and command line tool
Stars: ✭ 78 (+160%)
Mutual labels:  ipc
Jstp
Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
Stars: ✭ 132 (+340%)
Mutual labels:  ipc
procbridge
A super-lightweight IPC (Inter-Process Communication) protocol over TCP socket.
Stars: ✭ 118 (+293.33%)
Mutual labels:  ipc
reactor-aeron
A reactive driver for Aeron transport (https://github.com/real-logic/aeron)
Stars: ✭ 43 (+43.33%)
Mutual labels:  ipc
dotnetCampus.Ipc
本机内多进程通讯库
Stars: ✭ 84 (+180%)
Mutual labels:  ipc
apollo-link-electron
Get GraphQL results over IPC for Electron apps. (WIP)
Stars: ✭ 17 (-43.33%)
Mutual labels:  ipc

Eiphop abstracts electron's multi-channel IPC model to an HTTP like interface. It was built in the process of building HTTPSLocalhost, a mac app that lets you run TLS/SSL services locally.

Installation

The current stable version is 1.0.13.

yarn add eiphop

Getting started

We tend to think of Eiphop as Redux, except the actions are implemented in the main process and invoked from the renderer.

Define actions

Imagine you have the following actions in your main process:

const pingActions = {  
  ping: (req, res) => {  
     const {payload} = req;  
     res.send({msg: 'pong'});  
  }  
}

const hipActions = {
  hip: async (req, res) => {  
     const {payload} = req;
     res.notify('Sleeping for 800ms, BRB');
     // sleep for 800ms
     await  new  Promise(done  =>  setTimeout(done, 800)); 
     res.send({msg: 'hop'});

     // or res.error({msg: 'failed'})  
  } 
}

Setup main handler

Actions from different domain objects need to be combined to one global map and passed to eiphop's setupMainHandler function.

// somewhere inside main.js

import {setupMainHandler} from 'eiphop';
import electron from 'electron';

setupMainHandler(electron, {...hipActions, ...pingActions}, true);

setupMainHandler takes three arguments:

  1. The electron module to use
  2. The actions map to expose (the above example exposes two actions : {ping: function(), hip: function()})
  3. Enable logging flag (false by default).

Setup Renderer Listener

In your renderer’s index.js file, setup the listener as follows:

import {setupFrontendListener} from 'eiphop';

// listen to ipc responses  
const electron = window.electron; // or require('electron')  
setupFrontendListener(electron);

setupFrontendListener takes only an electron module. There is no support for logging on frontend (we realised it’s easier to console log manually in renderer).

Now your channels are ready. All you need to do is trigger actions.

Emit actions and expect response

Use the emit function to call actions defined in the main action map.

import {emit} from 'eiphop';

emit('ping', {you: 'can', pass: 'data', to: 'main'}, (msg) => {console.log(msg)})  
  .then(res => console.log(res)) // will log {msg: 'pong'}  
  .catch(err => console.log(err))  
;

emit('hip', {empty: 'payload'}, (msg) => {console.log(msg)})  
  .then(res => console.log(res)) // will log {msg: 'hop'}  
  .catch(err => console.log(err))  
;

emit takes up to three arguments:

  1. The name of the action to call (this was defined is actions map in main)
  2. The payload to send (this can be an object, string, list etc)
  3. [Optional] A callback function called by the main process to notify the render process with a message.

Using Notifiers

For example, sometimes there is a long running operation on the main process and you may want to provide the render process with an update as to it's progress.

You can use notifiers to send a message to the emiter on the render process by using res.notify without resolving the promise.

// Render process
import {emit} from 'eiphop';

emit('download', {/* fileIds, etc */}, (msg) => {console.log(msg)})  
  .then(res => console.log(res)) // will contain the downloaded file  
  .catch(err => console.log(err))  
;

// Main process
const pingActions = {  
  ping: (req, res) => {  
     const {payload} = req;

     payload.filesToDownload.forEach((fileId) => {
       // Tell the render process what is happening so it can inform the user
       res.notify(`Downloading file ${fileId}`);
       downloadFile(payload.fileId);
     });
     
     res.send({msg: 'pong'});  
  }  
}

Usage with React

Check the example folder.

Why another wrapper ? / How to structure real life apps ?

Check this blog post.

Contributors

Thanks and Gratitude :)

License

MIT License

Copyright (c) [2019-Present] [Shivek Khurana]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].