@ngenux/ngage-whiteboarding 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,343 +1,439 @@
1
- # React Collaborative Whiteboard
2
-
3
- A React component library for creating collaborative whiteboards with real-time synchronization via WebSockets.
4
-
5
- ## ✨ Features
6
-
7
- - 🎨 **Real-time collaborative drawing** - Multiple users can draw simultaneously
8
- - 🔧 **Multiple drawing tools** - Pencil, shapes (rectangle, ellipse, arrow), eraser, line tools
9
- - â†Šī¸ **Undo/Redo functionality** - Per-user undo/redo with collaborative support
10
- - đŸ‘Ĩ **Multi-user support** - Admin controls and user permissions
11
- - 📱 **Responsive design** - Works on desktop, tablet, and mobile
12
- - 🔒 **Admin controls** - Lock/unlock canvas, clear canvas, user management
13
- - 💾 **Export functionality** - PNG, JPEG, PDF export options
14
- - đŸ—œī¸ **Data compression** - Optimized performance with automatic compression
15
- - ⚡ **Real-time sync** - Ultra-smooth 60fps collaborative drawing experience
16
- - đŸŽ¯ **TypeScript support** - Fully typed for better development experience
17
-
18
- ## 📋 Prerequisites
19
-
20
- This package requires the following dependencies in your project:
21
-
22
- - **React** 16.8+ (with Hooks support)
23
- - **Tailwind CSS** 3.0+ (for styling)
24
- - **Vite** or similar modern bundler (recommended)
25
-
26
- ### Optional but Recommended:
27
- - **shadcn/ui** setup for consistent design system
28
-
29
- ## đŸ“Ļ Installation
30
-
31
- ### Step 1: Install the Package
32
-
33
- ```bash
34
- npm install @ngenux/ngage-whiteboarding
35
- ```
36
-
37
- ### Step 2: Setup Tailwind CSS (if not already installed)
38
-
39
- ```bash
40
- npm install -D tailwindcss postcss autoprefixer
41
- npx tailwindcss init -p
42
- ```
43
-
44
- ### Step 3: Configure Tailwind
45
-
46
- Update your `tailwind.config.js` to include the package components:
47
-
48
- ```js
49
- /** @type {import('tailwindcss').Config} */
50
- module.exports = {
51
- content: [
52
- "./src/**/*.{js,ts,jsx,tsx}",
53
- "./node_modules/@ngenux/ngage-whiteboarding/**/*.{js,jsx,ts,tsx}",
54
- ],
55
- theme: {
56
- extend: {},
57
- },
58
- plugins: [],
59
- }
60
- ```
61
-
62
- ### Step 4: Import Styles
63
-
64
- Add the package CSS to your main CSS file or import it in your main component:
65
-
66
- ```css
67
- /* In your main CSS file (e.g., src/index.css) */
68
- @tailwind base;
69
- @tailwind components;
70
- @tailwind utilities;
71
- ```
72
-
73
- ```tsx
74
- // Or import in your main component
75
- import '@ngenux/ngage-whiteboarding/dist/styles.css';
76
- ```
77
-
78
- ### Step 5: Verify Setup
79
-
80
- Create a simple test component to verify everything is working:
81
-
82
- ```tsx
83
- import React from 'react';
84
- import '@ngenux/ngage-whiteboarding/dist/styles.css';
85
- import { WhiteboardProvider, Whiteboard } from '@ngenux/ngage-whiteboarding';
86
-
87
- function TestWhiteboard() {
88
- return (
89
- <div style={{ width: '100vw', height: '100vh' }}>
90
- <WhiteboardProvider webSocketUrl="ws://localhost:3001">
91
- <Whiteboard
92
- roomId="test-room"
93
- userId="test-user"
94
- isAdmin={true}
95
- allowedUsers={['test-user']}
96
- />
97
- </WhiteboardProvider>
98
- </div>
99
- );
100
- }
101
-
102
- export default TestWhiteboard;
103
- ```
104
-
105
- If you see a styled whiteboard with a toolbar and sidebar, your setup is complete! 🎉
106
-
107
- ## 🚀 Quick Start
108
-
109
- ### Basic Setup
110
-
111
- ```tsx
112
- import React from 'react';
113
- import '@ngenux/ngage-whiteboarding/dist/styles.css'; // Import the CSS
114
- import { WhiteboardProvider, Whiteboard } from '@ngenux/ngage-whiteboarding';
115
-
116
- function App() {
117
- return (
118
- <WhiteboardProvider webSocketUrl="ws://localhost:3001">
119
- <Whiteboard
120
- roomId="room-123"
121
- userId="user-456"
122
- isAdmin={true}
123
- allowedUsers={['user-456', 'user-789']}
124
- />
125
- </WhiteboardProvider>
126
- );
127
- }
128
-
129
- export default App;
130
- ```
131
-
132
- ### For Vite Projects
133
-
134
- If you're using Vite, make sure your `vite.config.js` includes:
135
-
136
- ```js
137
- import { defineConfig } from 'vite'
138
- import react from '@vitejs/plugin-react'
139
-
140
- export default defineConfig({
141
- plugins: [react()],
142
- css: {
143
- postcss: './postcss.config.js', // Ensure PostCSS is configured
144
- },
145
- })
146
- ```
147
-
148
- ### For shadcn/ui Projects
149
-
150
- If you're using shadcn/ui, you can enhance the integration with our utility functions:
151
-
152
- ```tsx
153
- import { cn } from '@ngenux/ngage-whiteboarding'; // Use our cn utility
154
-
155
- // Or use with your existing shadcn/ui cn function
156
- import { cn } from '@/lib/utils';
157
- import { Whiteboard } from '@ngenux/ngage-whiteboarding';
158
-
159
- const customClasses = cn('your-custom-classes', 'conditional-class');
160
- ```
161
-
162
- ### Advanced Usage with Multiple Rooms
163
-
164
- ```tsx
165
- import React, { useState } from 'react';
166
- import { WhiteboardProvider, Whiteboard } from '@ngenux/ngage-whiteboarding';
167
-
168
- function CollaborativeApp() {
169
- const [currentRoom, setCurrentRoom] = useState('room-1');
170
- const [currentUser] = useState('user-' + Math.random().toString(36).substr(2, 9));
171
-
172
- return (
173
- <WhiteboardProvider webSocketUrl="wss://your-websocket-server.com">
174
- <div>
175
- <select value={currentRoom} onChange={(e) => setCurrentRoom(e.target.value)}>
176
- <option value="room-1">Room 1</option>
177
- <option value="room-2">Room 2</option>
178
- <option value="room-3">Room 3</option>
179
- </select>
180
-
181
- <Whiteboard
182
- roomId={currentRoom}
183
- userId={currentUser}
184
- isAdmin={currentUser === 'admin-user'}
185
- allowedUsers={[currentUser, 'other-user-1', 'other-user-2']}
186
- />
187
- </div>
188
- </WhiteboardProvider>
189
- );
190
- }
191
- ```
192
-
193
- ## 📝 API Reference
194
-
195
- ### WhiteboardProvider Props
196
-
197
- | Prop | Type | Required | Description |
198
- |------|------|----------|-------------|
199
- | `webSocketUrl` | `string` | ✅ | WebSocket server URL for real-time collaboration |
200
- | `children` | `ReactNode` | ✅ | Child components (typically contains `<Whiteboard>`) |
201
-
202
- ### Whiteboard Props
203
-
204
- | Prop | Type | Required | Default | Description |
205
- |------|------|----------|---------|-------------|
206
- | `roomId` | `string` | ✅ | - | Unique identifier for the collaboration room |
207
- | `userId` | `string` | ✅ | - | Unique identifier for the current user |
208
- | `isAdmin` | `boolean` | ❌ | `false` | Whether user has admin privileges (clear, lock/unlock) |
209
- | `allowedUsers` | `string[]` | ❌ | `[]` | Array of user IDs who have drawing permissions |
210
-
211
- ### Hooks
212
-
213
- #### useWhiteboardStream
214
-
215
- Automatically captures the whiteboard canvas as a video stream (30 FPS). No manual start/stop controls needed.
216
-
217
- ```tsx
218
- import { useWhiteboardStream } from '@ngenux/ngage-whiteboarding';
219
-
220
- function VideoStreamComponent() {
221
- const { mediaStream } = useWhiteboardStream();
222
-
223
- return (
224
- <div>
225
- {mediaStream && (
226
- <video
227
- srcObject={mediaStream}
228
- autoPlay
229
- muted
230
- style={{ width: '300px', height: '200px' }}
231
- />
232
- )}
233
- </div>
234
- );
235
- }
236
- ```
237
-
238
- **Note:** Stream capture starts automatically when the whiteboard canvas is available and can be controlled via the whiteboard context's `captureEnabled` state.
239
-
240
- ## 🎨 Features in Detail
241
-
242
- ### Drawing Tools
243
- - **Pencil**: Freehand drawing
244
- - **Shapes**: Rectangle, Ellipse, Arrow, Line
245
- - **Eraser**: Remove parts of drawings
246
- - **Select**: Move and transform shapes
247
- - **Pan**: Navigate around the canvas
248
-
249
- ### Collaborative Features
250
- - **Real-time drawing**: See other users draw in real-time
251
- - **User permissions**: Control who can draw
252
- - **Admin controls**: Lock/unlock canvas, clear all drawings
253
- - **Per-user undo/redo**: Each user maintains their own undo stack
254
-
255
- ### Export Options
256
- - **PNG**: Transparent or solid background
257
- - **JPEG**: Solid background (white if transparent is selected)
258
- - **PDF-format**: High-quality PNG optimized for printing/PDF conversion
259
-
260
- ## 🔧 TypeScript Support
261
-
262
- The package includes full TypeScript definitions:
263
-
264
- ```tsx
265
- import type {
266
- WhiteboardProps,
267
- WhiteboardProviderProps,
268
- ToolType,
269
- StrokeStyle
270
- } from '@ngenux/ngage-whiteboarding';
271
-
272
- const MyWhiteboard: React.FC<WhiteboardProps> = (props) => {
273
- // Your implementation
274
- };
275
- ```
276
-
277
- ## 🌐 Browser Support
278
-
279
- - Chrome 80+
280
- - Firefox 75+
281
- - Safari 13+
282
- - Edge 80+
283
-
284
- **Note:** Requires a modern browser with WebSocket support and ES6+ features.
285
-
286
- ## 📱 Responsive Design
287
-
288
- The whiteboard automatically adapts to different screen sizes and supports touch interactions on mobile devices.
289
-
290
- ## ⚡ Performance
291
-
292
- - **Optimized rendering**: Uses Konva.js for high-performance 2D canvas rendering
293
- - **Data compression**: Automatic compression of collaborative data
294
- - **Throttled updates**: Optimized for 60fps real-time collaboration
295
- - **Memory efficient**: Smart cleanup of stale collaborative data
296
-
297
- ## 🐛 Troubleshooting
298
-
299
- ### Common Issues
300
-
301
- 1. **Styles not appearing / Components look unstyled**
302
- - ✅ Ensure Tailwind CSS is installed and configured in your project
303
- - ✅ Add the package path to your `tailwind.config.js` content array
304
- - ✅ Import the package CSS: `import '@ngenux/ngage-whiteboarding/dist/styles.css'`
305
- - ✅ Verify your PostCSS configuration is working
306
-
307
- 2. **WebSocket connection fails**
308
- - Ensure your WebSocket server is running and accessible
309
- - Check CORS configuration on your server
310
- - Verify the `webSocketUrl` is correct
311
-
312
- 3. **Drawing doesn't sync between users**
313
- - Verify all users are in the same `roomId`
314
- - Check WebSocket server is properly broadcasting messages
315
- - Ensure `userId` is unique for each user
316
-
317
- 4. **TypeScript errors**
318
- - Make sure you're importing types correctly
319
- - Verify your TypeScript configuration includes the package types
320
- - Ensure React types are properly installed
321
-
322
- 5. **Build errors with Vite/bundler**
323
- - Update to the latest version of your bundler
324
- - Ensure PostCSS and Tailwind plugins are properly configured
325
- - Check that the package is included in your bundler's dependency optimization
326
-
327
- ## 📄 License
328
-
329
- MIT
330
-
331
-
332
- ## 📞 Support
333
-
334
- If you encounter any issues or have questions, please file an issue on the [GitHub repository](https://github.com/ngenux-accelerators/ngage-whiteboarding/issues).
335
-
336
- ---
337
-
338
- ## 👨‍đŸ’ģ Author
339
-
340
- **ng-sushil**
341
- - GitHub: [@ng-sushil](https://github.com/ng-sushil)
342
-
1
+ # React Collaborative Whiteboard
2
+
3
+ A React component library for creating collaborative whiteboards with real-time synchronization via WebSockets.
4
+
5
+ ## ✨ Features
6
+
7
+ - 🎨 **Real-time collaborative drawing** - Multiple users can draw simultaneously
8
+ - 🔧 **Multiple drawing tools** - Pencil, shapes (rectangle, ellipse, arrow), eraser, line tools
9
+ - â†Šī¸ **Undo/Redo functionality** - Per-user undo/redo with collaborative support
10
+ - đŸ‘Ĩ **Multi-user support** - Admin controls and user permissions
11
+ - 📱 **Responsive design** - Works on desktop, tablet, and mobile
12
+ - 🔒 **Admin controls** - Lock/unlock canvas, clear canvas, user management
13
+ - 💾 **Export functionality** - PNG, JPEG, PDF export options
14
+ - đŸ—œī¸ **Data compression** - Optimized performance with automatic compression
15
+ - ⚡ **Real-time sync** - Ultra-smooth 60fps collaborative drawing experience
16
+ - đŸŽ¯ **TypeScript support** - Fully typed for better development experience
17
+
18
+ ## 📋 Prerequisites
19
+
20
+ This package requires the following dependencies in your project:
21
+
22
+ - **React** 16.8+ (with Hooks support)
23
+ - **Tailwind CSS** 3.0+ (for styling)
24
+ - **Vite** or similar modern bundler (recommended)
25
+
26
+ ### Optional but Recommended:
27
+ - **shadcn/ui** setup for consistent design system
28
+
29
+ ## đŸ“Ļ Installation
30
+
31
+ ### Step 1: Install the Package
32
+
33
+ ```bash
34
+ npm install @ngenux/ngage-whiteboarding
35
+ ```
36
+
37
+ ### Step 2: Setup Tailwind CSS (if not already installed)
38
+
39
+ ```bash
40
+ npm install -D tailwindcss postcss autoprefixer
41
+ npx tailwindcss init -p
42
+ ```
43
+
44
+ ### Step 3: Configure Tailwind
45
+
46
+ Update your `tailwind.config.js` to include the package components:
47
+
48
+ ```js
49
+ /** @type {import('tailwindcss').Config} */
50
+ module.exports = {
51
+ content: [
52
+ "./src/**/*.{js,ts,jsx,tsx}",
53
+ "./node_modules/@ngenux/ngage-whiteboarding/**/*.{js,jsx,ts,tsx}",
54
+ ],
55
+ theme: {
56
+ extend: {},
57
+ },
58
+ plugins: [],
59
+ }
60
+ ```
61
+
62
+ ### Step 4: Import Styles
63
+
64
+ Add the package CSS to your main CSS file or import it in your main component:
65
+
66
+ ```css
67
+ /* In your main CSS file (e.g., src/index.css) */
68
+ @tailwind base;
69
+ @tailwind components;
70
+ @tailwind utilities;
71
+ ```
72
+
73
+ ```tsx
74
+ // Or import in your main component
75
+ import '@ngenux/ngage-whiteboarding/dist/styles.css';
76
+ ```
77
+
78
+ ### Step 5: Verify Setup
79
+
80
+ Create a simple test component to verify everything is working:
81
+
82
+ ```tsx
83
+ import React from 'react';
84
+ import '@ngenux/ngage-whiteboarding/dist/styles.css';
85
+ import { WhiteboardProvider, Whiteboard } from '@ngenux/ngage-whiteboarding';
86
+
87
+ function TestWhiteboard() {
88
+ return (
89
+ <div style={{ width: '100vw', height: '100vh' }}>
90
+ <WhiteboardProvider webSocketUrl="ws://localhost:3001">
91
+ <Whiteboard
92
+ roomId="test-room"
93
+ userId="test-user"
94
+ isAdmin={true}
95
+ allowedUsers={['test-user']}
96
+ />
97
+ </WhiteboardProvider>
98
+ </div>
99
+ );
100
+ }
101
+
102
+ export default TestWhiteboard;
103
+ ```
104
+
105
+ If you see a styled whiteboard with a toolbar and sidebar, your setup is complete! 🎉
106
+
107
+ ## 🚀 Quick Start
108
+
109
+ ### Basic Setup
110
+
111
+ ```tsx
112
+ import React from 'react';
113
+ import '@ngenux/ngage-whiteboarding/dist/styles.css'; // Import the CSS
114
+ import { WhiteboardProvider, Whiteboard } from '@ngenux/ngage-whiteboarding';
115
+
116
+ function App() {
117
+ return (
118
+ <WhiteboardProvider webSocketUrl="ws://localhost:3001">
119
+ <Whiteboard
120
+ roomId="room-123"
121
+ userId="user-456"
122
+ isAdmin={true}
123
+ allowedUsers={['user-456', 'user-789']}
124
+ />
125
+ </WhiteboardProvider>
126
+ );
127
+ }
128
+
129
+ export default App;
130
+ ```
131
+
132
+ ### For Vite Projects
133
+
134
+ If you're using Vite, make sure your `vite.config.js` includes:
135
+
136
+ ```js
137
+ import { defineConfig } from 'vite'
138
+ import react from '@vitejs/plugin-react'
139
+
140
+ export default defineConfig({
141
+ plugins: [react()],
142
+ css: {
143
+ postcss: './postcss.config.js', // Ensure PostCSS is configured
144
+ },
145
+ })
146
+ ```
147
+
148
+ ### For shadcn/ui Projects
149
+
150
+ If you're using shadcn/ui, you can enhance the integration with our utility functions:
151
+
152
+ ```tsx
153
+ import { cn } from '@ngenux/ngage-whiteboarding'; // Use our cn utility
154
+
155
+ // Or use with your existing shadcn/ui cn function
156
+ import { cn } from '@/lib/utils';
157
+ import { Whiteboard } from '@ngenux/ngage-whiteboarding';
158
+
159
+ const customClasses = cn('your-custom-classes', 'conditional-class');
160
+ ```
161
+
162
+ ### Advanced Usage with Multiple Rooms
163
+
164
+ ```tsx
165
+ import React, { useState } from 'react';
166
+ import { WhiteboardProvider, Whiteboard } from '@ngenux/ngage-whiteboarding';
167
+
168
+ function CollaborativeApp() {
169
+ const [currentRoom, setCurrentRoom] = useState('room-1');
170
+ const [currentUser] = useState('user-' + Math.random().toString(36).substr(2, 9));
171
+
172
+ return (
173
+ <WhiteboardProvider webSocketUrl="wss://your-websocket-server.com">
174
+ <div>
175
+ <select value={currentRoom} onChange={(e) => setCurrentRoom(e.target.value)}>
176
+ <option value="room-1">Room 1</option>
177
+ <option value="room-2">Room 2</option>
178
+ <option value="room-3">Room 3</option>
179
+ </select>
180
+
181
+ <Whiteboard
182
+ roomId={currentRoom}
183
+ userId={currentUser}
184
+ isAdmin={currentUser === 'admin-user'}
185
+ allowedUsers={[currentUser, 'other-user-1', 'other-user-2']}
186
+ />
187
+ </div>
188
+ </WhiteboardProvider>
189
+ );
190
+ }
191
+ ```
192
+
193
+ ### Transparent Background Configuration
194
+
195
+ If you want to enforce a transparent background and prevent users from changing it:
196
+
197
+ ```tsx
198
+ import { WhiteboardProvider, Whiteboard } from '@ngenux/ngage-whiteboarding';
199
+
200
+ function TransparentWhiteboard() {
201
+ return (
202
+ <WhiteboardProvider webSocketUrl="ws://localhost:3001">
203
+ <Whiteboard
204
+ roomId="transparent-room"
205
+ userId="user-123"
206
+ isAdmin={true}
207
+ allowedUsers={['user-123']}
208
+ transparentBackground={true} // Forces transparent & locks background
209
+ />
210
+ </WhiteboardProvider>
211
+ );
212
+ }
213
+ ```
214
+
215
+ **Behavior:**
216
+ - When `transparentBackground={true}`:
217
+ - ✅ Background is automatically set to transparent
218
+ - 🔒 Background color picker is disabled and shows "Transparent background locked"
219
+ - Perfect for overlaying the whiteboard on existing content
220
+
221
+ - When `transparentBackground={false}` (default):
222
+ - ✅ Background defaults to white
223
+ - 🎨 Users can change background color freely
224
+
225
+ ### Video Background for Annotation
226
+
227
+ Annotate over live video streams (screen-share, webcam, etc.):
228
+
229
+ ```tsx
230
+ import { WhiteboardProvider, Whiteboard } from '@ngenux/ngage-whiteboarding';
231
+ import { useEffect, useState } from 'react';
232
+
233
+ function VideoAnnotationWhiteboard() {
234
+ const [videoStream, setVideoStream] = useState<MediaStream | undefined>();
235
+
236
+ // Get screen share or webcam stream
237
+ useEffect(() => {
238
+ async function getStream() {
239
+ try {
240
+ // Screen share example
241
+ const stream = await navigator.mediaDevices.getDisplayMedia({
242
+ video: { width: 1920, height: 1080 }
243
+ });
244
+ setVideoStream(stream);
245
+ } catch (err) {
246
+ console.error('Failed to get video stream:', err);
247
+ }
248
+ }
249
+ getStream();
250
+
251
+ return () => {
252
+ // Cleanup: stop all tracks when component unmounts
253
+ if (videoStream) {
254
+ videoStream.getTracks().forEach(track => track.stop());
255
+ }
256
+ };
257
+ }, []);
258
+
259
+ return (
260
+ <WhiteboardProvider webSocketUrl="ws://localhost:3001">
261
+ <Whiteboard
262
+ roomId="video-annotation-room"
263
+ userId="user-123"
264
+ isAdmin={true}
265
+ allowedUsers={['user-123']}
266
+ videoStream={videoStream} // Video renders as background layer
267
+ />
268
+ </WhiteboardProvider>
269
+ );
270
+ }
271
+ ```
272
+
273
+ **Features:**
274
+ - đŸŽĨ **Video as background**: Stream renders behind whiteboard canvas
275
+ - đŸ–Šī¸ **Draw over video**: All drawing tools work normally over the video
276
+ - 🔒 **Auto-transparent**: Background automatically set to transparent
277
+ - ⚡ **60fps performance**: HTML video layer, no canvas copying
278
+ - 📐 **Auto-scaling**: Video maintains aspect ratio with letterbox
279
+ - đŸŽ¯ **Pointer-events handled**: Video doesn't interfere with drawing
280
+
281
+ **Use cases:**
282
+ - Screen-share annotation for remote presentations
283
+ - Video call annotation
284
+ - Educational content markup
285
+ - Live streaming annotation
286
+
287
+ ## 📝 API Reference
288
+
289
+ ### WhiteboardProvider Props
290
+
291
+ | Prop | Type | Required | Description |
292
+ |------|------|----------|-------------|
293
+ | `webSocketUrl` | `string` | ✅ | WebSocket server URL for real-time collaboration |
294
+ | `children` | `ReactNode` | ✅ | Child components (typically contains `<Whiteboard>`) |
295
+
296
+ ### Whiteboard Props
297
+
298
+ | Prop | Type | Required | Default | Description |
299
+ |------|------|----------|---------|-------------|
300
+ | `roomId` | `string` | ✅ | - | Unique identifier for the collaboration room |
301
+ | `userId` | `string` | ✅ | - | Unique identifier for the current user |
302
+ | `isAdmin` | `boolean` | ❌ | `false` | Whether user has admin privileges (clear, lock/unlock) |
303
+ | `allowedUsers` | `string[]` | ❌ | `[]` | Array of user IDs who have drawing permissions |
304
+ | `transparentBackground` | `boolean` | ❌ | `false` | Forces transparent background and disables color picker |
305
+ | `videoStream` | `MediaStream` | ❌ | `undefined` | Live video stream for background layer (screen-share/video annotation) |
306
+
307
+ ### Hooks
308
+
309
+ #### useWhiteboardStream
310
+
311
+ Automatically captures the whiteboard canvas as a video stream (30 FPS). No manual start/stop controls needed.
312
+
313
+ ```tsx
314
+ import { useWhiteboardStream } from '@ngenux/ngage-whiteboarding';
315
+
316
+ function VideoStreamComponent() {
317
+ const { mediaStream } = useWhiteboardStream();
318
+
319
+ return (
320
+ <div>
321
+ {mediaStream && (
322
+ <video
323
+ srcObject={mediaStream}
324
+ autoPlay
325
+ muted
326
+ style={{ width: '300px', height: '200px' }}
327
+ />
328
+ )}
329
+ </div>
330
+ );
331
+ }
332
+ ```
333
+
334
+ **Note:** Stream capture starts automatically when the whiteboard canvas is available and can be controlled via the whiteboard context's `captureEnabled` state.
335
+
336
+ ## 🎨 Features in Detail
337
+
338
+ ### Drawing Tools
339
+ - **Pencil**: Freehand drawing
340
+ - **Shapes**: Rectangle, Ellipse, Arrow, Line
341
+ - **Eraser**: Remove parts of drawings
342
+ - **Select**: Move and transform shapes
343
+ - **Pan**: Navigate around the canvas
344
+
345
+ ### Collaborative Features
346
+ - **Real-time drawing**: See other users draw in real-time
347
+ - **User permissions**: Control who can draw
348
+ - **Admin controls**: Lock/unlock canvas, clear all drawings
349
+ - **Per-user undo/redo**: Each user maintains their own undo stack
350
+
351
+ ### Export Options
352
+ - **PNG**: Transparent or solid background
353
+ - **JPEG**: Solid background (white if transparent is selected)
354
+ - **PDF-format**: High-quality PNG optimized for printing/PDF conversion
355
+
356
+ ## 🔧 TypeScript Support
357
+
358
+ The package includes full TypeScript definitions:
359
+
360
+ ```tsx
361
+ import type {
362
+ WhiteboardProps,
363
+ WhiteboardProviderProps,
364
+ ToolType,
365
+ StrokeStyle
366
+ } from '@ngenux/ngage-whiteboarding';
367
+
368
+ const MyWhiteboard: React.FC<WhiteboardProps> = (props) => {
369
+ // Your implementation
370
+ };
371
+ ```
372
+
373
+ ## 🌐 Browser Support
374
+
375
+ - Chrome 80+
376
+ - Firefox 75+
377
+ - Safari 13+
378
+ - Edge 80+
379
+
380
+ **Note:** Requires a modern browser with WebSocket support and ES6+ features.
381
+
382
+ ## 📱 Responsive Design
383
+
384
+ The whiteboard automatically adapts to different screen sizes and supports touch interactions on mobile devices.
385
+
386
+ ## ⚡ Performance
387
+
388
+ - **Optimized rendering**: Uses Konva.js for high-performance 2D canvas rendering
389
+ - **Data compression**: Automatic compression of collaborative data
390
+ - **Throttled updates**: Optimized for 60fps real-time collaboration
391
+ - **Memory efficient**: Smart cleanup of stale collaborative data
392
+
393
+ ## 🐛 Troubleshooting
394
+
395
+ ### Common Issues
396
+
397
+ 1. **Styles not appearing / Components look unstyled**
398
+ - ✅ Ensure Tailwind CSS is installed and configured in your project
399
+ - ✅ Add the package path to your `tailwind.config.js` content array
400
+ - ✅ Import the package CSS: `import '@ngenux/ngage-whiteboarding/dist/styles.css'`
401
+ - ✅ Verify your PostCSS configuration is working
402
+
403
+ 2. **WebSocket connection fails**
404
+ - Ensure your WebSocket server is running and accessible
405
+ - Check CORS configuration on your server
406
+ - Verify the `webSocketUrl` is correct
407
+
408
+ 3. **Drawing doesn't sync between users**
409
+ - Verify all users are in the same `roomId`
410
+ - Check WebSocket server is properly broadcasting messages
411
+ - Ensure `userId` is unique for each user
412
+
413
+ 4. **TypeScript errors**
414
+ - Make sure you're importing types correctly
415
+ - Verify your TypeScript configuration includes the package types
416
+ - Ensure React types are properly installed
417
+
418
+ 5. **Build errors with Vite/bundler**
419
+ - Update to the latest version of your bundler
420
+ - Ensure PostCSS and Tailwind plugins are properly configured
421
+ - Check that the package is included in your bundler's dependency optimization
422
+
423
+ ## 📄 License
424
+
425
+ MIT
426
+
427
+
428
+ ## 📞 Support
429
+
430
+ If you encounter any issues or have questions, please file an issue on the [GitHub repository](https://github.com/ngenux-accelerators/ngage-whiteboarding/issues).
431
+
432
+ ---
433
+
434
+ ## 👨‍đŸ’ģ Author
435
+
436
+ **ng-sushil**
437
+ - GitHub: [@ng-sushil](https://github.com/ng-sushil)
438
+
343
439
  **Happy collaborating! 🎨✨**