Skip to content

Commit

Permalink
fix: initiate only one websocket connection instead of 1 per session
Browse files Browse the repository at this point in the history
  • Loading branch information
rasulov1337 committed Dec 19, 2024
1 parent 5b6b86c commit 860808b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/components/ChatWindow/ChatWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ export default class ChatWindow extends BaseComponent {
this.recipientId = recipientId;
this.messages = messages;

if (globalStore.chat.socket) {
globalStore.chat.socket.close();
if (
!globalStore.chat.socket ||
globalStore.chat.socket.readyState === WebSocket.CLOSED ||
globalStore.chat.socket.readyState === WebSocket.CLOSING
) {
globalStore.chat.socket = new WebSocket(
`wss://${window.location.hostname}:${location.port}/websocket`
);
}

globalStore.chat.socket = new WebSocket(
`wss://${window.location.hostname}:${location.port}/websocket`
);
}

protected afterRender() {
Expand Down

0 comments on commit 860808b

Please sign in to comment.