@ngenux/ngage-whiteboarding 1.0.0
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 +249 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +42595 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +42617 -0
- package/dist/index.js.map +1 -0
- package/dist/src/components/Shapes/Arrow.d.ts +11 -0
- package/dist/src/components/Shapes/Arrow.d.ts.map +1 -0
- package/dist/src/components/Shapes/Ellipse.d.ts +11 -0
- package/dist/src/components/Shapes/Ellipse.d.ts.map +1 -0
- package/dist/src/components/Shapes/ErasedShape.d.ts +11 -0
- package/dist/src/components/Shapes/ErasedShape.d.ts.map +1 -0
- package/dist/src/components/Shapes/FreehandDrawing.d.ts +11 -0
- package/dist/src/components/Shapes/FreehandDrawing.d.ts.map +1 -0
- package/dist/src/components/Shapes/Line.d.ts +11 -0
- package/dist/src/components/Shapes/Line.d.ts.map +1 -0
- package/dist/src/components/Shapes/Rectangle.d.ts +11 -0
- package/dist/src/components/Shapes/Rectangle.d.ts.map +1 -0
- package/dist/src/components/Whiteboard/Board.d.ts +14 -0
- package/dist/src/components/Whiteboard/Board.d.ts.map +1 -0
- package/dist/src/components/Whiteboard/Toolbar.d.ts +19 -0
- package/dist/src/components/Whiteboard/Toolbar.d.ts.map +1 -0
- package/dist/src/components/Whiteboard/index.d.ts +9 -0
- package/dist/src/components/Whiteboard/index.d.ts.map +1 -0
- package/dist/src/context/WhiteboardContext.d.ts +128 -0
- package/dist/src/context/WhiteboardContext.d.ts.map +1 -0
- package/dist/src/hooks/useCapture.d.ts +4 -0
- package/dist/src/hooks/useCapture.d.ts.map +1 -0
- package/dist/src/hooks/useCollaborativeWhiteboard.d.ts +27 -0
- package/dist/src/hooks/useCollaborativeWhiteboard.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +123 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/utils/compression.d.ts +14 -0
- package/dist/src/utils/compression.d.ts.map +1 -0
- package/dist/src/utils/socket-utility.d.ts +6 -0
- package/dist/src/utils/socket-utility.d.ts.map +1 -0
- package/package.json +97 -0
package/README.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
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
|
+
## đĻ Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @ngenux/ngage-whiteboarding
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## đ Quick Start
|
|
25
|
+
|
|
26
|
+
### Basic Setup
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import React from 'react';
|
|
30
|
+
import { WhiteboardProvider, Whiteboard } from '@ngenux/ngage-whiteboarding';
|
|
31
|
+
|
|
32
|
+
function App() {
|
|
33
|
+
return (
|
|
34
|
+
<WhiteboardProvider webSocketUrl="ws://localhost:3001">
|
|
35
|
+
<Whiteboard
|
|
36
|
+
roomId="room-123"
|
|
37
|
+
userId="user-456"
|
|
38
|
+
isAdmin={true}
|
|
39
|
+
allowedUsers={['user-456', 'user-789']}
|
|
40
|
+
/>
|
|
41
|
+
</WhiteboardProvider>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default App;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Advanced Usage with Multiple Rooms
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import React, { useState } from 'react';
|
|
52
|
+
import { WhiteboardProvider, Whiteboard } from '@ngenux/ngage-whiteboarding';
|
|
53
|
+
|
|
54
|
+
function CollaborativeApp() {
|
|
55
|
+
const [currentRoom, setCurrentRoom] = useState('room-1');
|
|
56
|
+
const [currentUser] = useState('user-' + Math.random().toString(36).substr(2, 9));
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<WhiteboardProvider webSocketUrl="wss://your-websocket-server.com">
|
|
60
|
+
<div>
|
|
61
|
+
<select value={currentRoom} onChange={(e) => setCurrentRoom(e.target.value)}>
|
|
62
|
+
<option value="room-1">Room 1</option>
|
|
63
|
+
<option value="room-2">Room 2</option>
|
|
64
|
+
<option value="room-3">Room 3</option>
|
|
65
|
+
</select>
|
|
66
|
+
|
|
67
|
+
<Whiteboard
|
|
68
|
+
roomId={currentRoom}
|
|
69
|
+
userId={currentUser}
|
|
70
|
+
isAdmin={currentUser === 'admin-user'}
|
|
71
|
+
allowedUsers={[currentUser, 'other-user-1', 'other-user-2']}
|
|
72
|
+
/>
|
|
73
|
+
</div>
|
|
74
|
+
</WhiteboardProvider>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## đ API Reference
|
|
80
|
+
|
|
81
|
+
### WhiteboardProvider Props
|
|
82
|
+
|
|
83
|
+
| Prop | Type | Required | Description |
|
|
84
|
+
|------|------|----------|-------------|
|
|
85
|
+
| `webSocketUrl` | `string` | â
| WebSocket server URL for real-time collaboration |
|
|
86
|
+
| `children` | `ReactNode` | â
| Child components (typically contains `<Whiteboard>`) |
|
|
87
|
+
|
|
88
|
+
### Whiteboard Props
|
|
89
|
+
|
|
90
|
+
| Prop | Type | Required | Default | Description |
|
|
91
|
+
|------|------|----------|---------|-------------|
|
|
92
|
+
| `roomId` | `string` | â
| - | Unique identifier for the collaboration room |
|
|
93
|
+
| `userId` | `string` | â
| - | Unique identifier for the current user |
|
|
94
|
+
| `isAdmin` | `boolean` | â | `false` | Whether user has admin privileges (clear, lock/unlock) |
|
|
95
|
+
| `allowedUsers` | `string[]` | â | `[]` | Array of user IDs who have drawing permissions |
|
|
96
|
+
|
|
97
|
+
### Hooks
|
|
98
|
+
|
|
99
|
+
#### useWhiteboardStream
|
|
100
|
+
|
|
101
|
+
Automatically captures the whiteboard canvas as a video stream (30 FPS). No manual start/stop controls needed.
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
import { useWhiteboardStream } from '@ngenux/ngage-whiteboarding';
|
|
105
|
+
|
|
106
|
+
function VideoStreamComponent() {
|
|
107
|
+
const { mediaStream } = useWhiteboardStream();
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<div>
|
|
111
|
+
{mediaStream && (
|
|
112
|
+
<video
|
|
113
|
+
srcObject={mediaStream}
|
|
114
|
+
autoPlay
|
|
115
|
+
muted
|
|
116
|
+
style={{ width: '300px', height: '200px' }}
|
|
117
|
+
/>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Note:** Stream capture starts automatically when the whiteboard canvas is available and can be controlled via the whiteboard context's `captureEnabled` state.
|
|
125
|
+
|
|
126
|
+
## đ¨ Features in Detail
|
|
127
|
+
|
|
128
|
+
### Drawing Tools
|
|
129
|
+
- **Pencil**: Freehand drawing
|
|
130
|
+
- **Shapes**: Rectangle, Ellipse, Arrow, Line
|
|
131
|
+
- **Eraser**: Remove parts of drawings
|
|
132
|
+
- **Select**: Move and transform shapes
|
|
133
|
+
- **Pan**: Navigate around the canvas
|
|
134
|
+
|
|
135
|
+
### Collaborative Features
|
|
136
|
+
- **Real-time drawing**: See other users draw in real-time
|
|
137
|
+
- **User permissions**: Control who can draw
|
|
138
|
+
- **Admin controls**: Lock/unlock canvas, clear all drawings
|
|
139
|
+
- **Per-user undo/redo**: Each user maintains their own undo stack
|
|
140
|
+
|
|
141
|
+
### Export Options
|
|
142
|
+
- **PNG**: Transparent or solid background
|
|
143
|
+
- **JPEG**: Solid background (white if transparent is selected)
|
|
144
|
+
- **PDF-format**: High-quality PNG optimized for printing/PDF conversion
|
|
145
|
+
|
|
146
|
+
## đ ī¸ Development
|
|
147
|
+
|
|
148
|
+
### Building the Package
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# Install dependencies
|
|
152
|
+
npm install
|
|
153
|
+
|
|
154
|
+
# Build the package
|
|
155
|
+
npm run build
|
|
156
|
+
|
|
157
|
+
# Watch mode for development
|
|
158
|
+
npm run dev
|
|
159
|
+
|
|
160
|
+
# Preview package contents
|
|
161
|
+
npm run pack-preview
|
|
162
|
+
|
|
163
|
+
# Clean build artifacts
|
|
164
|
+
npm run clean
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Package Structure
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
dist/
|
|
171
|
+
âââ index.js # CommonJS build
|
|
172
|
+
âââ index.esm.js # ES modules build
|
|
173
|
+
âââ index.d.ts # TypeScript definitions
|
|
174
|
+
âââ *.map # Source maps
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## đ§ TypeScript Support
|
|
178
|
+
|
|
179
|
+
The package includes full TypeScript definitions:
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
import type {
|
|
183
|
+
WhiteboardProps,
|
|
184
|
+
WhiteboardProviderProps,
|
|
185
|
+
ToolType,
|
|
186
|
+
StrokeStyle
|
|
187
|
+
} from '@ngenux/ngage-whiteboarding';
|
|
188
|
+
|
|
189
|
+
const MyWhiteboard: React.FC<WhiteboardProps> = (props) => {
|
|
190
|
+
// Your implementation
|
|
191
|
+
};
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## đ Browser Support
|
|
195
|
+
|
|
196
|
+
- Chrome 80+
|
|
197
|
+
- Firefox 75+
|
|
198
|
+
- Safari 13+
|
|
199
|
+
- Edge 80+
|
|
200
|
+
|
|
201
|
+
## đą Responsive Design
|
|
202
|
+
|
|
203
|
+
The whiteboard automatically adapts to different screen sizes and supports touch interactions on mobile devices.
|
|
204
|
+
|
|
205
|
+
## ⥠Performance
|
|
206
|
+
|
|
207
|
+
- **Optimized rendering**: Uses Konva.js for high-performance 2D canvas rendering
|
|
208
|
+
- **Data compression**: Automatic compression of collaborative data
|
|
209
|
+
- **Throttled updates**: Optimized for 60fps real-time collaboration
|
|
210
|
+
- **Memory efficient**: Smart cleanup of stale collaborative data
|
|
211
|
+
|
|
212
|
+
## đ Troubleshooting
|
|
213
|
+
|
|
214
|
+
### Common Issues
|
|
215
|
+
|
|
216
|
+
1. **WebSocket connection fails**
|
|
217
|
+
- Ensure your WebSocket server is running and accessible
|
|
218
|
+
- Check CORS configuration on your server
|
|
219
|
+
- Verify the `webSocketUrl` is correct
|
|
220
|
+
|
|
221
|
+
2. **Drawing doesn't sync between users**
|
|
222
|
+
- Verify all users are in the same `roomId`
|
|
223
|
+
- Check WebSocket server is properly broadcasting messages
|
|
224
|
+
- Ensure `userId` is unique for each user
|
|
225
|
+
|
|
226
|
+
3. **TypeScript errors**
|
|
227
|
+
- Make sure you're importing types correctly
|
|
228
|
+
- Verify your TypeScript configuration includes the package types
|
|
229
|
+
|
|
230
|
+
## đ License
|
|
231
|
+
|
|
232
|
+
MIT
|
|
233
|
+
|
|
234
|
+
## đ¤ Contributing
|
|
235
|
+
|
|
236
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
237
|
+
|
|
238
|
+
## đ Support
|
|
239
|
+
|
|
240
|
+
If you encounter any issues or have questions, please file an issue on the GitHub repository.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## đ¨âđģ Author
|
|
245
|
+
|
|
246
|
+
**ng-sushil**
|
|
247
|
+
- GitHub: [@ng-sushil](https://github.com/ng-sushil)
|
|
248
|
+
|
|
249
|
+
**Happy collaborating! đ¨â¨**
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Whiteboard } from './src/components/Whiteboard';
|
|
2
|
+
import { WhiteboardProvider } from './src/context/WhiteboardContext';
|
|
3
|
+
import { useCapture } from './src/hooks/useCapture';
|
|
4
|
+
export { Whiteboard, WhiteboardProvider, useCapture as useWhiteboardStream };
|
|
5
|
+
export type { WhiteboardProps } from './src/components/Whiteboard';
|
|
6
|
+
export type { ShapeProps, ToolType, StrokeStyle, WhiteboardState, DrawingAction, CompressedData } from './src/types';
|
|
7
|
+
export interface WhiteboardProviderProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
webSocketUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,UAAU,IAAI,mBAAmB,EAAE,CAAC;AAG7E,YAAY,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,YAAY,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,eAAe,EACf,aAAa,EACb,cAAc,EACf,MAAM,aAAa,CAAC;AAGrB,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|