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

fix: message not sending #615

Merged
merged 8 commits into from
Jun 23, 2024
Merged

fix: message not sending #615

merged 8 commits into from
Jun 23, 2024

Conversation

Dun-sin
Copy link
Owner

@Dun-sin Dun-sin commented Jun 23, 2024

Fixes Issue

My PR closes #610

πŸ‘¨β€πŸ’» Changes proposed(What did you do ?)

  • Send the current user's chat room ID on every connect to ensure users are always in the same room, resolving key exchange issues.
  • Use a useRef to store the crypto key value and using it in the onNewMessageHandler to ensure proper decryption.
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.

```
setTimeout(() => {
// Key exchange logic
}, 3000);
```

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.

 ```
	useEffect(() => {
		generateKeyPair();
	}, [currentChatId]);
	```

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 the onNewMessageHandler function.

```javascript
const cryptoKeyRef = useRef(null);
cryptoKeyRef.current = cryptoKey;
```

βœ”οΈ Check List (Check all the applicable boxes)

  • My code follows the code style of this project.
  • This PR does not contain plagiarized content.
  • The title and description of the PR is clear and explains the approach.

Copy link

render bot commented Jun 23, 2024

Copy link

vercel bot commented Jun 23, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
whisper ❌ Failed (Inspect) Jun 23, 2024 10:58am
whisper-b2p2 βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Jun 23, 2024 10:58am

@Dun-sin Dun-sin merged commit 33a9293 into main Jun 23, 2024
3 of 4 checks passed
@Dun-sin Dun-sin deleted the fix/message-not-sending branch June 23, 2024 10:59
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.

[BUG] Message not sending
1 participant