0

Say I am making a little chat application using phoenix.

Locally when I open multiple tabs in a browser, will that be a separate socket connection?

From what I see with other chat apps is that if I open a new tab or even browser window, it re-connects to the same chat session, which makes sense since you want to re-connect the user using a cookie or something.

If this is the case, how do you test things locally if you want to test multiple users in a chat session etc.?

Any tricks?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199

1 Answers1

1

Yes, each tab will have a separate socket. If you are authenticating your sockets per the recommend approach (in the socket.js boilerplate generated with your project), you will automatically authenticated. However, if you want the second tab to open the same room, you will need to handle that yourself. The answers to these questions will give you some ideas:

But would you really want to do that? Perhaps the user has opened another browser tab/window because they want to chat in another room.

I'm a little unclear on your question, but I'm going to assume that you want to test different users on the same computer. You can open the chat app in a different browser like Chrome, Firefox, IE, etc. This is how I do manual testing. If your looking for automated unit testing of channels, Chapter 13 of Programming Phoenix has some good examples.

Community
  • 1
  • 1
Steve Pallen
  • 4,417
  • 16
  • 33
  • on a side note, is the client side socket handling production ready? I guess I am referring to socket.js, I'm a newbie so just wondering. – Blankman Apr 21 '17 at 00:37
  • 1
    I'm using it in production for all the signalling in an enterprise class WebRTC soft phone. I'm also using it in a team chat application. I'm rendering templates server side and pushing large chunks of html through the socket. My only issue has been with using jQuery to update the DOM. So, I would say Yes. – Steve Pallen Apr 21 '17 at 00:44