Screen Sharing Quick Reference
import { useScreenShare } from '@/hooks/use-screen-share'
const { isScreenSharing, startScreenShare, stopScreenShare } = useScreenShare({
userId: 'user-id',
userName: 'User Name',
})
// Start
await startScreenShare({ quality: '1080p' })
// Stop
stopScreenShare()
| Component |
Purpose |
Path |
ScreenSharePanel |
Full screen share UI |
@/components/call/screen-share-panel |
AnnotationToolbar |
Drawing tools |
@/components/call/annotation-toolbar |
CallModal |
Integrated call UI |
@/components/call/call-modal |
| Hook |
Purpose |
useScreenShare |
Screen sharing lifecycle |
useScreenRecording |
Recording management |
| Class |
Purpose |
ScreenCaptureManager |
Capture screen/window/tab |
ScreenAnnotator |
Draw annotations |
CursorHighlighter |
Track cursors |
ScreenRecorder |
Record screen shares |
-
Pen - Freehand drawing
-
Arrow - Point to areas
-
Line - Straight lines
-
Rectangle - Draw boxes
-
Circle - Draw circles
-
Text - Add labels
-
Eraser - Remove annotations
| Quality |
Resolution |
FPS |
Bitrate |
| 720p |
1280x720 |
30 |
1.5 Mbps |
| 1080p |
1920x1080 |
30 |
2.5 Mbps |
| 4K |
3840x2160 |
60 |
8 Mbps |
await startRecording(stream, {
format: 'webm', // or 'mp4'
quality: 'high', // 'low', 'medium', 'high'
includeWebcam: true, // Add webcam overlay
webcamSize: 'small', // 'small', 'medium', 'large'
webcamPosition: 'bottom-right', // 4 corners
})
| Browser |
Support |
System Audio |
| Chrome 72+ |
โ
Full |
โ
Yes |
| Edge 79+ |
โ
Full |
โ
Yes |
| Firefox 66+ |
โ
Full |
โ No |
| Safari 13+ |
โ ๏ธ Partial |
โ No |
// Adaptive quality based on network
const quality = getOptimalQuality(networkSpeed)
// Lower frame rate for better performance
await startScreenShare({ frameRate: 15 })
// Update quality dynamically
await updateQuality(shareId, '720p')
// Always check permissions
if (!ScreenCaptureManager.isSupported()) {
// Show error
}
// Handle permission denial
try {
await startScreenShare()
} catch (error) {
if (error.name === 'NotAllowedError') {
// User denied
}
}
| Error |
Cause |
Solution |
NotAllowedError |
Permission denied |
Request permission again |
NotFoundError |
No screen selected |
User must select a screen |
NotSupportedError |
Browser doesn't support |
Use Chrome/Edge/Firefox |
const captureManager = createScreenCaptureManager({
onStreamStarted: (stream) => {
// Stream started
},
onStreamEnded: (streamId) => {
// Stream ended
},
onError: (error) => {
// Handle error
},
onTrackEnded: (kind) => {
// Track ended (video/audio)
},
})
await startScreenShare({
quality: '1080p',
captureSystemAudio: true,
captureCursor: true,
})
await startRecording(screenStream, {
includeWebcam: true,
webcamPosition: 'bottom-right',
})
annotator.setTool('pen')
annotator.setColor('#FF0000')
annotator.setStrokeWidth(4)
highlighter.updateCursor({
x: 100,
y: 200,
userId: 'user-id',
userName: 'User Name',
timestamp: Date.now(),
})
๐ Integration with Calls
<CallModal
isScreenSharing={isScreenSharing}
onToggleScreenShare={() => {
if (isScreenSharing) {
stopScreenShare()
} else {
startScreenShare()
}
}}
currentUserId={user.id}
currentUserName={user.name}
{...otherProps}
/>
# Check TypeScript
npx tsc --noEmit
# Run tests
pnpm test src/lib/webrtc
# Manual test
pnpm dev
# Navigate to /call-test