Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hardikroongta8 committed Apr 27, 2024
1 parent 7638546 commit d346be5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion handlers/websocketHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const connectionHandler = async (socket, req) => {
message: 'Timeout'
}));
socket.close();
}, 15000);
}, 25000);
}
} catch (err) {
if (axios.isAxiosError(err)) {
Expand Down
9 changes: 5 additions & 4 deletions helpers/websocketHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import WebSocket from "ws";

export const isConnectedHelper = (wss, connectionId) => {
console.log(wss.clients);
var isClientConnected = false;
wss.clients.forEach((client) => {
if(client.connectionId === connectionId){
if (client.connectionId === connectionId) {
isClientConnected = true;
}
});
Expand All @@ -13,16 +14,16 @@ export const isConnectedHelper = (wss, connectionId) => {

export const closeConnectionHelper = (wss, connectionId) => {
wss.clients.forEach((client) => {
if(client.connectionId === connectionId){
if (client.connectionId === connectionId) {
client.close();
}
});
}

export const sendMessageToSocketHelper = (wss, connectionId, data) => {
wss.clients.forEach((client) => {
if(client.connectionId == connectionId){
if(client.readyState === WebSocket.OPEN){
if (client.connectionId == connectionId) {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify(data));
}
}
Expand Down

0 comments on commit d346be5

Please sign in to comment.