Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

BrowserCapabilities.js 11KB

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