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

Atom-shell and socket.io #1141

Closed
nicola opened this issue Feb 14, 2015 · 11 comments
Closed

Atom-shell and socket.io #1141

nicola opened this issue Feb 14, 2015 · 11 comments

Comments

@nicola
Copy link

nicola commented Feb 14, 2015

I start a socket.io connection with my node script main.js (as in the examples). Now, every time I get a message through socket.io I want a new window to open, but how can I pass the socket variable that contains the connection?

Is there a way to pass variables from the nodejs part to the browser window?

@anaisbetts
Copy link
Contributor

You can't pass the socket itself, only the data that comes through the socket, via the ipc module. I would consider opening the socket in the renderer process instead, it will be much easier to debug

@nicola
Copy link
Author

nicola commented Feb 14, 2015

But my issue is that I only open windows when the socket receive a message, so I can't really do them in a window


Typed with hands

On Sat, Feb 14, 2015 at 7:24 PM, Paul Betts notifications@github.com
wrote:

You can't pass the socket itself, only the data that comes through the socket, via the ipc module. I would consider opening the socket in the renderer process instead, it will be much easier to debug

Reply to this email directly or view it on GitHub:
#1141 (comment)

@bwin
Copy link
Contributor

bwin commented Feb 14, 2015

I would consider opening the socket in the renderer process instead, it will be much easier to debug

&

But my issue is that I only open windows when the socket receive a message, so I can't really do them in a window

You could use a hidden window to open the socket, this way it would already be in the renderer process (and easier to debug).

Typed with hands

👍

@nicola
Copy link
Author

nicola commented Feb 14, 2015

What is the advantage of moving the socket logic from the main.js to the renderer process? They still do the same thing (beyond debugging purposes I mean). I don't have really clear how you would solve using the socket connection from the other windows, I guess I will need to use some sort of communication between windows to achieve that

@bwin
Copy link
Contributor

bwin commented Feb 14, 2015

Can you please describe your use case a little bit? Is it a chat app or something? Why do you open a new window per received msg and why do you need to pass your socket to this window?

Edit: Sorry for not answering your questions first.

@bwin
Copy link
Contributor

bwin commented Feb 14, 2015

Also, do you listen on the same socket in the browsercode after passing it to a window, or do you open a new one for in the browsercode after passing the "old" one to a window?
In fewer words: is there just one socket for all windows or would you have a socket for every window + 1 in main.js?

Ok, just ignore this one, I just re-read your first comment.
So you want to do something like:

io.on('connection', function(socket){
  //open new window
  //pass socket to new window
});

@nicola
Copy link
Author

nicola commented Feb 14, 2015

//pass socket to new window

This is what I am trying to ask, thanks for your time

@bwin
Copy link
Contributor

bwin commented Feb 14, 2015

Could you tell me something about your use case? What are you trying to accomplish with this?

@nicola
Copy link
Author

nicola commented Feb 14, 2015

Overall this is what the app does:

I have an app that when someone is talking to me, it opens a chat window.

I have a socket.io on a server, this allow people to join a room,
when a client join a room and sends a message to the room,
all the people in the room that are connected with their atom-shell app,
the atom-shell app using socket.io-clients that listen to .on('join') will start a new window,
from this window they can keep chatting.

@bwin
Copy link
Contributor

bwin commented Feb 15, 2015

I still can't come up with something better than what Paul Betts already said.
Wrap that shit in ipc. It's an additional layer of indirection, but shouldn't be too much boilerplate. You would basically interact with the socket in the browser-process and re-send the received events to the corresponding windows. And from the windows you could send msgs to the browser-process (also via ipc), which handles the socket stuff.
(You could replace browser-process with your main-window for better debuggability (breakpoints, etc) of the socket-stuff.)

Consider changing the title of this issue to something with "socket.io".
I haven't used socket.io with Atom-Shell, so there might be a much better solution than the proposed. It may be worth asking others for their experience with Atom-Shell & socket.io.

@nicola nicola changed the title Pass variable from main.js to browser window? Atom-shell and socket.io Feb 15, 2015
@zcbenz
Copy link
Member

zcbenz commented Feb 27, 2015

You can not explicitly pass an object from browser side to renderer side, but you can make use of remote module to get an object from browser side in renderer, it is a bit puzzling and you can see an example in #1095. Or you can manually do everything with IPC.

But you must notice that remote is implemented with IPC under the hood, so things could be rather slow.

@zcbenz zcbenz closed this as completed Feb 27, 2015
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

4 participants