ClankBundle icon indicating copy to clipboard operation
ClankBundle copied to clipboard

Access current session?

Open abenz1267 opened this issue 11 years ago • 7 comments

Hi,

how can i access a session that's currently opened on the connection?

Regards

abenz1267 avatar Mar 31 '14 15:03 abenz1267

@JDare no tip/idea?

abenz1267 avatar Apr 06 '14 11:04 abenz1267

If you're talking about accessing a web session on the socket, try this documentation: https://github.com/JDare/ClankBundle/blob/master/Resources/docs/SessionSetup.md

JDare avatar Apr 06 '14 14:04 JDare

@JDare Hi,

no, i'm talking about accessing the Autobahn session opened when calling "Clank.connect". "//session is an Autobahn JS WAMP session." -> this session.

F.e: I have a page with a dynamic header -> multiple twig templates, but all those templates need to use the same session, cuz otherwise i'm opening a new Autobahn session for every new websocket call.

abenz1267 avatar Apr 06 '14 16:04 abenz1267

@JDare When reloading the page, all connections get closed, as they should. The header f.e. establishes a websocket connection, subscribing to different topics.

My header consists of like...3 different dynamic parts. F.e. if i need to publish to a topic in section 2, i have to establish a new connection, but i'd be much more pratical to use the connection/session opened in the 1. section of the header.... which always gets opened.

What i'd need to know is how to use the already opened connection.

abenz1267 avatar Apr 08 '14 00:04 abenz1267

Cmon, no one knows how to solve this? I mean..it should be possible to use the same connection to publish/subscribe/unsubscribe WITHOUT calling

var _CLANK_URI = "ws://{{ clank_host }}:{{ clank_port }}";
         var myClank = Clank.connect(_CLANK_URI);

myClank.on("socket/connect", function(session){
    //session is an Autobahn JS WAMP session.
});

evertime, since it always opens ANOTHER connection, instead of using the already opened one.

abenz1267 avatar Apr 10 '14 08:04 abenz1267

@JDare

All i'd need is the opened "Autobahn JS WAMP session", so i can call f.e: session.publish("acme/channel", {msg: "This is a message!"});

without opening a new connection ( cuz a connection is opened already...).

From the autobahn API reference:

"Connection.session Returns an instance of autobahn.Session if there is a session currently running on the connection."

So how can i access this session within clank? Clank can obv. start a session when connecting, but how to get an already started session on that connection?

Regards

abenz1267 avatar Apr 11 '14 05:04 abenz1267

In my js, I have done:

clank.on('socket/connect', function (session) {
    window['clankSession'] = session;
});

So I can access session everywhere (subscribe, publish...) once the session is opened by using:

clankSession.publish("acme/channel", {msg: "This is a message!"});

alcalyn avatar Aug 08 '14 15:08 alcalyn