ConnectyCube / connectycube-reactnative-samples

Chat and Video Chat code samples for React Native, ConnectyCube
https://connectycube.com
Apache License 2.0
124 stars 111 forks source link

Need information about sessionExpired listener. #287

Closed UmerQur3shi closed 2 years ago

UmerQur3shi commented 2 years ago

Hey @DaveLomber, hope you're doing good. I've implemented ConnectyCube with firebase and everything is working fine, I just want to know about the sessionExpired event in config, it takes two arguments i.e handleRespose and error. Is handleResponse a method which I'll write and pass it to sessionExpired for recreating a session for already logged in firebase user when his current connectycube session expires or it's already implemented in the sdk and I'll just have to call it? And error is the callback I guess if it fails to create a session so that we can retry creating it in error. And do I have to connect connectycube chat again after creating a new user session ( after login to connectycube again for the firebase user with newly created session token )? I'm asking you all this because session expiration is not in our control and it takes time so I'll have to wait for hours again n again for a session to expire before testing, hope to get help from you soon, thanks :)

DaveLomber commented 2 years ago

@UmerQur3shi greetings

1) Here is a working example of this callback:

https://developers.connectycube.com/js/authentication-and-users?id=session-expiration

const CONFIG = {
  on: {
    sessionExpired: (handleResponse, retry) => {
      // call handleResponse() if you do not want to process a session expiration,
      // so an error will be returned to origin request
      // handleResponse();

      const params = {}
      ConnectyCube.createSession(params)
        .then(retry)
        .catch((error) => {});
    },
  },
};

This is only about ConnectyCube session, not related to Firebase whatever. You should manage the Firebase session independently

2) "And do I have to connect connectycube chat again after creating a new user session ( after login to connectycube again for the firebase user with newly created session token )?"

If you are connected already, do not need to re-connect

UmerQur3shi commented 2 years ago

@UmerQur3shi greetings

  1. Here is a working example of this callback:

https://developers.connectycube.com/js/authentication-and-users?id=session-expiration

const CONFIG = {
  on: {
    sessionExpired: (handleResponse, retry) => {
      // call handleResponse() if you do not want to process a session expiration,
      // so an error will be returned to origin request
      // handleResponse();

      const params = {}
      ConnectyCube.createSession(params)
        .then(retry)
        .catch((error) => {});
    },
  },
};

This is only about ConnectyCube session, not related to Firebase whatever. You should manage the Firebase session independently

  1. "And do I have to connect connectycube chat again after creating a new user session ( after login to connectycube again for the firebase user with newly created session token )?"

If you are connected already, do not need to re-connect

Thanks for the response, what I understood from these documents is that I just need to write a function for creating a session / user login and then I'll pass that function to sessionExpired in Config as an argument instead of handleResponse keyword mentioned in the docs, am I right?

DaveLomber commented 2 years ago

@UmerQur3shi this is correct

actually if call handleResponse then the initial request will return an error, e.g. user performs a request to get chat dialogs and the session expired, then a get chat dialogs request will return an error

But when you skip handleResponse, then the SDK will wait for you to recreate a session, so then SDK will re-peat the get chat dialogs request and return a success to the end user

UmerQur3shi commented 2 years ago

@UmerQur3shi this is correct

actually if call handleResponse then the initial request will return an error, e.g. user performs a request to get chat dialogs and the session expired, then a get chat dialogs request will return an error

But when you skip handleResponse, then the SDK will wait for you to recreate a session, so then SDK will re-peat the get chat dialogs request and return a success to the end user

Thanks @DaveLomber , you're the best <3