0

I'm building an application in real time with socket.io

Each time the user enters the application creates a socket ID. So if I joining the application in several browser tabs generates me a socket id for each tab.

I generate a room for specific users and included my sockets id, but I need to emit broadcast message except to my sockets id.

This code don't work for me because emit broadcast message but sends to my other id sockets

socket.broadcast.to("room").emit('message', "somethings")

Any ideas?

saeta
  • 4,048
  • 2
  • 31
  • 48
  • possible duplicate of [Manage multiple tabs (but same user) in socket.io](http://stackoverflow.com/questions/12166187/manage-multiple-tabs-but-same-user-in-socket-io) – Mithun Satheesh Sep 28 '15 at 03:26

1 Answers1

0

Assuming you are using some application framework like express along side socket.io, you can use the valid session id obtained from Express.js for maping the socketIDs generated from the same session.

Other than maping the socketIDs to the sessionID, I dont think there is a way to obtain all the socketIDs generated across tabs as the information on other tabs wont be accessible in the current tab context.

Below are few existing questions discussing this same case:

  1. manage-multiple-tabs-but-same-user-in-socket-io
  2. socket-io-and-session
Community
  • 1
  • 1
Mithun Satheesh
  • 27,240
  • 14
  • 77
  • 101
  • I read the links previously and I get my sessionID associated with my sockets ID. I can't ignore these sockets ID in broadcast message. – saeta Sep 28 '15 at 03:37
  • In the question you are trying to emit to all but not your socketids. So are you saying that you are unable to figure out the difference of all socketIDs and those under Your session? – Mithun Satheesh Sep 28 '15 at 03:42
  • I'm saying I can not emit a message omitting my socketsid without make a loop in socketsid's array. Do you get me? – saeta Sep 28 '15 at 03:52