You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BrowserCapabilities.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. import { BrowserDetection } from '@jitsi/js-utils';
  2. /* Minimum required Chrome / Chromium version. This applies also to derivatives. */
  3. const MIN_REQUIRED_CHROME_VERSION = 72;
  4. const MIN_REQUIRED_FIREFOX_VERSION = 91;
  5. const MIN_REQUIRED_SAFARI_VERSION = 14;
  6. const MIN_REQUIRED_IOS_VERSION = 14;
  7. // Starting with iPadOS 13 the actual Safari / iPadOS version is concealed from the UA string and
  8. // the system pretends to be macOS 10.15.7. Yeah, you read that right.
  9. const FROZEN_MACOS_VERSION = '10.15.7';
  10. // TODO: Move this code to js-utils.
  11. // NOTE: Now we are extending BrowserDetection in order to preserve
  12. // RTCBrowserType interface but maybe it worth exporting BrowserCapabilities
  13. // and BrowserDetection as separate objects in future.
  14. /**
  15. * Implements browser capabilities for lib-jitsi-meet.
  16. */
  17. export default class BrowserCapabilities extends BrowserDetection {
  18. /**
  19. * Tells whether or not the <tt>MediaStream/tt> is removed from the <tt>PeerConnection</tt> and disposed on video
  20. * mute (in order to turn off the camera device). This is needed on Firefox because of the following bug
  21. * https://bugzilla.mozilla.org/show_bug.cgi?id=1735951
  22. *
  23. * @return {boolean} <tt>true</tt> if the current browser supports this strategy or <tt>false</tt> otherwise.
  24. */
  25. doesVideoMuteByStreamRemove() {
  26. return this.isChromiumBased() || this.isWebKitBased() || this.isFirefox();
  27. }
  28. /**
  29. * Checks if the client is running on an Android browser.
  30. *
  31. * @returns {boolean}
  32. */
  33. isAndroidBrowser() {
  34. return !this.isReactNative() && this.getOS() === 'Android';
  35. }
  36. /**
  37. * Checks if the current platform is iOS.
  38. *
  39. * @returns {boolean}
  40. */
  41. isIosBrowser() {
  42. return !this.isReactNative() && this.getOS() === 'iOS';
  43. }
  44. /**
  45. * Checks if the client is running on a mobile device.
  46. */
  47. isMobileDevice() {
  48. return this.isAndroidBrowser() || this.isIosBrowser() || this.isReactNative();
  49. }
  50. /**
  51. * Checks whether current running context is a Trusted Web Application.
  52. *
  53. * @returns {boolean} Whether the current context is a TWA.
  54. */
  55. isTwa() {
  56. return 'matchMedia' in window && window.matchMedia('(display-mode:standalone)').matches;
  57. }
  58. /**
  59. * Checks if the current browser is supported.
  60. *
  61. * @returns {boolean} true if the browser is supported, false otherwise.
  62. */
  63. isSupported() {
  64. // First check for WebRTC APIs because some "security" extensions are dumb.
  65. if (typeof RTCPeerConnection === 'undefined'
  66. || !navigator?.mediaDevices?.enumerateDevices || !navigator?.mediaDevices?.getUserMedia) {
  67. return false;
  68. }
  69. if (this.isSafari() && this._getSafariVersion() < MIN_REQUIRED_SAFARI_VERSION) {
  70. return false;
  71. }
  72. return (this.isChromiumBased() && this.isEngineVersionGreaterThan(MIN_REQUIRED_CHROME_VERSION - 1))
  73. || (this.isFirefox() && this.isVersionGreaterThan(MIN_REQUIRED_FIREFOX_VERSION - 1))
  74. || this.isReactNative()
  75. || this.isWebKitBased();
  76. }
  77. /**
  78. * Returns whether the browser is supported for Android
  79. * @returns {boolean} true if the browser is supported for Android devices
  80. */
  81. isSupportedAndroidBrowser() {
  82. return this.isChromiumBased() || this.isFirefox();
  83. }
  84. /**
  85. * Returns whether the browser is supported for iOS
  86. * @returns {boolean} true if the browser is supported for iOS devices
  87. */
  88. isSupportedIOSBrowser() {
  89. // After iPadOS 13 we have no way to know the Safari or iPadOS version, so YOLO.
  90. if (!this.isSafari() && this.isWebKitBased() && this.getOSVersion() === FROZEN_MACOS_VERSION) {
  91. return true;
  92. }
  93. return this._getSafariVersion() >= MIN_REQUIRED_IOS_VERSION
  94. || this._getIOSVersion() >= MIN_REQUIRED_IOS_VERSION;
  95. }
  96. /**
  97. * Returns whether or not the current environment needs a user interaction
  98. * with the page before any unmute can occur.
  99. *
  100. * @returns {boolean}
  101. */
  102. isUserInteractionRequiredForUnmute() {
  103. return this.isFirefox() && this.isVersionLessThan('68');
  104. }
  105. /**
  106. * Checks if the current browser triggers 'onmute'/'onunmute' events when
  107. * user's connection is interrupted and the video stops playback.
  108. * @returns {*|boolean} 'true' if the event is supported or 'false'
  109. * otherwise.
  110. */
  111. supportsVideoMuteOnConnInterrupted() {
  112. return this.isChromiumBased() || this.isReactNative();
  113. }
  114. /**
  115. * Checks if the current browser reports upload and download bandwidth
  116. * statistics.
  117. * @return {boolean}
  118. */
  119. supportsBandwidthStatistics() {
  120. // FIXME bandwidth stats are currently not implemented for FF on our
  121. // side, but not sure if not possible ?
  122. return !this.isFirefox() && !this.isWebKitBased();
  123. }
  124. /**
  125. * Checks if the current browser supports setting codec preferences on the transceiver.
  126. * @returns {boolean}
  127. */
  128. supportsCodecPreferences() {
  129. return Boolean(window.RTCRtpTransceiver
  130. && 'setCodecPreferences' in window.RTCRtpTransceiver.prototype
  131. && window.RTCRtpReceiver
  132. && typeof window.RTCRtpReceiver.getCapabilities !== 'undefined')
  133. // this is not working on Safari because of the following bug
  134. // https://bugs.webkit.org/show_bug.cgi?id=215567
  135. && !this.isWebKitBased()
  136. // Calling this API on Firefox is causing freezes when the local endpoint is the answerer.
  137. // https://bugzilla.mozilla.org/show_bug.cgi?id=1917800
  138. && !this.isFirefox();
  139. }
  140. /**
  141. * Checks if the browser supports the new codec selection API, i.e., checks if dictionary member
  142. * RTCRtpEncodingParameters.codec as defined in
  143. * https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-codec is supported by the browser. It
  144. * allows the application to change the current codec used by each RTCRtpSender without a renegotiation.
  145. *
  146. * @returns {boolean}
  147. */
  148. supportsCodecSelectionAPI() {
  149. return this.isChromiumBased() && this.isEngineVersionGreaterThan(125);
  150. }
  151. /**
  152. * Returns true if the browser supports Dependency Descriptor header extension.
  153. *
  154. * @returns {boolean}
  155. */
  156. supportsDDExtHeaders() {
  157. return !(this.isFirefox() && this.isVersionLessThan('136'));
  158. }
  159. /**
  160. * Checks if the current browser support the device change event.
  161. * @return {boolean}
  162. */
  163. supportsDeviceChangeEvent() {
  164. return navigator.mediaDevices
  165. && typeof navigator.mediaDevices.ondevicechange !== 'undefined'
  166. && typeof navigator.mediaDevices.addEventListener !== 'undefined';
  167. }
  168. /**
  169. * Checks if the current browser supports the Long Tasks API that lets us observe
  170. * performance measurement events and be notified of tasks that take longer than
  171. * 50ms to execute on the main thread.
  172. */
  173. supportsPerformanceObserver() {
  174. return typeof window.PerformanceObserver !== 'undefined'
  175. && PerformanceObserver.supportedEntryTypes.indexOf('longtask') > -1;
  176. }
  177. /**
  178. * Checks if the current browser supports audio level stats on the receivers.
  179. */
  180. supportsReceiverStats() {
  181. return typeof window.RTCRtpReceiver !== 'undefined'
  182. && Object.keys(RTCRtpReceiver.prototype).indexOf('getSynchronizationSources') > -1;
  183. }
  184. /**
  185. * Checks if the current browser reports round trip time statistics for
  186. * the ICE candidate pair.
  187. * @return {boolean}
  188. */
  189. supportsRTTStatistics() {
  190. // Firefox does not seem to report RTT for ICE candidate pair:
  191. // eslint-disable-next-line max-len
  192. // https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
  193. // It does report mozRTT for RTP streams, but at the time of this
  194. // writing it's value does not make sense most of the time
  195. // (is reported as 1):
  196. // https://bugzilla.mozilla.org/show_bug.cgi?id=1241066
  197. // For Chrome and others we rely on 'googRtt'.
  198. return !this.isFirefox();
  199. }
  200. /**
  201. * Returns true if the browser supports the new Scalability Mode API for VP9/AV1 simulcast and full SVC. H.264
  202. * simulcast will also be supported by the jvb for this version because the bridge is able to read the Dependency
  203. * Descriptor RTP header extension to extract layers information for H.264 as well.
  204. *
  205. * @returns {boolean}
  206. */
  207. supportsScalabilityModeAPI() {
  208. return this.isChromiumBased() && this.isEngineVersionGreaterThan(112);
  209. }
  210. /**
  211. * Returns true if the browser supports track based statistics for the local video track. Otherwise,
  212. * track resolution and framerate will be calculated based on the 'outbound-rtp' statistics.
  213. * @returns {boolean}
  214. */
  215. supportsTrackBasedStats() {
  216. return this.isChromiumBased() && this.isEngineVersionLessThan(112);
  217. }
  218. /**
  219. * Returns true if VP9 is supported by the client on the browser. VP9 is currently disabled on Safari
  220. * and older versions of Firefox because of issues. Please check https://bugs.webkit.org/show_bug.cgi?id=231074 for
  221. * details.
  222. */
  223. supportsVP9() {
  224. return !(this.isWebKitBased() || (this.isFirefox() && this.isVersionLessThan('136')));
  225. }
  226. /**
  227. * Checks if the browser uses SDP munging for turning on simulcast.
  228. *
  229. * @returns {boolean}
  230. */
  231. usesSdpMungingForSimulcast() {
  232. return this.isChromiumBased() || this.isReactNative() || this.isWebKitBased();
  233. }
  234. /**
  235. * Checks if the browser uses RIDs/MIDs for siganling the simulcast streams
  236. * to the bridge instead of the ssrcs.
  237. */
  238. usesRidsForSimulcast() {
  239. return false;
  240. }
  241. /**
  242. * Checks if the browser supports getDisplayMedia.
  243. * @returns {boolean} {@code true} if the browser supports getDisplayMedia.
  244. */
  245. supportsGetDisplayMedia() {
  246. return typeof navigator.getDisplayMedia !== 'undefined'
  247. || (typeof navigator.mediaDevices !== 'undefined'
  248. && typeof navigator.mediaDevices.getDisplayMedia
  249. !== 'undefined');
  250. }
  251. /**
  252. * Checks if the browser supports WebRTC Encoded Transform, an alternative
  253. * to insertable streams.
  254. *
  255. * NOTE: At the time of this writing the only browser supporting this is
  256. * Safari / WebKit, behind a flag.
  257. *
  258. * @returns {boolean} {@code true} if the browser supports it.
  259. */
  260. supportsEncodedTransform() {
  261. return Boolean(window.RTCRtpScriptTransform);
  262. }
  263. /**
  264. * Checks if the browser supports insertable streams, needed for E2EE.
  265. * @returns {boolean} {@code true} if the browser supports insertable streams.
  266. */
  267. supportsInsertableStreams() {
  268. if (!(typeof window.RTCRtpSender !== 'undefined'
  269. && window.RTCRtpSender.prototype.createEncodedStreams)) {
  270. return false;
  271. }
  272. // Feature-detect transferable streams which we need to operate in a worker.
  273. // See https://groups.google.com/a/chromium.org/g/blink-dev/c/1LStSgBt6AM/m/hj0odB8pCAAJ
  274. const stream = new ReadableStream();
  275. try {
  276. window.postMessage(stream, '*', [ stream ]);
  277. return true;
  278. } catch {
  279. return false;
  280. }
  281. }
  282. /**
  283. * Whether the browser supports the RED format for audio.
  284. */
  285. supportsAudioRed() {
  286. return Boolean(window.RTCRtpSender
  287. && window.RTCRtpSender.getCapabilities
  288. && window.RTCRtpSender.getCapabilities('audio').codecs.some(codec => codec.mimeType === 'audio/red')
  289. && window.RTCRtpReceiver
  290. && window.RTCRtpReceiver.getCapabilities
  291. && window.RTCRtpReceiver.getCapabilities('audio').codecs.some(codec => codec.mimeType === 'audio/red'));
  292. }
  293. /**
  294. * Checks if the browser supports voice activity detection via the @type {VADAudioAnalyser} service.
  295. *
  296. * @returns {boolean}
  297. */
  298. supportsVADDetection() {
  299. return this.isChromiumBased();
  300. }
  301. /**
  302. * Check if the browser supports the RTP RTX feature (and it is usable).
  303. *
  304. * @returns {boolean}
  305. */
  306. supportsRTX() {
  307. // Disable RTX on Firefox up to 96 because we prefer simulcast over RTX
  308. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1738504
  309. return !(this.isFirefox() && this.isVersionLessThan('96'));
  310. }
  311. /**
  312. * Returns the version of a Safari browser.
  313. *
  314. * @returns {Number}
  315. */
  316. _getSafariVersion() {
  317. if (this.isSafari()) {
  318. return Number.parseInt(this.getVersion(), 10);
  319. }
  320. return -1;
  321. }
  322. /**
  323. * Returns the version of an ios browser.
  324. *
  325. * @returns {Number}
  326. */
  327. _getIOSVersion() {
  328. if (this.isWebKitBased()) {
  329. return Number.parseInt(this.getOSVersion(), 10);
  330. }
  331. return -1;
  332. }
  333. }