-
Notifications
You must be signed in to change notification settings - Fork 48
feat(react-dogfood): add collaborative whiteboard #2271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oliverlaz
wants to merge
1
commit into
main
Choose a base branch
from
worktree-whiteboards
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
sample-apps/react/react-dogfood/components/Whiteboard/ToggleWhiteboardButton.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * Media-control toggle that opens/closes the shared whiteboard for everyone. | ||
| */ | ||
| import { | ||
| CompositeButton, | ||
| useI18n, | ||
| WithTooltip, | ||
| } from '@stream-io/video-react-sdk'; | ||
|
|
||
| import type { WhiteboardApi } from './useWhiteboard'; | ||
|
|
||
| const WhiteboardIcon = () => ( | ||
| <svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true"> | ||
| <rect | ||
| x="3" | ||
| y="4" | ||
| width="18" | ||
| height="13" | ||
| rx="1.5" | ||
| stroke="currentColor" | ||
| strokeWidth="1.8" | ||
| fill="none" | ||
| /> | ||
| <path | ||
| d="M8 21h8M12 17v4" | ||
| stroke="currentColor" | ||
| strokeWidth="1.8" | ||
| fill="none" | ||
| /> | ||
| <path | ||
| d="M7 13l4-4 1.8 1.8L16 7.6" | ||
| stroke="currentColor" | ||
| strokeWidth="1.8" | ||
| fill="none" | ||
| /> | ||
| </svg> | ||
| ); | ||
|
|
||
| export const ToggleWhiteboardButton = (props: { wb: WhiteboardApi }) => { | ||
| const { wb } = props; | ||
| const { t } = useI18n(); | ||
| return ( | ||
| <WithTooltip title={t('Whiteboard')}> | ||
| <CompositeButton | ||
| active={wb.isOpen} | ||
| variant="primary" | ||
| disabled={!wb.ready} | ||
| onClick={() => (wb.isOpen ? wb.close() : wb.open())} | ||
| data-testid="whiteboard-toggle-button" | ||
| > | ||
| <WhiteboardIcon /> | ||
| </CompositeButton> | ||
| </WithTooltip> | ||
| ); | ||
| }; |
145 changes: 145 additions & 0 deletions
145
sample-apps/react/react-dogfood/components/Whiteboard/Whiteboard.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /** | ||
| * Whiteboard stage: centered canvas + bottom toolbar + right-side participants | ||
| * strip. Laid out like CallParticipantsScreenView (screen-share takeover), and | ||
| * mounted only while the board is open. Keyboard shortcuts: P/L/R/T select | ||
| * tools; Ctrl/Cmd +/-/0 control zoom. | ||
| */ | ||
| import { useEffect, useRef, useState } from 'react'; | ||
| import { | ||
| DefaultParticipantViewUI, | ||
| IconButton, | ||
| ParticipantView, | ||
| useCall, | ||
| useCallStateHooks, | ||
| useVerticalScrollPosition, | ||
| } from '@stream-io/video-react-sdk'; | ||
|
|
||
| import type { Tool } from './core/model'; | ||
| import { | ||
| WhiteboardCanvas, | ||
| type WhiteboardCanvasHandle, | ||
| } from './WhiteboardCanvas'; | ||
| import { WhiteboardToolbar } from './WhiteboardToolbar'; | ||
| import type { WhiteboardApi } from './useWhiteboard'; | ||
|
|
||
| const SHORTCUT_TOOLS: Record<string, Tool> = { | ||
| p: 'pen', | ||
| l: 'line', | ||
| r: 'rect', | ||
| t: 'text', | ||
| e: 'eraser', | ||
| h: 'pan', | ||
| }; | ||
|
|
||
| const isTypingTarget = (target: EventTarget | null): boolean => { | ||
| if (!(target instanceof HTMLElement)) return false; | ||
| const tag = target.tagName; | ||
| return tag === 'INPUT' || tag === 'TEXTAREA' || target.isContentEditable; | ||
| }; | ||
|
|
||
| const WhiteboardParticipants = () => { | ||
| const call = useCall(); | ||
| const { useParticipants } = useCallStateHooks(); | ||
| const participants = useParticipants(); | ||
| const [scrollWrapper, setScrollWrapper] = useState<HTMLDivElement | null>( | ||
| null, | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (!scrollWrapper || !call) return; | ||
| const cleanup = call.setViewport(scrollWrapper); | ||
| return () => cleanup?.(); | ||
| }, [scrollWrapper, call]); | ||
|
|
||
| const scrollPosition = useVerticalScrollPosition(scrollWrapper); | ||
|
|
||
| return ( | ||
| <div className="rd__whiteboard__participants"> | ||
| {scrollPosition && scrollPosition !== 'top' && ( | ||
| <IconButton | ||
| icon="caret-up" | ||
| onClick={() => | ||
| scrollWrapper?.scrollBy({ top: -150, behavior: 'smooth' }) | ||
| } | ||
| /> | ||
| )} | ||
| <div | ||
| ref={setScrollWrapper} | ||
| className="rd__whiteboard__participants-scroll" | ||
| > | ||
| {participants.map((participant) => ( | ||
| <ParticipantView | ||
| key={participant.sessionId} | ||
| participant={participant} | ||
| ParticipantViewUI={DefaultParticipantViewUI} | ||
| /> | ||
| ))} | ||
| </div> | ||
| {scrollPosition && scrollPosition !== 'bottom' && ( | ||
| <IconButton | ||
| icon="caret-down" | ||
| onClick={() => | ||
| scrollWrapper?.scrollBy({ top: 150, behavior: 'smooth' }) | ||
| } | ||
| /> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export const Whiteboard = (props: { wb: WhiteboardApi }) => { | ||
| const { wb } = props; | ||
| const [zoom, setZoom] = useState(1); | ||
| const handleRef = useRef<WhiteboardCanvasHandle | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const onKeyDown = (event: KeyboardEvent) => { | ||
| if (isTypingTarget(event.target)) return; | ||
| if (event.ctrlKey || event.metaKey) { | ||
| if (event.key === '=' || event.key === '+') { | ||
| event.preventDefault(); | ||
| handleRef.current?.zoomIn(); | ||
| } else if (event.key === '-') { | ||
| event.preventDefault(); | ||
| handleRef.current?.zoomOut(); | ||
| } else if (event.key === '0') { | ||
| event.preventDefault(); | ||
| handleRef.current?.reset(); | ||
| } | ||
| return; | ||
| } | ||
| const tool = SHORTCUT_TOOLS[event.key.toLowerCase()]; | ||
| if (tool) { | ||
| event.preventDefault(); | ||
| wb.setTool(tool); | ||
| } | ||
| }; | ||
| window.addEventListener('keydown', onKeyDown); | ||
| return () => window.removeEventListener('keydown', onKeyDown); | ||
| }, [wb]); | ||
|
|
||
| return ( | ||
| <div className="rd__whiteboard"> | ||
| <div className="rd__whiteboard__stage"> | ||
| <WhiteboardCanvas | ||
| wb={wb} | ||
| handleRef={handleRef} | ||
| onZoomChange={setZoom} | ||
| /> | ||
| <WhiteboardToolbar | ||
| activeTool={wb.activeTool} | ||
| setTool={wb.setTool} | ||
| color={wb.color} | ||
| setColor={wb.setColor} | ||
| onClear={wb.clear} | ||
| onZoomIn={() => handleRef.current?.zoomIn()} | ||
| onZoomOut={() => handleRef.current?.zoomOut()} | ||
| onReset={() => handleRef.current?.reset()} | ||
| onFit={() => handleRef.current?.fit()} | ||
| zoom={zoom} | ||
| /> | ||
| </div> | ||
| <WhiteboardParticipants /> | ||
| </div> | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expose the whiteboard toggle on mobile too.
Line 324 adds the only whiteboard entry point under
str-video__call-controls__desktop, so mobile participants have no way to open/close the board from call controls. That misses the PRβs core interaction path for a whole form factor.π€ Prompt for AI Agents