:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(desktop/command-center): random youtube video in brainrot cell (#81082)
Joe Martin246e3c8b7bf6
diff --git a/products/desktop/packages/ui/src/features/command-center/components/CommandCenterPanel.tsx b/products/desktop/packages/ui/src/features/command-center/components/CommandCenterPanel.tsxindex acb9c0cc77ba..a6db853c90d5 100644--- a/products/desktop/packages/ui/src/features/command-center/components/CommandCenterPanel.tsx+++ b/products/desktop/packages/ui/src/features/command-center/components/CommandCenterPanel.tsx@@ -10,6 +10,7 @@ import {X,} from "@phosphor-icons/react";import { isBrainrotCell } from "@posthog/core/command-center/grid";+import { Spinner as QuillSpinner, Text as QuillText } from "@posthog/quill";import { ANALYTICS_EVENTS, type WorkspaceMode } from "@posthog/shared";import type { Task } from "@posthog/shared/domain-types";import { useSettingsStore } from "@posthog/ui/features/settings/settingsStore";@@ -19,7 +20,7 @@ import { openTask } from "@posthog/ui/router/useOpenTask";import { track } from "@posthog/ui/shell/analytics";import { useHostCapabilities } from "@posthog/ui/shell/useHostCapabilities";import { secureRandomString } from "@posthog/ui/utils/random";-import { Flex, Spinner, Text } from "@radix-ui/themes";+import { Flex, Text } from "@radix-ui/themes";import { useCallback, useEffect, useRef, useState } from "react";import { useFolders } from "../../folders/useFolders";import { useCloudPrUrl } from "../../git-interaction/useCloudPrUrl";@@ -33,7 +34,6 @@ import type {CellStatus,CommandCenterCellData,} from "../hooks/useCommandCenterData";-import { useElementOrientation } from "../hooks/useElementOrientation";import { getTerminalCellStateKey } from "../terminalCells";import { CommandCenterPRButton } from "./CommandCenterPRButton";import { TaskSelector } from "./TaskSelector";@@ -221,32 +221,91 @@ function EmptyCell({ cellIndex }: { cellIndex: number }) {);}-const BRAINROT_LANDSCAPE_URL =- "https://res.cloudinary.com/dmukukwp6/video/upload/brainrot_landscape_051f419306.mp4";-const BRAINROT_PORTRAIT_URL =- "https://res.cloudinary.com/dmukukwp6/video/upload/brainrot_portrait_0f14096e6a.mp4";+const BRAINROT_PLAYLIST_IDS = [+ "PLnOY1RYHjDfw2joBxUPADaadeX5IradbH",+ "PLSzOLzwLMqSM",+];+const BRAINROT_EMBED_ORIGIN = "https://www.youtube-nocookie.com";++function brainrotEmbedUrl(playlistId: string): string {+ return `${BRAINROT_EMBED_ORIGIN}/embed/videoseries?list=${playlistId}&enablejsapi=1&autoplay=1&mute=1&playsinline=1&rel=0`;+}++function pickBrainrotEmbedUrl(): string {+ const playlistId =+ BRAINROT_PLAYLIST_IDS[+ Math.floor(Math.random() * BRAINROT_PLAYLIST_IDS.length)+ ];+ return brainrotEmbedUrl(playlistId);+}function BrainrotCell({ cellIndex }: { cellIndex: number }) {const clearCell = useCommandCenterStore((s) => s.clearCell);- const stageRef = useRef<HTMLDivElement>(null);- const orientation = useElementOrientation(stageRef);- const src =- orientation === "portrait" ? BRAINROT_PORTRAIT_URL : BRAINROT_LANDSCAPE_URL;+ const iframeRef = useRef<HTMLIFrameElement>(null);+ const randomizedRef = useRef(false);const [loading, setLoading] = useState(true);+ // Lazy initializer so the playlist choice is made once per mount.+ const [embedUrl] = useState(pickBrainrotEmbedUrl);++ const postToPlayer = useCallback((func: string, args: unknown[]) => {+ iframeRef.current?.contentWindow?.postMessage(+ JSON.stringify({ event: "command", func, args }),+ BRAINROT_EMBED_ORIGIN,+ );+ }, []);++ useEffect(() => {+ // The embed widget only reports the playlist contents over postMessage+ // after a "listening" handshake (sent in handleLoad). That report is the+ // keyless way to learn the playlist length, so the jump to a random video+ // has to happen here rather than via a URL parameter.+ const onMessage = (event: MessageEvent) => {+ if (event.origin !== BRAINROT_EMBED_ORIGIN) return;+ if (event.source !== iframeRef.current?.contentWindow) return;+ if (typeof event.data !== "string") return;+ let message: { info?: { playlist?: unknown } };+ try {+ message = JSON.parse(event.data);+ } catch {+ return;+ }+ const playlist = message.info?.playlist;+ if (+ randomizedRef.current ||+ !Array.isArray(playlist) ||+ playlist.length === 0+ ) {+ return;+ }+ randomizedRef.current = true;+ postToPlayer("playVideoAt", [+ Math.floor(Math.random() * playlist.length),+ ]);+ postToPlayer("setLoop", [true]);+ };+ window.addEventListener("message", onMessage);+ return () => window.removeEventListener("message", onMessage);+ }, [postToPlayer]);++ const handleLoad = useCallback(() => {+ setLoading(false);+ iframeRef.current?.contentWindow?.postMessage(+ JSON.stringify({+ event: "listening",+ id: `brainrot-${cellIndex}`,+ channel: "widget",+ }),+ BRAINROT_EMBED_ORIGIN,+ );+ }, [cellIndex]);return (- <Flex direction="column" height="100%">- <Flex- align="center"- gap="2"- px="2"- py="1"- className="shrink-0 border-gray-6 border-b"- >+ <div className="flex h-full flex-col">+ <div className="flex shrink-0 items-center gap-2 border-gray-6 border-b px-2 py-1"><Lightning size={12} weight="fill" className="shrink-0 text-amber-9" />- <Text className="min-w-0 flex-1 truncate font-medium text-[12px]">+ <QuillText className="min-w-0 flex-1 truncate font-medium text-[12px]">Brainrot- </Text>+ </QuillText><buttontype="button"onClick={() => clearCell(cellIndex)}@@ -255,30 +314,24 @@ function BrainrotCell({ cellIndex }: { cellIndex: number }) {><X size={12} /></button>- </Flex>- <div- ref={stageRef}- className="relative min-h-0 flex-1 overflow-hidden bg-black"- >- <video- key={orientation}- src={src}- aria-label="Brainrot"- autoPlay- loop- muted- playsInline- onLoadStart={() => setLoading(true)}- onCanPlay={() => setLoading(false)}- className="h-full w-full object-contain"+ </div>+ <div className="relative min-h-0 flex-1 overflow-hidden bg-black">+ <iframe+ ref={iframeRef}+ src={embedUrl}+ title="Brainrot"+ allow="autoplay; encrypted-media; picture-in-picture"+ allowFullScreen+ onLoad={handleLoad}+ className="h-full w-full border-0"/>{loading && (<div className="absolute inset-0 flex items-center justify-center text-gray-11">- <Spinner size="3" />+ <QuillSpinner className="h-6 w-6" /></div>)}</div>- </Flex>+ </div>);}diff --git a/products/desktop/packages/ui/src/features/command-center/hooks/useElementOrientation.ts b/products/desktop/packages/ui/src/features/command-center/hooks/useElementOrientation.tsdeleted file mode 100644index 4d0017a774cc..000000000000--- a/products/desktop/packages/ui/src/features/command-center/hooks/useElementOrientation.ts+++ /dev/null@@ -1,26 +0,0 @@-import { type RefObject, useEffect, useState } from "react";--export type Orientation = "landscape" | "portrait";--// Reports whether the element is wider than tall, so a matching-orientation-// video can be chosen as the grid resizes.-export function useElementOrientation(- ref: RefObject<HTMLElement | null>,-): Orientation {- const [orientation, setOrientation] = useState<Orientation>("landscape");-- useEffect(() => {- const element = ref.current;- if (!element) return;-- const observer = new ResizeObserver((entries) => {- const box = entries[0]?.contentRect;- if (!box || box.width === 0 || box.height === 0) return;- setOrientation(box.width >= box.height ? "landscape" : "portrait");- });- observer.observe(element);- return () => observer.disconnect();- }, [ref]);-- return orientation;-}