0

I want to create realtime application and i want to send realtime updates only for specific users (for example my friends).

I have list of friend ids and my own id on client side. As I understand, I need to set sockjs session with my own id when I connect for my friends to be able to find me later when they send events.

The problem that I cant find where I can set the session id? The sockjs-client doesn't allows to send parameters with url on connect..

Anderson
  • 573
  • 1
  • 4
  • 9

1 Answers1

2

The usual way is to treat the first message sent over sockjs specially. If you send your authorization / username / cookie / whatever as a first message from sockjs-client, you can receive that in sockjs server and mark this connection as fits.

Marek
  • 3,471
  • 1
  • 16
  • 15
  • Thank you for suggestion. Now i thought about opening connection to url with user id as part of url (not arguments). This should be easy to extract them with regex. – Anderson Nov 29 '12 at 15:20
  • Can I set the url to /info by myself? Because it always append it to endpoint? – Anderson Nov 29 '12 at 16:07
  • Request to `/info` is part of SockJS protocol, no, user is not allowed to interfere with that. But you can indeed pass magical options to SockJS constructor that will cause SockJS-client not to call /info. This is _not_ recommended though. – Marek Nov 30 '12 at 15:36
  • will setting session_id as browser cookie help?? – Somesh Dec 18 '12 at 12:01
  • Just send the user name and any metadata you need as the first message over sockjs. – Marek Dec 19 '12 at 13:09
  • @Marek: Can you tell me how to close the WS Connection if client doesn't send the metadata in first request as need? – Thanh Nguyen Van Dec 23 '14 at 10:38