Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WebRTCSupportGate
function WebRtcSupportGate({
children,
forceUnsupported,
forceUnsupportedIos,
forceUnsupportedFacebook,
forceUnsupportedInApp,
}) {
const isWebRtcSupported =
!!global.RTCPeerConnection &&
!!global.navigator.mediaDevices &&
!!global.navigator.mediaDevices.getUserMedia &&
!forceUnsupported;
if (isIos() || forceUnsupportedIos || forceUnsupportedInApp) {
const safariVersion = extractSafariVersion();
// Safari version 604 brought WebRTC support, but was horribly broken on browser version <604.4
const isBadVersionOfSafari =
safariVersion.majorVersion === 604 && safariVersion.minorVersion < 4;
if ((isWebRtcSupported && isBadVersionOfSafari) || forceUnsupportedIos) {
return renderUnsupportediPhone();
}
// WebRTC was supported from Safari 604.4. However, in-app Safari was not updated at this time.
// If the Safari version should support WebRTC, but doesn't, we can assume it's an unsupported in-app browser
const isGoodVersionOfSafari =
(safariVersion.majorVersion === 604 && safariVersion.minorVersion > 3) ||
safariVersion.majorVersion > 604;
const isUnsupportedInAppBrowser =
!isWebRtcSupported && isGoodVersionOfSafari;
if (isUnsupportedInAppBrowser || forceUnsupportedInApp) {
return renderUnsupportedInAppBrowser();
}
}
const isUnsupportedFacebookBrowser =
global.navigator.userAgent.includes("FBAN") ||
global.navigator.userAgent.includes("FBAV") ||
forceUnsupportedFacebook;
if (isUnsupportedFacebookBrowser) {
return renderUnsupportedFacebookBrowser();
}
if (!isWebRtcSupported) {
return renderUnsupportedDesktop();
}
return children;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.