1.0.3 • Published 2 years ago

@open_brainiac/electron-ipc-router v1.0.3

Weekly downloads
147
License
MIT
Repository
github
Last release
2 years ago

electron-ipc-router

electron-ipc-router is used to send messages between the main, and the renderer process. and helps debug the main process.

NPM

##Install

npm i @open_brainiac/electron-ipc-router

🚀 Usage:

// main process
import {subscriber} from "@open_brainiac/electron-ipc-router"

const routes = {
  foo: function(a,b){
    return a+b;
  },
  bar: async function(){
    // getData is an async function, like getting data from DB
    let data = await getData()
    return  data;
  }
}

subscriber({routes})
<!--  Renderer process -->
<script>
    import {ipc} from "@open_brainiac/electron-ipc-router"
    console.log(ipc("foo", 1,2))// => prints: 3
    ipc("bar").then(res=>console.log(res)) // => prints the data variable
</script>

Debugging server

Using the electron-ipc-router you can start a node server that exposes the functions of the routes object.

Note: this functionality should be used only for debugging the routes and not for production.

  let options = {
    routes,
    server: true,
    port: 3000,
  }
  subscriber(options)
  curl --location --request POST 'http://localhost:3000/foo' \ // => the name of the function
  --header 'Content-Type: application/json' \
  --data-raw '{
      "args": [1,2] //=> array of the function arguments
  }'

🤝 Contributing

Contributions, issues and feature requests are welcome!

📝 License

This project is MIT licensed

1.0.2

2 years ago

1.0.1

2 years ago

1.0.3

2 years ago

1.0.1-beta.5

3 years ago

1.0.0-beta.2

3 years ago

1.0.1-beta.3

3 years ago

1.0.0-beta.1

3 years ago

1.0.0-beta.0

3 years ago

1.0.0-beta

3 years ago