Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron: send buffer from main to renderer

In the main process, I have a simple Uint8Array and I want to send it to the renderer process.

sender.send is converting everything to JSON, so it cannot be used for binary data.

Is there a simple solution for this?

like image 377
widgg Avatar asked Apr 06 '16 16:04

widgg


People also ask

How do you send from Main to renderer Electron?

The ipcMain module is used to communicate asynchronously from the main process to renderer processes. When used in the main process, the module handles asynchronous and synchronous messages sent from a renderer process (web page). The messages sent from a renderer will be emitted to this module.

How does IPC work in Electron?

IPC channels​ In Electron, processes communicate by passing messages through developer-defined "channels" with the ipcMain and ipcRenderer modules. These channels are arbitrary (you can name them anything you want) and bidirectional (you can use the same channel name for both modules).

What is IPC renderer?

The ipcRenderer module is an EventEmitter. It provides a few methods so you can send synchronous and asynchronous messages from the render process (web page) to the main process. You can also receive replies from the main process.


1 Answers

in main.js

global.Uint8Array.root = YOUR_JSON;

in render js

const {remote} = require('electron');
...
console.log(remote.getGobal('Uint8Array').root);
like image 74
KBIIX Avatar answered Sep 27 '22 20:09

KBIIX