import { get } from '../../util' ; export type Browser = 'Chrome' | 'Firefox' | 'not a browser' | 'unsupported browser' | 'WebKit browser without WebRTC support' | 'Safari' | 'Internet Explorer' | 'Edge' | 'non-Chromium Edge' | 'Opera' ; function detectBrowser ( ) { const navigator = window && window . navigator ; if ( typeof window === 'undefined' || ! window . navigator ) { return 'not a browser' ; } if ( get ( 'mozGetUserMedia' , navigator ) ) { return 'Firefox' ; } if ( get ( 'webkitGetUserMedia' , navigator ) ) { if ( window . hasOwnProperty ( 'webkitRTCPeerConnection' ) ) { if ( navigator . userAgent . match ( /Edg/ ) ) { return 'Edge' ; } if ( navigator . userAgent . match ( /Opera|OPR\// ) ) { return 'Opera' ; } return 'Chrome' ; } if ( navigator . userAgent . match ( /Version\/(\d+).(\d+)/ ) ) { return 'Safari' ; } return 'WebKit browser without WebRTC support' ; } if ( navigator . mediaDevices && navigator . userAgent . match ( /Edge\/(\d+).(\d+)$/ ) ) { return 'non-Chromium Edge' ; } if ( navigator . userAgent . indexOf ( 'MSIE ' ) > 0 || ! ! navigator . userAgent . match ( /Trident.*rv\:11\./ ) ) { return 'Internet Explorer' ; } if ( navigator . mediaDevices && navigator . userAgent . match ( /AppleWebKit\/(\d+)\./ ) ) { return 'Safari' ; } return 'unsupported browser' ; } export default function isSupportedBrowser ( ) { const supportedBrowsers = [ 'Chrome' , 'Firefox' , 'Safari' , 'Edge' , 'Opera' ] ; const browser = detectBrowser ( ) ; const supported = supportedBrowsers . indexOf ( browser ) > - 1 ; return { browser , supported } ; }