Last active
January 17, 2024 09:15
-
-
Save Tushkiz/6b1d919f836072c20a59f5a827cd00ba to your computer and use it in GitHub Desktop.
show/hide name tag dyte component on mouse move
This file contains hidden or 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
import { useCallback, useEffect, useRef, useState } from 'react'; | |
import DyteClient from '@dytesdk/web-core'; | |
import { DyteGrid, DyteUIBuilder, generateConfig } from '@dytesdk/react-ui-kit'; | |
type UIConfig = ReturnType<typeof generateConfig>['config']; | |
function ParticipantTileApp() { | |
const [meeting, setMeeting] = useState<DyteClient | null>(null); | |
const [uiConfig, setUIConfig] = useState<UIConfig>(); | |
const timerId = useRef<number>(); | |
const url = new URL(window.location.href); | |
const queryToken = url.searchParams.get('authToken')!; | |
if (!queryToken) { | |
alert('Please add authToken to url query params'); | |
} | |
const moveHandler = useCallback(() => { | |
if (uiConfig?.root) { | |
const builder = new DyteUIBuilder(uiConfig); | |
const participantTile = builder.find('dyte-participant-tile'); | |
if (!participantTile) return; | |
if (!timerId.current) { | |
participantTile.add('dyte-name-tag'); | |
setUIConfig(builder.build()); | |
} | |
clearTimeout(timerId.current); | |
timerId.current = setTimeout(() => { | |
participantTile.remove('dyte-name-tag'); | |
setUIConfig(builder.build()); | |
timerId.current = undefined; | |
}, 3000); | |
} | |
}, [uiConfig]); | |
useEffect(() => { | |
if (meeting) return; | |
const init = async () => { | |
DyteClient.init({ | |
defaults: { audio: false, video: false }, | |
authToken: queryToken, | |
}).then(async (m) => { | |
await m.join(); | |
setMeeting(m); | |
setUIConfig(generateConfig(m.self.suggestedTheme, m).config); | |
}); | |
}; | |
init(); | |
}, [meeting, moveHandler, queryToken, uiConfig]); | |
if (!meeting) { | |
return 'Loading...'; | |
} | |
return ( | |
<div style={{ height: '100vh' }}> | |
<DyteGrid meeting={meeting} config={uiConfig} onMouseMove={moveHandler} /> | |
</div> | |
); | |
} | |
export default ParticipantTileApp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment