Function Whiteboard

Whiteboard component provides a collaborative drawing interface with features such as freehand drawing, erasing, shapes, and undo/redo functionality.

import { Whiteboard } from 'mediasfu-reactjs';
import { io } from 'socket.io-client';

const parameters = {
socket: io("http://localhost:3000"),
showAlert: (alert) => console.log(alert),
islevel: "2",
roomName: "Room 1",
shapes: [],
useImageBackground: false,
redoStack: [],
undoStack: [],
whiteboardStarted: true,
whiteboardEnded: false,
whiteboardUsers: [{ id: "user1", name: "John" }],
participants: [{ id: "user1", name: "John", islevel: "1" }],
screenId: "screen1",
recordStarted: false,
recordStopped: false,
recordPaused: false,
recordResumed: false,
recordingMediaOptions: "video",
member: "John",
shareScreenStarted: false,
updateShapes: (newShapes) => console.log("Shapes updated:", newShapes),
updateUseImageBackground: (useImageBackground) => console.log("Background updated:", useImageBackground),
updateRedoStack: (redoStack) => console.log("Redo stack updated:", redoStack),
updateUndoStack: (undoStack) => console.log("Undo stack updated:", undoStack),
updateWhiteboardStarted: (started) => console.log("Whiteboard started:", started),
updateWhiteboardEnded: (ended) => console.log("Whiteboard ended:", ended),
updateWhiteboardUsers: (users) => console.log("Whiteboard users updated:", users),
updateParticipants: (participants) => console.log("Participants updated:", participants),
updateScreenId: (screenId) => console.log("Screen ID updated:", screenId),
updateShareScreenStarted: (shareStarted) => console.log("Screen sharing started:", shareStarted),
updateCanvasWhiteboard: (canvas) => console.log("Canvas updated:", canvas),
onScreenChanges: ({ changed }) => console.log("Screen changed:", changed),
captureCanvasStream: () => console.log("Canvas stream captured"),
};

<Whiteboard
customWidth={800}
customHeight={600}
parameters={parameters}
showAspect={true}
/>

This component supports multiple drawing modes (pen, eraser, shapes) and manages complex state interactions. It leverages HTML5 Canvas for drawing operations and supports touch events for mobile devices. Various useEffect hooks initialize and set up event listeners, while methods handle drawing, erasing, zooming, and shape manipulation.

Properties

propTypes?: WeakValidationMap<WhiteboardOptions>

Used to declare the types of the props accepted by the component. These types will be checked during rendering and in development only.

We recommend using TypeScript instead of checking prop types at runtime.

contextTypes?: ValidationMap<any>

Lets you specify which legacy context is consumed by this component.

defaultProps?: Partial<WhiteboardOptions>

Used to define default values for the props accepted by the component.

type Props = { name?: string }

const MyComponent: FC<Props> = (props) => {
return <div>{props.name}</div>
}

MyComponent.defaultProps = {
name: 'John Doe'
}
displayName?: string

Used in debugging messages. You might want to set it explicitly if you want to display a different name for debugging purposes.


const MyComponent: FC = () => {
return <div>Hello!</div>
}

MyComponent.displayName = 'MyAwesomeComponent'