-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chatClient.connectUser() before previous websocket connection is disconnected causes wrong current user #679
Comments
You must wait for the previous disconnect to finish before connecting with another user. private connectUser() {
const apiKey = environment.streamChat.apiKey;
// TODO: wait for disconnect to finish
await this.chatClient.init(apiKey, this.vm.currentUserId$$(), async () => {
return await this.vm.getStreamChatToken();
});
await this.channelService.init({
type: 'messaging',
members: { $in: [this.vm.currentUserId$$()] },
disabled: false,
});
}
private async disconnectUser() {
if (!this.chatClient.chatClient?.user) {
return;
}
this.channelService.reset();
await this.chatClient.disconnectUser();
} Since there is no way to wait for Feel free to reopen the ticket if you have further questions. |
@szuperaz I tried your suggestion, but it doesn't work. I suspect that |
This could also be if you don't wait for user connect before querying channels, if you look at my code, I've added await this.chatClient.init(apiKey, this.vm.currentUserId$$(), async () => {
return await this.vm.getStreamChatToken();
});
await this.channelService.init({
type: 'messaging',
members: { $in: [this.vm.currentUserId$$()] },
disabled: false,
}); |
@szuperaz Thank you for your quick response. I've tried, but still the problem persists. Here is the recording of this symptom, which that the current user is not properly set. Screen.Recording.2025-01-14.at.6.01.12.PM.movHope this helps to fix this problem. |
If you believe the issue is inside the SDK please create a reproduction by forking our sample app |
When users navigate away from the chat component and then quickly return, the previously active websocket connection may not have fully closed before the new ws connection is established. As a result, the current user occasionally appears as if they are another participant in the conversation. In the browser’s network panel, you can observe the old WebSocket still terminating while the new session is starting. This leads to chat messages from the “current user” being displayed on the left side (as though they belong to a different user).
Steps to Reproduce
Correct state
When visit the component before closing previous ws connection
Code
The text was updated successfully, but these errors were encountered: