Created
November 27, 2017 19:35
-
-
Save dagingaa/934f9c2a6551d344a2f27099e58518e5 to your computer and use it in GitHub Desktop.
WebRTCSupportGate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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