Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

BrowserCapabilities.js 11KB

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