0.1.0-0 • Published 6 years ago

electron-ipcrenderer-websocket v0.1.0-0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

Drop-in replacement for WebSocket using Electron IPCRenderer

Use Electron IPCRenderer like WebSocket.

On the main thread, you can use our electron-ipcmain-websocket to bridge messages from IPCMain into WebSocket-like interface.

When paired up with redux-websocket-bridge, you can easily send Redux actions thru IPC.

How to use

const WebSocket = require('electron-ipcrenderer-websocket');
const ws = new WebSocket('<IPC channel name>');

ws.onopen = event => {
  // Fired shortly after the constructor
};

ws.onmessage = event => {
  // "event.data" is string received from browserWindow.webContents.send(channelName, data)
  console.log(event.data);
};

// Send thru this.ipcRenderer.send()
ws.send(data);

// Also send thru this.ipcRenderer.send(), but append "/hex" to channel name and encode ArrayBuffer in hex string
ws.send(new ArrayBuffer(16));

Supported options

{
  ipcRenderer: require('electron').ipcRenderer,
  sendToHost: false
}
NameDescriptionDefault
ipcRendererAn instance of ipcRenderer to use, instead of acquiring it inside our codenull
sendToHostUse ipcRenderer.sendToHost to send to <WebView>, instead of ipcRenderer.send, which send to IPCMainfalse

What can it paired up with?

Contributions

Like us? Star us.

Something not right? File us an issue.