Display call member speaking status on bottom bar (#2742)
* add mutation observer hok * add hook to read speaking member by observing iframe content * display speaking member name in call status bar and improve layout * fix shrining
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { useEffect, useMemo } from 'react';
|
||||
|
||||
export type OnMutationCallback = (mutations: MutationRecord[]) => void;
|
||||
|
||||
export const getMutationRecord = (
|
||||
target: Node,
|
||||
mutations: MutationRecord[]
|
||||
): MutationRecord | undefined => mutations.find((mutation) => mutation.target === target);
|
||||
|
||||
export const useMutationObserver = (
|
||||
onMutationCallback: OnMutationCallback,
|
||||
observeElement?: Node | null | (() => Node | null),
|
||||
options?: MutationObserverInit
|
||||
): MutationObserver => {
|
||||
const mutationObserver = useMemo(
|
||||
() => new MutationObserver(onMutationCallback),
|
||||
[onMutationCallback]
|
||||
);
|
||||
|
||||
useEffect(() => () => mutationObserver?.disconnect(), [mutationObserver]);
|
||||
|
||||
useEffect(() => {
|
||||
const element = typeof observeElement === 'function' ? observeElement() : observeElement;
|
||||
|
||||
if (element) {
|
||||
mutationObserver.observe(element, options);
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (element) {
|
||||
mutationObserver.disconnect();
|
||||
}
|
||||
};
|
||||
}, [mutationObserver, observeElement, options]);
|
||||
|
||||
return mutationObserver;
|
||||
};
|
||||
Reference in New Issue
Block a user