@ngenux/ngage-whiteboarding 1.0.7 â 1.0.9
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 +344 -344
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +178 -102
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +185 -101
- package/dist/index.js.map +1 -1
- package/dist/src/components/Whiteboard/Board.d.ts.map +1 -1
- package/dist/src/components/Whiteboard/index.d.ts.map +1 -1
- package/dist/src/context/WhiteboardContext.d.ts.map +1 -1
- package/dist/src/utils/socket-utility.d.ts +6 -1
- package/dist/src/utils/socket-utility.d.ts.map +1 -1
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/socket-utility.esm.js +168 -0
- package/dist/utils/socket-utility.esm.js.map +1 -0
- package/dist/utils/socket-utility.js +177 -0
- package/dist/utils/socket-utility.js.map +1 -0
- package/dist/utils/src/components/Shapes/Arrow.d.ts +11 -0
- package/dist/utils/src/components/Shapes/Arrow.d.ts.map +1 -0
- package/dist/utils/src/components/Shapes/Ellipse.d.ts +11 -0
- package/dist/utils/src/components/Shapes/Ellipse.d.ts.map +1 -0
- package/dist/utils/src/components/Shapes/ErasedShape.d.ts +11 -0
- package/dist/utils/src/components/Shapes/ErasedShape.d.ts.map +1 -0
- package/dist/utils/src/components/Shapes/FreehandDrawing.d.ts +11 -0
- package/dist/utils/src/components/Shapes/FreehandDrawing.d.ts.map +1 -0
- package/dist/utils/src/components/Shapes/Line.d.ts +11 -0
- package/dist/utils/src/components/Shapes/Line.d.ts.map +1 -0
- package/dist/utils/src/components/Shapes/Rectangle.d.ts +11 -0
- package/dist/utils/src/components/Shapes/Rectangle.d.ts.map +1 -0
- package/dist/utils/src/components/Whiteboard/Board.d.ts +15 -0
- package/dist/utils/src/components/Whiteboard/Board.d.ts.map +1 -0
- package/dist/utils/src/components/Whiteboard/Toolbar.d.ts +21 -0
- package/dist/utils/src/components/Whiteboard/Toolbar.d.ts.map +1 -0
- package/dist/utils/src/components/Whiteboard/index.d.ts +11 -0
- package/dist/utils/src/components/Whiteboard/index.d.ts.map +1 -0
- package/dist/utils/src/context/WhiteboardContext.d.ts +128 -0
- package/dist/utils/src/context/WhiteboardContext.d.ts.map +1 -0
- package/dist/utils/src/hooks/useCapture.d.ts +4 -0
- package/dist/utils/src/hooks/useCapture.d.ts.map +1 -0
- package/dist/utils/src/hooks/useCollaborativeWhiteboard.d.ts +27 -0
- package/dist/utils/src/hooks/useCollaborativeWhiteboard.d.ts.map +1 -0
- package/dist/utils/src/lib/utils.d.ts +3 -0
- package/dist/utils/src/lib/utils.d.ts.map +1 -0
- package/dist/utils/src/types/index.d.ts +123 -0
- package/dist/utils/src/types/index.d.ts.map +1 -0
- package/dist/utils/src/utils/compression.d.ts +14 -0
- package/dist/utils/src/utils/compression.d.ts.map +1 -0
- package/dist/utils/src/utils/socket-utility.d.ts +11 -0
- package/dist/utils/src/utils/socket-utility.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/src/utils/video-coordinates.d.ts +0 -36
- package/dist/src/utils/video-coordinates.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,345 +1,345 @@
|
|
|
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
|
-
| `transparentBackground` | `boolean` | â | `false` | Forces transparent background and disables color picker |
|
|
211
|
-
| `videoStream` | `MediaStream` | â | `undefined` | Live video stream for background layer (screen-share/video annotation) |
|
|
212
|
-
|
|
213
|
-
### Hooks
|
|
214
|
-
|
|
215
|
-
#### useWhiteboardStream
|
|
216
|
-
|
|
217
|
-
Automatically captures the whiteboard canvas as a video stream (30 FPS). No manual start/stop controls needed.
|
|
218
|
-
|
|
219
|
-
```tsx
|
|
220
|
-
import { useWhiteboardStream } from '@ngenux/ngage-whiteboarding';
|
|
221
|
-
|
|
222
|
-
function VideoStreamComponent() {
|
|
223
|
-
const { mediaStream } = useWhiteboardStream();
|
|
224
|
-
|
|
225
|
-
return (
|
|
226
|
-
<div>
|
|
227
|
-
{mediaStream && (
|
|
228
|
-
<video
|
|
229
|
-
srcObject={mediaStream}
|
|
230
|
-
autoPlay
|
|
231
|
-
muted
|
|
232
|
-
style={{ width: '300px', height: '200px' }}
|
|
233
|
-
/>
|
|
234
|
-
)}
|
|
235
|
-
</div>
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
**Note:** Stream capture starts automatically when the whiteboard canvas is available and can be controlled via the whiteboard context's `captureEnabled` state.
|
|
241
|
-
|
|
242
|
-
## đ¨ Features in Detail
|
|
243
|
-
|
|
244
|
-
### Drawing Tools
|
|
245
|
-
- **Pencil**: Freehand drawing
|
|
246
|
-
- **Shapes**: Rectangle, Ellipse, Arrow, Line
|
|
247
|
-
- **Eraser**: Remove parts of drawings
|
|
248
|
-
- **Select**: Move and transform shapes
|
|
249
|
-
- **Pan**: Navigate around the canvas
|
|
250
|
-
|
|
251
|
-
### Collaborative Features
|
|
252
|
-
- **Real-time drawing**: See other users draw in real-time
|
|
253
|
-
- **User permissions**: Control who can draw
|
|
254
|
-
- **Admin controls**: Lock/unlock canvas, clear all drawings
|
|
255
|
-
- **Per-user undo/redo**: Each user maintains their own undo stack
|
|
256
|
-
|
|
257
|
-
### Export Options
|
|
258
|
-
- **PNG**: Transparent or solid background
|
|
259
|
-
- **JPEG**: Solid background (white if transparent is selected)
|
|
260
|
-
- **PDF-format**: High-quality PNG optimized for printing/PDF conversion
|
|
261
|
-
|
|
262
|
-
## đ§ TypeScript Support
|
|
263
|
-
|
|
264
|
-
The package includes full TypeScript definitions:
|
|
265
|
-
|
|
266
|
-
```tsx
|
|
267
|
-
import type {
|
|
268
|
-
WhiteboardProps,
|
|
269
|
-
WhiteboardProviderProps,
|
|
270
|
-
ToolType,
|
|
271
|
-
StrokeStyle
|
|
272
|
-
} from '@ngenux/ngage-whiteboarding';
|
|
273
|
-
|
|
274
|
-
const MyWhiteboard: React.FC<WhiteboardProps> = (props) => {
|
|
275
|
-
// Your implementation
|
|
276
|
-
};
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
## đ Browser Support
|
|
280
|
-
|
|
281
|
-
- Chrome 80+
|
|
282
|
-
- Firefox 75+
|
|
283
|
-
- Safari 13+
|
|
284
|
-
- Edge 80+
|
|
285
|
-
|
|
286
|
-
**Note:** Requires a modern browser with WebSocket support and ES6+ features.
|
|
287
|
-
|
|
288
|
-
## đą Responsive Design
|
|
289
|
-
|
|
290
|
-
The whiteboard automatically adapts to different screen sizes and supports touch interactions on mobile devices.
|
|
291
|
-
|
|
292
|
-
## ⥠Performance
|
|
293
|
-
|
|
294
|
-
- **Optimized rendering**: Uses Konva.js for high-performance 2D canvas rendering
|
|
295
|
-
- **Data compression**: Automatic compression of collaborative data
|
|
296
|
-
- **Throttled updates**: Optimized for 60fps real-time collaboration
|
|
297
|
-
- **Memory efficient**: Smart cleanup of stale collaborative data
|
|
298
|
-
|
|
299
|
-
## đ Troubleshooting
|
|
300
|
-
|
|
301
|
-
### Common Issues
|
|
302
|
-
|
|
303
|
-
1. **Styles not appearing / Components look unstyled**
|
|
304
|
-
- â
Ensure Tailwind CSS is installed and configured in your project
|
|
305
|
-
- â
Add the package path to your `tailwind.config.js` content array
|
|
306
|
-
- â
Import the package CSS: `import '@ngenux/ngage-whiteboarding/dist/styles.css'`
|
|
307
|
-
- â
Verify your PostCSS configuration is working
|
|
308
|
-
|
|
309
|
-
2. **WebSocket connection fails**
|
|
310
|
-
- Ensure your WebSocket server is running and accessible
|
|
311
|
-
- Check CORS configuration on your server
|
|
312
|
-
- Verify the `webSocketUrl` is correct
|
|
313
|
-
|
|
314
|
-
3. **Drawing doesn't sync between users**
|
|
315
|
-
- Verify all users are in the same `roomId`
|
|
316
|
-
- Check WebSocket server is properly broadcasting messages
|
|
317
|
-
- Ensure `userId` is unique for each user
|
|
318
|
-
|
|
319
|
-
4. **TypeScript errors**
|
|
320
|
-
- Make sure you're importing types correctly
|
|
321
|
-
- Verify your TypeScript configuration includes the package types
|
|
322
|
-
- Ensure React types are properly installed
|
|
323
|
-
|
|
324
|
-
5. **Build errors with Vite/bundler**
|
|
325
|
-
- Update to the latest version of your bundler
|
|
326
|
-
- Ensure PostCSS and Tailwind plugins are properly configured
|
|
327
|
-
- Check that the package is included in your bundler's dependency optimization
|
|
328
|
-
|
|
329
|
-
## đ License
|
|
330
|
-
|
|
331
|
-
MIT
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
## đ Support
|
|
335
|
-
|
|
336
|
-
If you encounter any issues or have questions, please file an issue on the [GitHub repository](https://github.com/ngenux-accelerators/ngage-whiteboarding/issues).
|
|
337
|
-
|
|
338
|
-
---
|
|
339
|
-
|
|
340
|
-
## đ¨âđģ Author
|
|
341
|
-
|
|
342
|
-
**ng-sushil**
|
|
343
|
-
- GitHub: [@ng-sushil](https://github.com/ng-sushil)
|
|
344
|
-
|
|
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
|
+
| `transparentBackground` | `boolean` | â | `false` | Forces transparent background and disables color picker |
|
|
211
|
+
| `videoStream` | `MediaStream` | â | `undefined` | Live video stream for background layer (screen-share/video annotation) |
|
|
212
|
+
|
|
213
|
+
### Hooks
|
|
214
|
+
|
|
215
|
+
#### useWhiteboardStream
|
|
216
|
+
|
|
217
|
+
Automatically captures the whiteboard canvas as a video stream (30 FPS). No manual start/stop controls needed.
|
|
218
|
+
|
|
219
|
+
```tsx
|
|
220
|
+
import { useWhiteboardStream } from '@ngenux/ngage-whiteboarding';
|
|
221
|
+
|
|
222
|
+
function VideoStreamComponent() {
|
|
223
|
+
const { mediaStream } = useWhiteboardStream();
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<div>
|
|
227
|
+
{mediaStream && (
|
|
228
|
+
<video
|
|
229
|
+
srcObject={mediaStream}
|
|
230
|
+
autoPlay
|
|
231
|
+
muted
|
|
232
|
+
style={{ width: '300px', height: '200px' }}
|
|
233
|
+
/>
|
|
234
|
+
)}
|
|
235
|
+
</div>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
**Note:** Stream capture starts automatically when the whiteboard canvas is available and can be controlled via the whiteboard context's `captureEnabled` state.
|
|
241
|
+
|
|
242
|
+
## đ¨ Features in Detail
|
|
243
|
+
|
|
244
|
+
### Drawing Tools
|
|
245
|
+
- **Pencil**: Freehand drawing
|
|
246
|
+
- **Shapes**: Rectangle, Ellipse, Arrow, Line
|
|
247
|
+
- **Eraser**: Remove parts of drawings
|
|
248
|
+
- **Select**: Move and transform shapes
|
|
249
|
+
- **Pan**: Navigate around the canvas
|
|
250
|
+
|
|
251
|
+
### Collaborative Features
|
|
252
|
+
- **Real-time drawing**: See other users draw in real-time
|
|
253
|
+
- **User permissions**: Control who can draw
|
|
254
|
+
- **Admin controls**: Lock/unlock canvas, clear all drawings
|
|
255
|
+
- **Per-user undo/redo**: Each user maintains their own undo stack
|
|
256
|
+
|
|
257
|
+
### Export Options
|
|
258
|
+
- **PNG**: Transparent or solid background
|
|
259
|
+
- **JPEG**: Solid background (white if transparent is selected)
|
|
260
|
+
- **PDF-format**: High-quality PNG optimized for printing/PDF conversion
|
|
261
|
+
|
|
262
|
+
## đ§ TypeScript Support
|
|
263
|
+
|
|
264
|
+
The package includes full TypeScript definitions:
|
|
265
|
+
|
|
266
|
+
```tsx
|
|
267
|
+
import type {
|
|
268
|
+
WhiteboardProps,
|
|
269
|
+
WhiteboardProviderProps,
|
|
270
|
+
ToolType,
|
|
271
|
+
StrokeStyle
|
|
272
|
+
} from '@ngenux/ngage-whiteboarding';
|
|
273
|
+
|
|
274
|
+
const MyWhiteboard: React.FC<WhiteboardProps> = (props) => {
|
|
275
|
+
// Your implementation
|
|
276
|
+
};
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## đ Browser Support
|
|
280
|
+
|
|
281
|
+
- Chrome 80+
|
|
282
|
+
- Firefox 75+
|
|
283
|
+
- Safari 13+
|
|
284
|
+
- Edge 80+
|
|
285
|
+
|
|
286
|
+
**Note:** Requires a modern browser with WebSocket support and ES6+ features.
|
|
287
|
+
|
|
288
|
+
## đą Responsive Design
|
|
289
|
+
|
|
290
|
+
The whiteboard automatically adapts to different screen sizes and supports touch interactions on mobile devices.
|
|
291
|
+
|
|
292
|
+
## ⥠Performance
|
|
293
|
+
|
|
294
|
+
- **Optimized rendering**: Uses Konva.js for high-performance 2D canvas rendering
|
|
295
|
+
- **Data compression**: Automatic compression of collaborative data
|
|
296
|
+
- **Throttled updates**: Optimized for 60fps real-time collaboration
|
|
297
|
+
- **Memory efficient**: Smart cleanup of stale collaborative data
|
|
298
|
+
|
|
299
|
+
## đ Troubleshooting
|
|
300
|
+
|
|
301
|
+
### Common Issues
|
|
302
|
+
|
|
303
|
+
1. **Styles not appearing / Components look unstyled**
|
|
304
|
+
- â
Ensure Tailwind CSS is installed and configured in your project
|
|
305
|
+
- â
Add the package path to your `tailwind.config.js` content array
|
|
306
|
+
- â
Import the package CSS: `import '@ngenux/ngage-whiteboarding/dist/styles.css'`
|
|
307
|
+
- â
Verify your PostCSS configuration is working
|
|
308
|
+
|
|
309
|
+
2. **WebSocket connection fails**
|
|
310
|
+
- Ensure your WebSocket server is running and accessible
|
|
311
|
+
- Check CORS configuration on your server
|
|
312
|
+
- Verify the `webSocketUrl` is correct
|
|
313
|
+
|
|
314
|
+
3. **Drawing doesn't sync between users**
|
|
315
|
+
- Verify all users are in the same `roomId`
|
|
316
|
+
- Check WebSocket server is properly broadcasting messages
|
|
317
|
+
- Ensure `userId` is unique for each user
|
|
318
|
+
|
|
319
|
+
4. **TypeScript errors**
|
|
320
|
+
- Make sure you're importing types correctly
|
|
321
|
+
- Verify your TypeScript configuration includes the package types
|
|
322
|
+
- Ensure React types are properly installed
|
|
323
|
+
|
|
324
|
+
5. **Build errors with Vite/bundler**
|
|
325
|
+
- Update to the latest version of your bundler
|
|
326
|
+
- Ensure PostCSS and Tailwind plugins are properly configured
|
|
327
|
+
- Check that the package is included in your bundler's dependency optimization
|
|
328
|
+
|
|
329
|
+
## đ License
|
|
330
|
+
|
|
331
|
+
MIT
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
## đ Support
|
|
335
|
+
|
|
336
|
+
If you encounter any issues or have questions, please file an issue on the [GitHub repository](https://github.com/ngenux-accelerators/ngage-whiteboarding/issues).
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## đ¨âđģ Author
|
|
341
|
+
|
|
342
|
+
**ng-sushil**
|
|
343
|
+
- GitHub: [@ng-sushil](https://github.com/ng-sushil)
|
|
344
|
+
|
|
345
345
|
**Happy collaborating! đ¨â¨**
|