Skip to content

armgit / meet

Public Imported from GitHub
0

Open source video conferencing app powered by LiveKit. Built with Django and React.

♻️(frontend) extract notification decoding logic for reusability

lebaudantoine92851b10ccc8
diff --git a/src/frontend/src/features/notifications/MainNotificationToast.tsx b/src/frontend/src/features/notifications/MainNotificationToast.tsx
index 81520967..1a9274ff 100644
--- a/src/frontend/src/features/notifications/MainNotificationToast.tsx
+++ b/src/frontend/src/features/notifications/MainNotificationToast.tsx
@@ -4,6 +4,7 @@ import { Participant, RemoteParticipant, RoomEvent } from 'livekit-client'
import { ToastProvider, toastQueue } from './components/ToastProvider'
import { NotificationType } from './NotificationType'
import { NotificationDuration } from './NotificationDuration'
+import { decodeNotificationDataReceived } from './utils'
import { Div } from '@/primitives'
import { ChatMessage, isMobileBrowser } from '@livekit/components-core'
import { useNotificationSound } from '@/features/notifications/hooks/useSoundNotification'
@@ -67,14 +68,11 @@ export const MainNotificationToast = () => {
payload: Uint8Array,
participant?: RemoteParticipant
) => {
- const decoder = new TextDecoder()
- const notificationPayload = JSON.parse(decoder.decode(payload))
- const notificationType = notificationPayload.type
- const data = notificationPayload.data
+ const { type, data } = decodeNotificationDataReceived(payload)
if (!participant) return
- switch (notificationType) {
+ switch (type) {
case NotificationType.ParticipantMuted:
toastQueue.add(
{
@@ -85,7 +83,7 @@ export const MainNotificationToast = () => {
)
break
case NotificationType.ReactionReceived:
- handleEmoji(data?.emoji, participant)
+ if (data?.emoji) handleEmoji(data.emoji, participant)
break
default:
return
diff --git a/src/frontend/src/features/notifications/utils.ts b/src/frontend/src/features/notifications/utils.ts
index 58605f3d..2b756801 100644
--- a/src/frontend/src/features/notifications/utils.ts
+++ b/src/frontend/src/features/notifications/utils.ts
@@ -2,6 +2,7 @@ import { toastQueue } from './components/ToastProvider'
import { NotificationType } from './NotificationType'
import { NotificationDuration } from './NotificationDuration'
import { Participant } from 'livekit-client'
+import { NotificationPayload } from './NotificationPayload'
export const showLowerHandToast = (
participant: Participant,
@@ -26,3 +27,10 @@ export const closeLowerHandToasts = () => {
}
})
}
+
+export const decodeNotificationDataReceived = (
+ payload: Uint8Array
+): NotificationPayload => {
+ const decoder = new TextDecoder()
+ return JSON.parse(decoder.decode(payload))
+}