Comechat Audio and Video Problem with Angular 8

Hi, I solved refresh page problem. But I think that it is not good solution. After refreshing page, I must log-in again to CometChat. If I did not make it, I could not solve refresh page problem.

Step 1 ) I followed this example and I saw that after refreshing page, this example call login page again. For that reason, I must call login method of CometChat Pro after refreshing

https://www.cometchat.com/tutorials/angular-voice-video-chat/

ngAfterContentInit(): void {
const user = this.tokenService.getPayload();
if (user) {
    this.cometChatService.login(user._id).subscribe(value => {
        console.log('Login CometChatAgain');
    }, error => {
        console.log('Error Login CometChatAgain');
    });
}

}

Support Answered:
Hello @musacavus, CometChat SDK stores user session in local storage until that user calls CometChat.logout(). The detail remains in the local storage. You can check this by using CometChat.getLoggedinUser(). If the method returns null , only then you need to call CometChat.login(). Else you do not need to call CometChat.login(). I hope this helps you solve your issue with calling login method on each page refresh.

NOTE: But this solution could not be solved my problem. Because of when I refresh page CometChat must be initailzed again for that reason I must re-login cometchat. Please Could you help me about this problem ?

Hello @musacavus,

The SDK stores the last logged in user in local storage. Every time a user loads/reloads the page you first have to initialize the SDK and then check what CometChat.getLoggedInUser() returns. It will either return a User object or null.

  1. User Object => It means that the user is logged in and you can go ahead without calling the CometChat.login().

  2. null => It means there is no logged in user and you have to log in the user using CometChat.login().

Also, please note that if you clear the browser local storage then CometChat.getLoggedInUser() will return null. The storage is only cleared when you logout from CometChat. Hope this helps!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.