Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes Issue
My PR closes #610
π¨βπ» Changes proposed(What did you do ?)
Debugging Issue #610
Problem: Initial Key Exchange Failure
Messages were not being sent due to a failure in the exchange of crypto keys, caused by users attempting to exchange keys before being correctly assigned to chat rooms.
Solution
To address this, a delay of 3 seconds was introduced in the key exchange process using the
setTimeout
function. This delay ensured that all users were properly connected before initiating the key exchange.By delaying the key exchange, we ensured that all users were fully connected before initiating the process. Specifically, this approach ensured that the client creating the chat (User 1) sent keys only after all participants, including those joining (User 2), were successfully connected. Consequently, User 2 received the necessary keys from User 1, resolving the synchronization issue.
Problem: Timer Issue in Production
The timer used in development failed in production, leading to decryption issues. Keys were being sent on every render from both sides instead of being exchanged, causing new socket IDs to be created each time.
Solution
To resolve this, the process of creating keys was moved to a hook and called after the search successfully ended in BuddyMatcher. This prevented keys from being sent multiple times. However, an issue arose where only one user received the keys due to incorrect placement of the key generation code and multiple function calls.
Problem: Decryption not working
The decryption function did not receive the crypto key properly. Although the crypto key was updated in the hook, it did not reflect in the
onNewMessageHandler
function.Solution
To fix this, a
useRef
was used to store the crypto key value, which was then used in theonNewMessageHandler
function.βοΈ Check List (Check all the applicable boxes)