forked from OurProjectsCombined/chat-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Keagan Aromin
authored and
Keagan Aromin
committed
Jan 12, 2025
1 parent
5cafe5f
commit 7d2ee3a
Showing
7 changed files
with
72 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useSocketContext } from '../context/SocketContext' | ||
import useConversation from '../zustand/useConversation' | ||
import { useEffect } from 'react' | ||
import notificationSound from '../assets/sounds/notification.mp3' | ||
|
||
const useListenMessages = () => { | ||
const { socket } = useSocketContext(); | ||
const { messages, setMessages } = useConversation(); | ||
|
||
useEffect(() => { | ||
socket?.on('newMessage', (newMessage) => { | ||
newMessage.shouldShake = true; | ||
const sound = new Audio(notificationSound); | ||
sound.play(); | ||
setMessages([...messages, newMessage]) | ||
}) | ||
|
||
//this line is important so we don't stack calls (this will stack notification sounds) | ||
return () => socket?.off('newMessage') | ||
}, [socket, setMessages, messages]) | ||
} | ||
|
||
export default useListenMessages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters