Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendToRenderers acts differently than callRenderer #26

Open
Laruxo opened this issue Nov 7, 2019 · 4 comments
Open

sendToRenderers acts differently than callRenderer #26

Laruxo opened this issue Nov 7, 2019 · 4 comments

Comments

@Laruxo
Copy link

Laruxo commented Nov 7, 2019

From documentation I expected that these two functions act the same. Only expected difference was callRenderer sending to specific window and sendToRenderers sending to BrowserWindow.getAllWindows().

After digging deeper I found that sendToRenderers does not use the same channel formatting as the other method, so it is impossible to handle incoming messages using ipcRenderer.answerMain.

I have two possible solutions:

  1. Exposing additional function in ipcRenderer to handle unchanged channel.
  2. Formatting channel in sendToRenderers for every window.

@sindresorhus which one would you prefer?

@sindresorhus
Copy link
Owner

sindresorhus commented Feb 2, 2020

This behavior is intentional. It's meant as a broadcaster, not a two-way communication channel. Its docs doesn't mention any support for replying.


Exposing additional function in ipcRenderer to handle unchanged channel.

Not really clear what you mean. "Unchanged channel"?

Formatting channel in sendToRenderers for every window.

Same here. Not clear what you mean.


It could in theory support replying and receive an array of replies, but there are certain things that needs to be decided. Like, what if a renderer sends a rejected promise, should it throw or first wait for all renderers to send their response. I imagine it would also be some overhead of having to wait for all the renderers to respond. Electron IPC is not cheap.

@alaj
Copy link

alaj commented Feb 19, 2020

I thought it was a bug when I couldn't receive message from sendToRenderers by answerMain.

@Razboy20
Copy link

Razboy20 commented Aug 3, 2022

I know this is an old issue, however is there a way to listen to sendToRenders within electron-better-ipc directly?

@serg06
Copy link

serg06 commented Jun 16, 2024

Ohh now I understand. ipcMain.callRenderer can only be answered by ipcRenderer.answerMain, and ipc.sendToRenderers can only be listened to by ipcRenderer.on.

For the last 4 years, I thought callRenderer was just broken because I wasn't receiving events. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants