🥚(frontend) add Konami code detector to unlock April Fool's effects

Implement easter egg that reveals fun features originally created for
April Fool's Day when users enter the Konami sequence.
This commit is contained in:
lebaudantoine
2025-04-30 17:42:13 +02:00
committed by aleb_the_flash
parent b27c5e9b92
commit 8023e44f71
5 changed files with 69 additions and 13 deletions

View File

@@ -17,7 +17,7 @@ import { Loader } from '@/primitives/Loader'
import { useSyncAfterDelay } from '@/hooks/useSyncAfterDelay'
import { RiProhibited2Line } from '@remixicon/react'
import { FunnyEffects } from './FunnyEffects'
import { useHasFaceLandmarksAccess } from '../../hooks/useHasFaceLandmarksAccess'
import { useHasFunnyEffectsAccess } from '../../hooks/useHasFunnyEffectsAccess'
enum BlurRadius {
NONE = 0,
@@ -52,7 +52,7 @@ export const EffectsConfiguration = ({
const { toggle, enabled } = useTrackToggle({ source: Track.Source.Camera })
const [processorPending, setProcessorPending] = useState(false)
const processorPendingReveal = useSyncAfterDelay(processorPending)
const hasFaceLandmarksAccess = useHasFaceLandmarksAccess()
const hasFunnyEffectsAccess = useHasFunnyEffectsAccess()
useEffect(() => {
const videoElement = videoRef.current
@@ -239,7 +239,7 @@ export const EffectsConfiguration = ({
: {}
)}
>
{hasFaceLandmarksAccess && (
{hasFunnyEffectsAccess && (
<FunnyEffects
videoTrack={videoTrack}
isPending={processorPendingReveal}

View File

@@ -1,10 +0,0 @@
import { useFeatureFlagEnabled } from 'posthog-js/react'
import { useIsAnalyticsEnabled } from '@/features/analytics/hooks/useIsAnalyticsEnabled'
import { FeatureFlags } from '@/features/analytics/enums'
export const useHasFaceLandmarksAccess = () => {
const featureEnabled = useFeatureFlagEnabled(FeatureFlags.faceLandmarks)
const isAnalyticsEnabled = useIsAnalyticsEnabled()
return featureEnabled || !isAnalyticsEnabled
}

View File

@@ -0,0 +1,22 @@
import { useFeatureFlagEnabled } from 'posthog-js/react'
import { useIsAnalyticsEnabled } from '@/features/analytics/hooks/useIsAnalyticsEnabled'
import { FeatureFlags } from '@/features/analytics/enums'
import useKonami from '@/features/rooms/livekit/hooks/useKonami'
import { konamiStore } from '@/stores/konami'
import { useSnapshot } from 'valtio'
export const useHasFunnyEffectsAccess = () => {
const featureEnabled = useFeatureFlagEnabled(FeatureFlags.faceLandmarks)
const isAnalyticsEnabled = useIsAnalyticsEnabled()
const konamiSnap = useSnapshot(konamiStore)
useKonami(
() =>
(konamiStore.areFunnyEffectsEnabled = !konamiSnap.areFunnyEffectsEnabled)
)
return (
(featureEnabled || !isAnalyticsEnabled) && konamiSnap.areFunnyEffectsEnabled
)
}

View File

@@ -0,0 +1,35 @@
/**
* Konami Code Detector Component
* This implementation is taken from: vmarchesin/react-konami-code
*/
import { useCallback, useEffect, useState } from 'react'
export const KONAMI_CODE = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]
function useKonami(action: () => void, { code = KONAMI_CODE } = {}) {
const [input, setInput] = useState<number[]>([])
const onKeyUp = useCallback(
(e: KeyboardEvent) => {
const newInput = input
newInput.push(e.keyCode)
newInput.splice(-code.length - 1, input.length - code.length)
setInput(newInput)
if (newInput.join('').includes(code.join(''))) {
action()
}
},
[input, setInput, code, action]
)
useEffect(() => {
document.addEventListener('keyup', onKeyUp)
return () => {
document.removeEventListener('keyup', onKeyUp)
}
}, [onKeyUp])
}
export default useKonami

View File

@@ -0,0 +1,9 @@
import { proxy } from 'valtio'
type State = {
areFunnyEffectsEnabled: boolean
}
export const konamiStore = proxy<State>({
areFunnyEffectsEnabled: false,
})