From a8922b43d494a9913e38e6df4d7665261fb68e21 Mon Sep 17 00:00:00 2001 From: Miron Pawlik Date: Wed, 27 Nov 2024 14:21:40 +0100 Subject: [PATCH] [FCE-930] Add useUpdatePeerMetadata hook (#203) ## Description Add new `useUpdatePeerMetadata` hook, that would allow to update metadata after connection. I've tested it with small code added in example app - it worked as expected. ## Motivation and Context Right now it is not possible to update metadata in web sdk. ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) --- packages/react-client/src/hooks/public.ts | 1 + .../src/hooks/useUpdatePeerMetadata.ts | 16 ++++++++++++++++ packages/react-client/src/index.ts | 1 + 3 files changed, 18 insertions(+) create mode 100644 packages/react-client/src/hooks/useUpdatePeerMetadata.ts diff --git a/packages/react-client/src/hooks/public.ts b/packages/react-client/src/hooks/public.ts index bc9d8f31..920ebbed 100644 --- a/packages/react-client/src/hooks/public.ts +++ b/packages/react-client/src/hooks/public.ts @@ -6,4 +6,5 @@ export { useInitializeDevices } from "./devices/useInitializeDevices"; export { usePeers } from "./usePeers"; export { useScreenShare } from "./useScreenShare"; export { useStatus } from "./useStatus"; +export { useUpdatePeerMetadata } from "./useUpdatePeerMetadata"; export { useVAD } from "./useVAD"; diff --git a/packages/react-client/src/hooks/useUpdatePeerMetadata.ts b/packages/react-client/src/hooks/useUpdatePeerMetadata.ts new file mode 100644 index 00000000..a4e8de21 --- /dev/null +++ b/packages/react-client/src/hooks/useUpdatePeerMetadata.ts @@ -0,0 +1,16 @@ +import { useCallback } from "react"; +import { useFishjamContext } from "./useFishjamContext"; +import type { GenericMetadata } from "@fishjam-cloud/ts-client"; + +export const useUpdatePeerMetadata = () => { + const { fishjamClientRef } = useFishjamContext(); + + const updatePeerMetadata = useCallback( + (peerMetadata: PeerMetadata) => { + fishjamClientRef.current.updatePeerMetadata(peerMetadata as GenericMetadata); + }, + [fishjamClientRef], + ); + + return { updatePeerMetadata }; +}; diff --git a/packages/react-client/src/index.ts b/packages/react-client/src/index.ts index 1af28555..f2c670d6 100644 --- a/packages/react-client/src/index.ts +++ b/packages/react-client/src/index.ts @@ -8,6 +8,7 @@ export { usePeers, useScreenShare, useStatus, + useUpdatePeerMetadata, useVAD, } from "./hooks/public"; export { FishjamProvider } from "./fishjamProvider";