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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. if (this.isSafari() && this._getSafariVersion() < MIN_REQUIRED_SAFARI_VERSION) {
  65. return false;
  66. }
  67. return (this.isChromiumBased() && this.isEngineVersionGreaterThan(MIN_REQUIRED_CHROME_VERSION - 1))
  68. || (this.isFirefox() && this.isVersionGreaterThan(MIN_REQUIRED_FIREFOX_VERSION - 1))
  69. || this.isReactNative()
  70. || this.isWebKitBased();
  71. }
  72. /**
  73. * Returns whether the browser is supported for Android
  74. * @returns {boolean} true if the browser is supported for Android devices
  75. */
  76. isSupportedAndroidBrowser() {
  77. return this.isChromiumBased() || this.isFirefox();
  78. }
  79. /**
  80. * Returns whether the browser is supported for iOS
  81. * @returns {boolean} true if the browser is supported for iOS devices
  82. */
  83. isSupportedIOSBrowser() {
  84. // After iPadOS 13 we have no way to know the Safari or iPadOS version, so YOLO.
  85. if (!this.isSafari() && this.isWebKitBased() && this.getOSVersion() === FROZEN_MACOS_VERSION) {
  86. return true;
  87. }
  88. return this._getSafariVersion() >= MIN_REQUIRED_IOS_VERSION
  89. || this._getIOSVersion() >= MIN_REQUIRED_IOS_VERSION;
  90. }
  91. /**
  92. * Returns whether or not the current environment needs a user interaction
  93. * with the page before any unmute can occur.
  94. *
  95. * @returns {boolean}
  96. */
  97. isUserInteractionRequiredForUnmute() {
  98. return this.isFirefox() && this.isVersionLessThan('68');
  99. }
  100. /**
  101. * Checks if the current browser triggers 'onmute'/'onunmute' events when
  102. * user's connection is interrupted and the video stops playback.
  103. * @returns {*|boolean} 'true' if the event is supported or 'false'
  104. * otherwise.
  105. */
  106. supportsVideoMuteOnConnInterrupted() {
  107. return this.isChromiumBased() || this.isReactNative();
  108. }
  109. /**
  110. * Checks if the current browser reports upload and download bandwidth
  111. * statistics.
  112. * @return {boolean}
  113. */
  114. supportsBandwidthStatistics() {
  115. // FIXME bandwidth stats are currently not implemented for FF on our
  116. // side, but not sure if not possible ?
  117. return !this.isFirefox() && !this.isWebKitBased();
  118. }
  119. /**
  120. * Checks if the current browser supports setting codec preferences on the transceiver.
  121. * @returns {boolean}
  122. */
  123. supportsCodecPreferences() {
  124. return Boolean(window.RTCRtpTransceiver
  125. && 'setCodecPreferences' in window.RTCRtpTransceiver.prototype
  126. && window.RTCRtpReceiver
  127. && typeof window.RTCRtpReceiver.getCapabilities !== 'undefined')
  128. // this is not working on Safari because of the following bug
  129. // https://bugs.webkit.org/show_bug.cgi?id=215567
  130. && !this.isWebKitBased();
  131. }
  132. /**
  133. * Checks if the browser supports the new codec selection API, i.e., checks if dictionary member
  134. * RTCRtpEncodingParameters.codec as defined in
  135. * https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-codec is supported by the browser. It
  136. * allows the application to change the current codec used by each RTCRtpSender without a renegotiation.
  137. *
  138. * @returns {boolean}
  139. */
  140. supportsCodecSelectionAPI() {
  141. return this.isChromiumBased() && this.isEngineVersionGreaterThan(125);
  142. }
  143. /**
  144. * Returns true if the browser supports Dependency Descriptor header extension.
  145. *
  146. * @returns {boolean}
  147. */
  148. supportsDDExtHeaders() {
  149. return !this.isFirefox();
  150. }
  151. /**
  152. * Checks if the current browser support the device change event.
  153. * @return {boolean}
  154. */
  155. supportsDeviceChangeEvent() {
  156. return navigator.mediaDevices
  157. && typeof navigator.mediaDevices.ondevicechange !== 'undefined'
  158. && typeof navigator.mediaDevices.addEventListener !== 'undefined';
  159. }
  160. /**
  161. * Checks if the current browser supports the Long Tasks API that lets us observe
  162. * performance measurement events and be notified of tasks that take longer than
  163. * 50ms to execute on the main thread.
  164. */
  165. supportsPerformanceObserver() {
  166. return typeof window.PerformanceObserver !== 'undefined'
  167. && PerformanceObserver.supportedEntryTypes.indexOf('longtask') > -1;
  168. }
  169. /**
  170. * Checks if the current browser supports audio level stats on the receivers.
  171. */
  172. supportsReceiverStats() {
  173. return typeof window.RTCRtpReceiver !== 'undefined'
  174. && Object.keys(RTCRtpReceiver.prototype).indexOf('getSynchronizationSources') > -1;
  175. }
  176. /**
  177. * Checks if the current browser reports round trip time statistics for
  178. * the ICE candidate pair.
  179. * @return {boolean}
  180. */
  181. supportsRTTStatistics() {
  182. // Firefox does not seem to report RTT for ICE candidate pair:
  183. // eslint-disable-next-line max-len
  184. // https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
  185. // It does report mozRTT for RTP streams, but at the time of this
  186. // writing it's value does not make sense most of the time
  187. // (is reported as 1):
  188. // https://bugzilla.mozilla.org/show_bug.cgi?id=1241066
  189. // For Chrome and others we rely on 'googRtt'.
  190. return !this.isFirefox();
  191. }
  192. /**
  193. * Returns true if the browser supports the new Scalability Mode API for VP9/AV1 simulcast and full SVC. H.264
  194. * simulcast will also be supported by the jvb for this version because the bridge is able to read the Dependency
  195. * Descriptor RTP header extension to extract layers information for H.264 as well.
  196. *
  197. * @returns {boolean}
  198. */
  199. supportsScalabilityModeAPI() {
  200. return this.isChromiumBased() && this.isEngineVersionGreaterThan(112);
  201. }
  202. /**
  203. * Returns true if the browser supports track based statistics for the local video track. Otherwise,
  204. * track resolution and framerate will be calculated based on the 'outbound-rtp' statistics.
  205. * @returns {boolean}
  206. */
  207. supportsTrackBasedStats() {
  208. return this.isChromiumBased() && this.isEngineVersionLessThan(112);
  209. }
  210. /**
  211. * Returns true if VP9 is supported by the client on the browser. VP9 is currently disabled on Firefox and Safari
  212. * because of issues with rendering. Please check https://bugzilla.mozilla.org/show_bug.cgi?id=1492500,
  213. * https://bugs.webkit.org/show_bug.cgi?id=231071 and https://bugs.webkit.org/show_bug.cgi?id=231074 for details.
  214. */
  215. supportsVP9() {
  216. return this.isChromiumBased() || this.isReactNative();
  217. }
  218. /**
  219. * Checks if the browser uses SDP munging for turning on simulcast.
  220. *
  221. * @returns {boolean}
  222. */
  223. usesSdpMungingForSimulcast() {
  224. return this.isChromiumBased() || this.isReactNative() || this.isWebKitBased();
  225. }
  226. /**
  227. * Checks if the browser uses RIDs/MIDs for siganling the simulcast streams
  228. * to the bridge instead of the ssrcs.
  229. */
  230. usesRidsForSimulcast() {
  231. return false;
  232. }
  233. /**
  234. * Checks if the browser supports getDisplayMedia.
  235. * @returns {boolean} {@code true} if the browser supports getDisplayMedia.
  236. */
  237. supportsGetDisplayMedia() {
  238. return typeof navigator.getDisplayMedia !== 'undefined'
  239. || (typeof navigator.mediaDevices !== 'undefined'
  240. && typeof navigator.mediaDevices.getDisplayMedia
  241. !== 'undefined');
  242. }
  243. /**
  244. * Checks if the browser supports WebRTC Encoded Transform, an alternative
  245. * to insertable streams.
  246. *
  247. * NOTE: At the time of this writing the only browser supporting this is
  248. * Safari / WebKit, behind a flag.
  249. *
  250. * @returns {boolean} {@code true} if the browser supports it.
  251. */
  252. supportsEncodedTransform() {
  253. return Boolean(window.RTCRtpScriptTransform);
  254. }
  255. /**
  256. * Checks if the browser supports insertable streams, needed for E2EE.
  257. * @returns {boolean} {@code true} if the browser supports insertable streams.
  258. */
  259. supportsInsertableStreams() {
  260. if (!(typeof window.RTCRtpSender !== 'undefined'
  261. && window.RTCRtpSender.prototype.createEncodedStreams)) {
  262. return false;
  263. }
  264. // Feature-detect transferable streams which we need to operate in a worker.
  265. // See https://groups.google.com/a/chromium.org/g/blink-dev/c/1LStSgBt6AM/m/hj0odB8pCAAJ
  266. const stream = new ReadableStream();
  267. try {
  268. window.postMessage(stream, '*', [ stream ]);
  269. return true;
  270. } catch {
  271. return false;
  272. }
  273. }
  274. /**
  275. * Whether the browser supports the RED format for audio.
  276. */
  277. supportsAudioRed() {
  278. return Boolean(window.RTCRtpSender
  279. && window.RTCRtpSender.getCapabilities
  280. && window.RTCRtpSender.getCapabilities('audio').codecs.some(codec => codec.mimeType === 'audio/red')
  281. && window.RTCRtpReceiver
  282. && window.RTCRtpReceiver.getCapabilities
  283. && window.RTCRtpReceiver.getCapabilities('audio').codecs.some(codec => codec.mimeType === 'audio/red'));
  284. }
  285. /**
  286. * Checks if the browser supports voice activity detection via the @type {VADAudioAnalyser} service.
  287. *
  288. * @returns {boolean}
  289. */
  290. supportsVADDetection() {
  291. return this.isChromiumBased();
  292. }
  293. /**
  294. * Check if the browser supports the RTP RTX feature (and it is usable).
  295. *
  296. * @returns {boolean}
  297. */
  298. supportsRTX() {
  299. // Disable RTX on Firefox up to 96 because we prefer simulcast over RTX
  300. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1738504
  301. return !(this.isFirefox() && this.isVersionLessThan('96'));
  302. }
  303. /**
  304. * Returns the version of a Safari browser.
  305. *
  306. * @returns {Number}
  307. */
  308. _getSafariVersion() {
  309. if (this.isSafari()) {
  310. return Number.parseInt(this.getVersion(), 10);
  311. }
  312. return -1;
  313. }
  314. /**
  315. * Returns the version of an ios browser.
  316. *
  317. * @returns {Number}
  318. */
  319. _getIOSVersion() {
  320. if (this.isWebKitBased()) {
  321. return Number.parseInt(this.getOSVersion(), 10);
  322. }
  323. return -1;
  324. }
  325. }