Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

BrowserCapabilities.js 12KB

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