Knowing one client's presence

#1

Hi all,

Is there any way the broker know the “presence” (online/offline) status of one client. In many IoT application, we need to know the present status. I skimmed through the spect but find no keyword (well, or I missed something).

Thanks.

0 Likes

#2

Hi,

There are a number of meta events and procedures for tracking sessions;
https://crossbar.io/docs/Session-Metaevents-and-Procedures/

So for example you can call “wamp.session.list” to get a list of active sessions, then “wamp.session.get” for each returned session_id to get details … depending on what you want to do, if you always store the last session_id of a client in your authentication database, you can do a single (relatively quick) “wamp.session.get” on that id to see if it’s active or whether the session has been closed.

Alternatively, or additionally, you could subscribe to “wamp.session.[on_join|on_leave]” and literally implement your own simple status indicator by updating the status of a client when they connect / disconnect …

Would that do it? … or could you expand a little on what you’re after?

2 Likes

#3

Great thanks. That’s all I missed about device presence.

We are concerning about the scalebility of crossbar, but that is another thread.

Thanks again.

0 Likes

#4

If of any use, there’s a new demo available on demo.crossbar.io that is essentially a presence indicator, i.e. shows a dynamic list of current connections …

0 Likes

#5

I’m experiencing difficulties using the wamp.session.list procedure with the optional filter_authroles list.

Using this JS code snippet in the client with AUTOBAHN_DEBUG = true:
session.call(“wamp.session.list”, [“editor”]).then(…

I see this in the JavasCript console:
(5) [48, 7056450737739894, {…}, “wamp.session.list”, Array(1)]
0: 48
1: 70564507377398942: {}
3: “wamp.session.list”
4: [“editor”]
length: 5
proto: Array(0)
WebSocket transport send [48,7056450737739894,{},“wamp.session.list”,[“editor”]]

then,in the Crossbar window I see:
2019-05-01T12:13:31+0200 [Router 95952] AssertionError: : Traceback (most recent call last):
File “c:\python37\lib\site-packages\crossbar\router\router.py”, line 239, in send
session._transport.send(msg)
File “c:\python37\lib\site-packages\crossbar\router\session.py”, line 235, in send
self._session.onMessage(msg)
File “c:\python37\lib\site-packages\autobahn\wamp\protocol.py”, line 933, in onMessage
on_reply = txaio.as_future(endpoint.fn, *invoke_args, **invoke_kwargs)
File “c:\python37\lib\site-packages\txaio\tx.py”, line 429, in as_future
return maybeDeferred(fun, *args, **kwargs)
— —
File “c:\python37\lib\site-packages\twisted\internet\defer.py”, line 151, in maybeDeferred
result = f(*args, **kw)
File “c:\python37\lib\site-packages\crossbar\router\service.py”, line 197, in session_list
assert(filter_authroles is None or isinstance(filter_authroles, list))
builtins.AssertionError:

And this leads to the following in the JavaScript console:
WebSocket transport receive [8,48,7056450737739894,{},“wamp.error.runtime_error”]
Call to wamp.session.list returned error y {error: “wamp.error.runtime_error”, args: Array(0), kwargs: {…}}

This with Crossbar 19.1.2. My config.json has a role of ‘editor’ defined for the realm I’m talking to. Looks like Autobahn is send the correct message, but Crossbar has an issue with it.

Am I doing something wrong here?

0 Likes

#6

Update on above situation:

I upgraded Crossbar to 19.3.5 and Autobahn.js to 19.3.3 just to be sure - but it makes no difference.

Thanks,
Bert

0 Likes

#7

Mmm, I think this is something that keeps “getting” me … in ABJS the second parameter is “args”, which needs to be a list of arguments. “filter_authroles” looks like it too needs to be a list … so I would expect the call to look something like;

session.call(“wamp.session.list”, [[“editor”]]).then(…

If you add an extra set of brackets (i.e. a role list within a parameter list) does this help?

0 Likes

#8

It does make a difference, but it does not improve…
In the browser’s console:
WebSocket transport send [48,1,{},“wamp.session.list”,[[“editor”]]]

Output in the crossbar window
File “c:\python37\lib\site-packages\crossbar\router\service.py”, line 202, in session_list
if filter_authroles is None or session._session_details[u’authrole’] in filter_authroles:
builtins.TypeError: ‘SessionDetails’ object is not subscriptable

In the browser’s console:
WebSocket transport receive [8,48,1,{},“wamp.error.runtime_error”,["‘SessionDetails’ object is not subscriptable"]]

0 Likes

#9

Ok, this looks more like a Crossbar refactoring issue / bug, let me look into this …

0 Likes

#10

Ok, you found a bug! :slight_smile:

Fix in the pipes …

0 Likes

#11

Thanks a ton.

Bert Hooyman
Amstelveen

0 Likes