Skip to content

Commit fbe9285

Browse files
committed
Adds an error for no webrtc enabled
1 parent 3bd340d commit fbe9285

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

.claude/settings.local.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"allow": [
44
"Bash(pnpm build:*)",
55
"Bash(pnpm test:*)",
6-
"Bash(npm test:*)"
6+
"Bash(npm test:*)",
7+
"Bash(pnpm type:check:*)",
8+
"Bash(pnpm lint:check:*)"
79
],
810
"deny": []
911
}

src/components/WebRTCProvider.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import React, {
1111
import Loading from './Loading'
1212
import Peer from 'peerjs'
1313
import { ErrorMessage } from './ErrorMessage'
14+
import {
15+
isWebRTCSupported,
16+
getWebRTCErrorMessage,
17+
} from '../utils/webrtc-detection'
1418

1519
export type WebRTCPeerValue = {
1620
peer: Peer
@@ -70,6 +74,9 @@ export default function WebRTCPeerProvider({
7074
const [isStopped, setIsStopped] = useState(false)
7175
const [error, setError] = useState<Error | null>(null)
7276

77+
// Check WebRTC support early
78+
const webrtcSupported = isWebRTCSupported()
79+
7380
const stop = useCallback(() => {
7481
console.log('[WebRTCProvider] Stopping peer')
7582
globalPeer?.destroy()
@@ -79,8 +86,12 @@ export default function WebRTCPeerProvider({
7986
}, [])
8087

8188
useEffect(() => {
89+
if (!webrtcSupported) {
90+
setError(new Error(getWebRTCErrorMessage()))
91+
return
92+
}
8293
getOrCreateGlobalPeer().then(setPeerValue).catch(setError)
83-
}, [])
94+
}, [webrtcSupported])
8495

8596
const value = useMemo(() => ({ peer: peerValue!, stop }), [peerValue, stop])
8697

src/utils/webrtc-detection.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Detects if WebRTC is available and enabled in the current browser
3+
*/
4+
export function isWebRTCSupported(): boolean {
5+
// Check if RTCPeerConnection is available
6+
if (typeof RTCPeerConnection === 'undefined') {
7+
return false
8+
}
9+
10+
// Test if we can actually create an RTCPeerConnection
11+
// This catches cases where the API exists but is disabled (like Firefox's media.peerconnection.enabled = false)
12+
try {
13+
const testConnection = new RTCPeerConnection()
14+
testConnection.close()
15+
return true
16+
} catch (error) {
17+
console.warn('[WebRTC Detection] RTCPeerConnection creation failed:', error)
18+
return false
19+
}
20+
}
21+
22+
/**
23+
* Gets a user-friendly error message for WebRTC issues
24+
*/
25+
export function getWebRTCErrorMessage(): string {
26+
if (typeof RTCPeerConnection === 'undefined') {
27+
return 'Your browser does not support WebRTC. Please use a modern browser like Chrome, Firefox, Safari, or Edge.'
28+
}
29+
30+
// This is likely Firefox with media.peerconnection.enabled = false
31+
return 'WebRTC is disabled in your browser. In Firefox, please enable it by setting "media.peerconnection.enabled" to true in about:config.'
32+
}

0 commit comments

Comments
 (0)