@100mslive/hms-whiteboard
v0.1.2
Published
[](https://github.com/100mslive/web-sdks/actions/workflows/lint-test-build.yml) [?.whiteboard; // Array<'read' | 'write' | 'admin'>
const isAdmin = !!permissions?.includes('admin');
const whiteboard = hmsStore.getState(selectWhiteboard);
const isOwner = whiteboard?.owner === localPeerUserId;
const toggle = async () => {
if (!isAdmin) {
return;
}
if (whiteboard?.open) {
isOwner && (await actions.interactivityCenter.whiteboard.close());
} else {
await actions.interactivityCenter.whiteboard.open();
}
};
// usage
const toggleButton = document.getElementById('toggle-whiteboard');
// non-admin users cannot toggle the whiteboard
toggleButton.disabled = !isAdmin;
toggleButton.onclick = toggle;// React Example
import React from 'react';
import { useWhiteboard } from '@100mslive/react-sdk';
export const WhiteboardToggle = () => {
const { toggle, open, isOwner } = useWhiteboard();
// non-admin users cannot toggle the whiteboard
if (!toggle) {
return null;
}
return (
<Button onClick={toggle} active={!open} disabled={open && !isOwner}>
Toggle Whitboard
</Button>
);
};Displaying the Collaborative Whiteboard
You can display the whiteboard when it's open by embedding it as an iframe or as a React component for more fine-grained controls, if your app is built using React.
// Vanilla JavaScript Example
import { selectWhiteboard } from '@100mslive/hms-video-store';
const whiteboard = hmsStore.subscribe((whiteboard) => {
if (whiteboard?.open && whiteboard?.url) {
const whiteboardIframe = document.createElement('iframe');
whiteboardIframe.src = whiteboard.url;
} else {
const whiteboardIframe = document.getElementById('whiteboard');
whiteboardIframe?.remove();
}
}, selectWhiteboard);// React Example
import React from 'react';
import { useWhiteboard } from '@100mslive/react-sdk';
import { Whiteboard } from '@100mslive/hms-whiteboard';
import '@100mslive/hms-whiteboard/index.css';
const WhiteboardEmbed = () => {
const { token, endpoint } = useWhiteboard();
if (!token) {
return null;
}
return (
<div style={{ width: '100%', height: '650px' }}>
<Whiteboard
token={token}
endpoint={`https://${endpoint}`}
onMount={({ store, editor }) => {
console.log(store, editor);
}}
/>
</div>
);
};Whiteboard related CSS needs to be imported in your app's top level CSS files using @import '@100mslive/hms-whiteboard/index.css';(recommended) or in one of your top level JS file using import '@100mslive/hms-whiteboard/index.css';.
Note that if you're using @100mslive/roomkit-react you'll need to import @100mslive/roomkit-react/index.css accordingly.
