-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: feat/presistent-socket
Are you sure you want to change the base?
Conversation
}); | ||
|
||
// Listen for when the client connects via socket.io-client | ||
io.on('connection', socket => { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
}); | ||
}); | ||
|
||
// When disconnect from client |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
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', { |
There was a problem hiding this comment.
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.
delete sockets[usertoken]; | ||
}; | ||
|
||
export { sockets, updateSocket, removeSocket }; | ||
const emitMessage = (socket, message, data) => { | ||
if (socket) { |
There was a problem hiding this comment.
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.
}); | ||
|
||
// When disconnect from client |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
No description provided.