Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

BrowserCapabilities.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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. // Keep this disabled for FF because simulcast is disabled by default.
  225. // For versions 136+ if the media.webrtc.simulcast.vp9.enabled config is set to true it will work.
  226. // TODO: enable for FF with version 136+ once media.webrtc.simulcast.vp9.enabled is set to true by default.
  227. return !(this.isWebKitBased() || this.isFirefox());
  228. }
  229. /**
  230. * Returns true if K-SVC is supported for VP9.
  231. *
  232. * @returns {boolean}
  233. */
  234. supportsKSVCForVP9() {
  235. return !this.isFirefox();
  236. }
  237. /**
  238. * Checks if the browser uses SDP munging for turning on simulcast.
  239. *
  240. * @returns {boolean}
  241. */
  242. usesSdpMungingForSimulcast() {
  243. return this.isChromiumBased() || this.isReactNative() || this.isWebKitBased();
  244. }
  245. /**
  246. * Checks if the browser uses RIDs/MIDs for siganling the simulcast streams
  247. * to the bridge instead of the ssrcs.
  248. */
  249. usesRidsForSimulcast() {
  250. return false;
  251. }
  252. /**
  253. * Checks if the browser supports getDisplayMedia.
  254. * @returns {boolean} {@code true} if the browser supports getDisplayMedia.
  255. */
  256. supportsGetDisplayMedia() {
  257. return typeof navigator.getDisplayMedia !== 'undefined'
  258. || (typeof navigator.mediaDevices !== 'undefined'
  259. && typeof navigator.mediaDevices.getDisplayMedia
  260. !== 'undefined');
  261. }
  262. /**
  263. * Checks if the browser supports WebRTC Encoded Transform, an alternative
  264. * to insertable streams.
  265. *
  266. * NOTE: At the time of this writing the only browser supporting this is
  267. * Safari / WebKit, behind a flag.
  268. *
  269. * @returns {boolean} {@code true} if the browser supports it.
  270. */
  271. supportsEncodedTransform() {
  272. return Boolean(window.RTCRtpScriptTransform);
  273. }
  274. /**
  275. * Checks if the browser supports insertable streams, needed for E2EE.
  276. * @returns {boolean} {@code true} if the browser supports insertable streams.
  277. */
  278. supportsInsertableStreams() {
  279. if (!(typeof window.RTCRtpSender !== 'undefined'
  280. && window.RTCRtpSender.prototype.createEncodedStreams)) {
  281. return false;
  282. }
  283. // Feature-detect transferable streams which we need to operate in a worker.
  284. // See https://groups.google.com/a/chromium.org/g/blink-dev/c/1LStSgBt6AM/m/hj0odB8pCAAJ
  285. const stream = new ReadableStream();
  286. try {
  287. window.postMessage(stream, '*', [ stream ]);
  288. return true;
  289. } catch {
  290. return false;
  291. }
  292. }
  293. /**
  294. * Whether the browser supports the RED format for audio.
  295. */
  296. supportsAudioRed() {
  297. return Boolean(window.RTCRtpSender
  298. && window.RTCRtpSender.getCapabilities
  299. && window.RTCRtpSender.getCapabilities('audio').codecs.some(codec => codec.mimeType === 'audio/red')
  300. && window.RTCRtpReceiver
  301. && window.RTCRtpReceiver.getCapabilities
  302. && window.RTCRtpReceiver.getCapabilities('audio').codecs.some(codec => codec.mimeType === 'audio/red'));
  303. }
  304. /**
  305. * Checks if the browser supports voice activity detection via the @type {VADAudioAnalyser} service.
  306. *
  307. * @returns {boolean}
  308. */
  309. supportsVADDetection() {
  310. return this.isChromiumBased();
  311. }
  312. /**
  313. * Check if the browser supports the RTP RTX feature (and it is usable).
  314. *
  315. * @returns {boolean}
  316. */
  317. supportsRTX() {
  318. // Disable RTX on Firefox up to 96 because we prefer simulcast over RTX
  319. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1738504
  320. return !(this.isFirefox() && this.isVersionLessThan('96'));
  321. }
  322. /**
  323. * Returns the version of a Safari browser.
  324. *
  325. * @returns {Number}
  326. */
  327. _getSafariVersion() {
  328. if (this.isSafari()) {
  329. return Number.parseInt(this.getVersion(), 10);
  330. }
  331. return -1;
  332. }
  333. /**
  334. * Returns the version of an ios browser.
  335. *
  336. * @returns {Number}
  337. */
  338. _getIOSVersion() {
  339. if (this.isWebKitBased()) {
  340. return Number.parseInt(this.getOSVersion(), 10);
  341. }
  342. return -1;
  343. }
  344. }