New to Autobahn - Confused about Session.ID

165 views
Skip to first unread message

redabo...@gmail.com

unread,
Oct 16, 2014, 5:14:08 PM10/16/14
to autob...@googlegroups.com
Hi,

I am new to Crossbar.io and Autobahn.js. I am unable to figure out how to discern different clients via a session ID.

Here is the portion of the config file that points to the nodejs:

{
         "type": "guest",
         "executable": "node",
         "arguments": ["server.js"],
         "options": {
             "workdir": "../nodejs"
}

I am guessing that session.id is referring to the process that relates to the connection to crossbar itself. Is there a way to retrieve an ID that relate to different clients / browser tabs?

Kind Regards,
Reda



Alexander Gödde

unread,
Oct 17, 2014, 5:46:52 AM10/17/14
to autob...@googlegroups.com

Hi!

 

Welcome to using Crossbar & Autobahn!

 

The session ID is an integer assigned by Crossbar at the time of session establishment, and is uniquely identifying for the client during the session lifetime. After a session ends, its session ID may be assigned to a subsequently connecting session. (Since it’s a long integer, cases of this will be relatively rare in practice.)

 

The session ID can be accessed from within the client (browser or NodeJS) as a property of the session object, e.g.  `session.id` (which returns the integer).

 

You can then use the session ID e.g. for receiver black- or whitelisting, i.e. limiting who receives a publication.

 

Hope this helps!

 

Regards,

 

Alex

--
You received this message because you are subscribed to the Google Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autobahnws+...@googlegroups.com.
To post to this group, send email to autob...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/201cd9d9-0625-4e7d-bb0b-992f6bdeb4f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

redabo...@gmail.com

unread,
Oct 17, 2014, 6:17:15 AM10/17/14
to autob...@googlegroups.com
Hello,

Thank you. Your explanation makes perfect sense and coincides with the way I expected session.id to work.
There must be a mistake in the way I am using it. The code below always returns the same ID on all of my browser tabs. Even different browser instances return the same session.id.

Your assistance would be greatly appreciated.

Here is the server code:
var autobahn = require('autobahn');
var crypto = require('crypto');

var connection = new autobahn.Connection({
        url
: 'ws://localhost:8080/ws',
        realm
: 'realm1'}
);

connection
.onopen= function (session) {
   
function createToken() {
        console
.log(session.id);
       
return crypto.randomBytes(32).toString('hex');
   
}

    session
.register('com.tarot.createToken', createToken).then(
       
function (registration) {
            console
.log("Procedure registered:", registration.id);
       
},
       
function (error) {
            console
.log("Registration failed:", error);
       
}
   
);
};

connection
.onclose = function(reason, details){
    console
.log("Client Disconnected!");
}

connection
.open();

This is the console output I get in the console using 3 tabs in two different browsers on the same machine:

2014-10-17 11:08:29+0100 [Guest       17938] Procedure registered: 2992382140210677
2014-10-17 11:08:33+0100 [Guest       17938] 6095189252032380
2014-10-17 11:08:39+0100 [Guest       17938] 6095189252032380
2014-10-17 11:12:31+0100 [Guest       17938] 6095189252032380
2014-10-17 11:12:54+0100 [Guest       17938] 6095189252032380
2014-10-17 11:13:02+0100 [Guest       17938] 6095189252032380
2014-10-17 11:13:17+0100 [Guest       17938] 6095189252032380

Kind Regards Borchardt

redabo...@gmail.com

unread,
Oct 17, 2014, 6:30:32 AM10/17/14
to autob...@googlegroups.com
Just to clarify. I am not referring to the console outputs in the browsers. I am only interested in the server giving me session.id's for each browser instance connecting.

Alexander Gödde

unread,
Oct 17, 2014, 8:27:57 AM10/17/14
to autob...@googlegroups.com

Hi!

 

The session ID is for the session through which the client is connected to Crossbar, i.e. for your code it is for the session connecting your sever to Crossbar. This session does not change because other clients (the browsers) connect to Crossbar, so you get back the same session ID each time.

 

To get the session ID of the connected clients, I currently see two ways:

 

-          You use the metaevent “wamp.metaevent.session.on_join” which is fired each time a client joins. Your backend subscribes to this, and you get an event which contains the session ID. 
-          Since this only notifies you that a client has connected, but not who that client is, you may want to implement something like this yourself. This could be via PubSub, i.e. your backend subscribes to a connection event, e.g. “com.tarot.client_joined”, and each client, on connecting, publishes to this and includes any extra information as the publication payload, or it could be via RPC, where the client calls a method on your backend. The latter would also make it easy to return any information the backend needs the client to know (e.g. the token you’re creating in your code below).
 
Hope this helps – else just contact me again!

redabo...@gmail.com

unread,
Oct 17, 2014, 9:45:06 AM10/17/14
to autob...@googlegroups.com
Hi,

This makes sense. Thank you very much for your help.

Kind Regards,
Reda
Reply all
Reply to author
Forward
0 new messages