I am writing a web app. I want users to be able to go to a URL and start a new "session" of my app. They can Slack their friends/colleagues the URL and then everybody is in a socket-connected scenario where the originator can pose questions to the group, who can answer anonymously.

Right now, I initialize the user type such that the person who started the session can ask the questions. I was planning on the fact that going to the same URL in a different tab would not have that initialization process, and therefore I could do all kinds of things differently (UI, etc). I am starting to wonder if there's a better what the better way to do this is.

I would like for users to not have to log in, unless at the end they want to save their results. I also don't know exactly how (if?) actual server sessions play into this.

I have something that generates a random string that becomes the route of the application with each newly opened session. I was hoping that would be the way to keep people/things separate.

I'm using React, Redux, and Socket.io. What I was hoping was that opening a URL in a second tab would do things like increase a counter of the number of users, etc. But, the state is obviously not there, so the two edged sword slays me and I need some type of other solution -- I'm using name-spacing with Socket.io.


I am no longer using socket.io name-spacing and am using the "rooms" feature native to socket.io. I actually did get it all working on my machine (able to have multiple tabs but different rooms and the room counts appropriately update etc.). However, I have not successfully got any socket features working on the hosted site yet, so I'm pretty this isn't over. (Rather new at this.) Will update post again when I know more. Thanks for the awesome answers so far.

  • 1
    I'm not completely sure what you want. Do you want to distinguish between different users on different machines, distinguish between different users on the same machine using different tabs in the same browser (doesn't make much sense for the use case your describing), identify the same user across multiple tabs, or something completely? Cookies and/or localstorage would be your best bet for identifying users. – c1moore Sep 26 '17 at 13:53
  • 2
    NOTE: if you are maintaining state using cookies, etc. 2 tabs in the same browser will share those cookies. However, using 2 different browsers (like chrome and firefox) on the same machine will keep everything separate. – Berin Loritsch Sep 26 '17 at 14:51

I hear you saying that two tabs visiting your service should be like browsers on two hosts, they should be held quite apart.

going to the same URL in a different tab ...

One could distinguish clients based on some combination of source IP, URL, and cookies. I don't see anything different when opening new tab on same old URL. (BTW, notice that you can inspect URL parameters or cookies for "freshness", for recent timestamp.)

Here is my suggestion. Upon receiving a GET for a "rendezvous address" URL, refuse to serve it directly, instead 302 to a "service address" URL, perhaps one that includes a nonce like a random GUID. Then when someone opens 1st tab in the browser to start chatting, and later opens 2nd tab, they will each wind up with random nonces and can be distinguished by their URLs. Different tabs within cookie scope will of course offer identical cookies, so cookies don't help much for distinguishing among tabs.

You could play with cookie scope, but it seems unnecessary. Adjusting each tab's URL to some unique value should suffice.

  • I appreciate your input...I am so new at this that I researching some of the new concepts in your answer and will see where that gets me. Thanks. – James Oct 11 '17 at 2:25

I'm not certain what you're asking, but here's a few approaches you can take based on what I think you might be asking.

Identify different users on different machines

To identify different users on different machines, simply assign them some sort of random ID and store that ID using a combination of cookies and localstorage/sessionstorage. You can probably find some library out there that can determine if cookies are enabled and fallback to localstorage/sessionstorage if necessary. For angular, I believe this is the library I use.

Identify the same user on the same machine/browser but different tabs

Using cookies and/or localstorage/sessionstorage works well here, too. These values are shared across tabs. You'll be able to determine which user started the conference and show them the coordinator screen even if they close out of the tab and reopen it.

Identify different users on the same machine/browser but different tabs

This doesn't quite make sense. Why would users be using the same computer to chat? This seems to be what your asking, though. If you want to do this for some reason, do not assign the user any cookies (or localstorage/sessionstorage variables). Assume every tab is a new user. To accomplish this and still identify the user, you could generate an ID in the tab and send that ID to socket.io for identification purposes.

Identify the same user on different machines

Without requiring your users to sign in or provide some sort of uniquely identifiable information, this is nigh impossible. Without requiring your users to sign in, you could provide unique IDs for each user (similar to how Go2Meeting handles identifying users) or request an email (or other form of identification) upon entering the room. The latter isn't a bad idea if this is for some sort of business where you want to solicit the users with emails reminding them to use your product.

You also mention not knowing if you need a server. Since you're using socket.io, it is possible to avoid the server after initially setting up the room; however, before that you should use the server to determine which view the user should see (using some way of identifying them listed above).

If you're willing to provide the coordinator a different URL for other members (e.g. https://communicate.io/12345#coordinator vs. https://communicate.io/12345), your work may actually become easier. You can easily differentiate between the coordinator and the other members based on the URL. You could still use the methods above for identifying users if you need to at that point.

  • Thank you for taking the time to prepare guidance for the various scenarios and apologies it wasn't clear enough to tell (and that I didn't respond to your comment in time before you had to write this). I think what I am needing to do is to identify unique visitors to one "session" in my app. One user could be in two tabs of the app, but if in different sessions, then that's fine. – James Oct 11 '17 at 2:27
  • @James If I understand what you're saying, you should consider using cookies and/or localstorage. Here are some resources on cookies and localstorage/sessionstorage. Do NOT use the IP, this is not reliable and several different users can appear to have the same IP address. – c1moore Oct 11 '17 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.