Skip to content
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

Backend socket manager #41

Open
wants to merge 5 commits into
base: feat/presistent-socket
Choose a base branch
from

Conversation

UmangSharma5
Copy link
Owner

No description provided.

@shaantanu314 shaantanu314 changed the base branch from main to feat/presistent-socket March 5, 2024 08:25
});

// Listen for when the client connects via socket.io-client
io.on('connection', socket => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    The variable `usertoken` is assigned from `user.socket_id`, which may lead to issues if `user` does not have a `socket_id` property. Consider adding a check to ensure `user.socket_id` exists before using it.

This comment was auto-generated by Code Bot to provide suggestions and improvements.

@@ -1,3 +1,5 @@
import { Server } from 'socket.io';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    The import statement is correct, but consider adding a comment to explain the purpose of the imported `Server` from 'socket.io'. This will improve code readability.

This comment was auto-generated by Code Bot to provide suggestions and improvements.

Comment on lines +36 to +39
});
});

// When disconnect from client
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    The disconnect event is currently not logging any information. It would be beneficial to log the socket ID of the user who disconnected for better debugging and monitoring.

This comment was auto-generated by Code Bot to provide suggestions and improvements.

@@ -7,8 +7,7 @@ import http from 'http';
import { fileURLToPath } from 'url';
import require_auth from './middleware/Auth.js';
import require_auth_proxylinks from './middleware/proxyLinksAuth.js';
import { updateSocket } from './SocketManager/socketmanager.js';
import { Server } from 'socket.io';
import initializeSocket from './SocketManager/socketmanager.js';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    The import statement for `initializeSocket` should be consistent with the previous implementation. Ensure that the new socket management approach is correctly integrated. If `initializeSocket` does not provide the same functionality as `updateSocket`, this could lead to issues in user session management.

This comment was auto-generated by Code Bot to provide suggestions and improvements.

Comment on lines 28 to 34
io.on('connection', socket => {
console.warn(`User connected ${socket.id}`);

socket.on('addUser', user => {
let usertoken = user.socket_id;
updateSocket(usertoken, socket);
socket.emit('AddedUser', {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    In the `addUser` event handler, consider adding error handling for cases where the `usertoken` might be undefined or invalid. This will help avoid issues when trying to update the socket.

This comment was auto-generated by Code Bot to provide suggestions and improvements.

Comment on lines 10 to +14
delete sockets[usertoken];
};

export { sockets, updateSocket, removeSocket };
const emitMessage = (socket, message, data) => {
if (socket) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    The `emitMessage` function could benefit from additional error handling. Consider checking if the `message` and `data` parameters are valid before emitting. This will prevent potential runtime errors.

This comment was auto-generated by Code Bot to provide suggestions and improvements.

Comment on lines +37 to +39
});

// When disconnect from client
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    The disconnect event handler is currently empty. It would be beneficial to log the disconnection or perform any necessary cleanup actions to maintain socket management integrity.

This comment was auto-generated by Code Bot to provide suggestions and improvements.

@@ -1,3 +1,5 @@
import { Server } from 'socket.io';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    The import statement is correct, but consider adding a comment to explain the purpose of the imported `Server` from 'socket.io'. This will improve code readability.

This comment was auto-generated by Code Bot to provide suggestions and improvements.

@@ -7,8 +7,7 @@ import http from 'http';
import { fileURLToPath } from 'url';
import require_auth from './middleware/Auth.js';
import require_auth_proxylinks from './middleware/proxyLinksAuth.js';
import { updateSocket } from './SocketManager/socketmanager.js';
import { Server } from 'socket.io';
import initializeSocket from './SocketManager/socketmanager.js';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    The import statement for `initializeSocket` should be consistent with the naming convention. Consider renaming the file to `SocketManager.js` to match the import statement. This will improve clarity and maintainability.

This comment was auto-generated by Code Bot to provide suggestions and improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants