librelist archives

« back to archive

multi tab chat with single session

multi tab chat with single session

From:
Dawid Kulig
Date:
2014-09-24 @ 13:45
Hey,

I’m developing a web application with ConverseJS chat included.

Currently I’m using 0.8.1 version with some tweaks from 0.8.3 version.

I’m using prebind method, with single session. So each tab I open has same
session id.

Generally, it work’s ok but I need help with some fixes.

I’ve modified strophe.js, and now I’m saving rid in cookie after each 
request, and before each request I’m loading this rid from cookie. 
At the moment only one tab is sending request to the xmpp server. I 
managed this by setting unique tabId for each tab, and save current tab 
tabId in cookie. In strophe.js in _onIdle() function, I’m checking whether
this tab has focus, and if yes, request is beeing sent. 
Today, I fixed problem with offline contacts after page realad or new tab open. 

The next things I wanted to implement are:

1) Reload conversation history after tab change. I’ve got eg. 3 tabs with 
chat opened. In tab 1 im starting conversation. It would be great when I 
switch to second or third tab I would see this conversation. I think there
is need to bind focus to each tab, and when this event is fired, load 
conversation history from localstore and initialize conversation tab which
was opened in the first tab. If the conversation tab is opened in both 
tabs, there will be only need to load conversation history.

2) Reload presences after tab change. Same situation as in 1), 3 tabs, in 
first tab which has focus I can see presence change of one of my contacts,
but when i switch to the next tab, i want to see this presence changed.


I would be grateful, if You could give me some tips how to handle properly
those situations.

Thanks in advance,
Dawid







Re: [conversejs] multi tab chat with single session

From:
Jc Brand
Date:
2014-09-25 @ 21:01

On 24. September 2014 15:45:58 GMT+02:00, Dawid Kulig 
<dawid.kulig@quantoo.pl> wrote:
>Hey,
>
>I’m developing a web application with ConverseJS chat included.
>
>Currently I’m using 0.8.1 version with some tweaks from 0.8.3 version.
>
>I’m using prebind method, with single session. So each tab I open has
>same session id.
>
>Generally, it work’s ok but I need help with some fixes.
>
>I’ve modified strophe.js, and now I’m saving rid in cookie after each
>request, and before each request I’m loading this rid from cookie. 
>At the moment only one tab is sending request to the xmpp server. I
>managed this by setting unique tabId for each tab, and save current tab
>tabId in cookie. In strophe.js in _onIdle() function, I’m checking
>whether this tab has focus, and if yes, request is beeing sent. 
>Today, I fixed problem with offline contacts after page realad or new
>tab open.

This looks to me like a worse approach in contrast to having a separate 
session per tab and using message carbons to make sure that all clients 
are current w.r.t sent and received messages.

>The next things I wanted to implement are:
>
>1) Reload conversation history after tab change. I’ve got eg. 3 tabs
>with chat opened. In tab 1 im starting conversation. It would be great
>when I switch to second or third tab I would see this conversation. I
>think there is need to bind focus to each tab, and when this event is
>fired, load conversation history from localstore and initialize
>conversation tab which was opened in the first tab. If the conversation
>tab is opened in both tabs, there will be only need to load
>conversation history

localStorage and sessionStorage are per tab. So you cannot retrieve 
messages from a different tab.

>2) Reload presences after tab change. Same situation as in 1), 3 tabs,
>in first tab which has focus I can see presence change of one of my
>contacts, but when i switch to the next tab, i want to see this
>presence changed.
>
>I would be grateful, if You could give me some tips how to handle
>properly those situations.

I think you are overcomplicating things by wanting to maintain a single 
session across tabs.

Instead, treat each tab as a separate client with its own JID resource and
use message carbons to keep them all in sync.

JC

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.

Re: [conversejs] multi tab chat with single session

From:
Jc Brand
Date:
2014-09-26 @ 10:18
On Fri, Sep 26, 2014 at 09:45:27AM +0200, Dawid Kulig wrote:
>      On 24. September 2014 15:45:58 GMT+02:00, Dawid Kulig
>      <[1]dawid.kulig@quantoo.pl> wrote:
> 
>        Hey,
> 
>        I’m developing a web application with ConverseJS chat included.
> 
>        Currently I’m using 0.8.1 version with some tweaks from 0.8.3 version.
> 
>        I’m using prebind method, with single session. So each tab I open has
>        same session id.
> 
>        Generally, it work’s ok but I need help with some fixes.
> 
>        I’ve modified strophe.js, and now I’m saving rid in cookie after each
>        request, and before each request I’m loading this rid from cookie.
>        At the moment only one tab is sending request to the xmpp server. I
>        managed this by setting unique tabId for each tab, and save current
>        tab
>        tabId in cookie. In strophe.js in _onIdle() function, I’m checking
>        whether this tab has focus, and if yes, request is beeing sent.
>        Today, I fixed problem with offline contacts after page realad or new
>        tab open.
> 
>      This looks to me like a worse approach in contrast to having a separate
>      session per tab and using message carbons to make sure that all clients
>      are current w.r.t sent and received messages.
> 
>    I cannot have separated session in my application. Application is used by
>    ~300-400 ppl every day, and I don’t want to have multiple sessions of each
>    user.

Why is 300-400 users using the app a problem for separated sessions? What
problem or difficulty do you foresee with separated sessions that you think
you're avoiding with a single session?
  
>        The next things I wanted to implement are:
> 
>        1) Reload conversation history after tab change. I’ve got eg. 3 tabs
>        with chat opened. In tab 1 im starting conversation. It would be great
>        when I switch to second or third tab I would see this conversation. I
>        think there is need to bind focus to each tab, and when this event is
>        fired, load conversation history from localstore and initialize
>        conversation tab which was opened in the first tab. If the
>        conversation
>        tab is opened in both tabs, there will be only need to load
>        conversation history
> 
>      localStorage and sessionStorage are per tab. So you cannot retrieve
>      messages from a different tab.
> 
>    I think it is, because when I open first tab, start conversation and then
>    i open a new tab I can see chat history from the first tab. But the
>    problem is when I have currently at least two tabs and I start
>    conversation in the first and the i switch to the second.

I checked and looks like you're right. localStorage is per origin (protocol +
domain name), which can span tabs.
  
>        2) Reload presences after tab change. Same situation as in 1), 3 tabs,
>        in first tab which has focus I can see presence change of one of my
>        contacts, but when i switch to the next tab, i want to see this
>        presence changed.
> 
>        I would be grateful, if You could give me some tips how to handle
>        properly those situations.
> 
>      I think you are overcomplicating things by wanting to maintain a single
>      session across tabs.
> 
>      Instead, treat each tab as a separate client with its own JID resource
>      and use message carbons to keep them all in sync.
> 
>    As I said before, I don’t want user to have multiple session. That’s why
>    I’m asking for some help.

Yes, but it would be nice if you explained why you don't want to.

Do you have experience with Backbone.js? Converse.js uses Backbone.js to model
and store chat boxes, messages, roster contacts etc.

You retrieve stored objects by calling "fetch" on a Backbone collection.
So if you are switching tabs and want to fetch objects (e.g. messages) you'd
call this.messages.fetch() (where this is a specific chatbox).

JC