cfdp / opeka

Counseling chat service, built for providing anonymous help to young people at risk
https://curachat.com
GNU General Public License v3.0
10 stars 6 forks source link

Improve chat session connectivity #94

Closed benjamin-dk closed 6 years ago

benjamin-dk commented 7 years ago

The clients often experience that the connection to the chat is lost.

Since there are no error messages tied to these events, we must assume that they are caused by a time out because of a bad internet connection.

We could improve the connectivity by adding some kind of authentication id (session cookie or local storage variable) to the client browser, that would allow for reconnection in a time interval we define.

It is also possible that we can mitigate the problem by adjusting disconnect settings in the Opeka app to so people don't get thrown off so fast.

alex-bukach commented 7 years ago

@benjamin-dk @cfdp I have a question. Here's the use case:

Currently (i.e. on develop branch) it results in having two users in the room: the old one and the new one. The server doesn't know that the first user has been disconnected (since as opposite to closing a browser when we notify the server about exit nothing happens in the case).

For the case of automatic reconnecting we'll let server know that it's the same user. However when a user is not able to reconnect (e.g. when the connection was lost and hasn't recovered) shouldn't we expire his session and delete from the users list in all rooms?

benjamin-dk commented 7 years ago

@alex-bukach In broad terms the primary goal of this feature is to help users that experience being disconnected. They should reconnect to the chat and enter the same room automatically with the same user and be able pick up the conversation.

So maybe the error message "Your connection to the server was lost. Please reconnect" should be replaced by a message saying "Your connection was lost. Trying to reconnect..." - a feature known from Googles web apps like Gmail and Google Docs.

This reconnection attempt should continue for a time interval that we define in the settings or until the counsellor closes the room or cancels the reconnection attempt (as we discussed previously - I will update the feature description with these points).

After these conditions are met, we can expire the session and inform the users appropriately.

So to answer your questions specifically - the user should not be forced to reload the page when losing the connection since we agreed that we use JS variables for remembering the session.

If we force the user to reload on a disconnection, we undermine the purpose of letting him reconnect automatically to the same room.

alex-bukach commented 7 years ago

@benjamin-dk I asked a bit different thing: when a user loses a connection and doesn't reconnect for some reason, counselor and other users (if any) keep seeing the user in the room. The question was whether we should expire the session and delete the user from the room. (Apparently yes.) The question was not related directly to the current issue though, probably it's the matter for another issue.

As for reconnecting, the approach I'm using now is given number of attempts to reconnect with given interval (both are set in settings) before displaying the message to a user. However we cannot stop reconnecting when a counselor closes a room or do anything else, since once the connection is lost, we don't have a way to say a browser to stop reconnecting. Do I miss anything?

benjamin-dk commented 7 years ago

Ok, I think I get it. Yes, in that case the user should be deleted from the room.

About the reconnection logic, I suppose you are right. I am looking forward to testing it, maybe I can give some more qualified feedback then @alex-bukach.

alex-bukach commented 7 years ago

@benjamin-dk the reconnection is implemented in https://github.com/cfdp/opeka/pull/103.

It is enabled by default, it can be disabled or its configuration (number of attempts and interval between them) can be changed at the module advanced settings page (/admin/config/services/opeka/advanced_settings).

benjamin-dk commented 6 years ago

I failed to mention an important thing, that we also need to implement. When a user is reconnecting we also need to let the counselors and others (in group rooms) know, that the user isn't currently available. I suggest we put (offline) after their name in the user list in the sidebar.