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?: any

Ignored by React.

Only kept in types for backwards compatibility. Will be removed in a future major release.

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'