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.
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();
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!
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/8c4a6517-89cb-4c2d-bb70-7278c231a826%40googlegroups.com.