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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import { getLogger } from 'jitsi-meet-logger';
  2. import { BrowserDetection } from 'js-utils';
  3. const logger = getLogger(__filename);
  4. // TODO: Move this code to js-utils.
  5. // NOTE: Now we are extending BrowserDetection in order to preserve
  6. // RTCBrowserType interface but maybe it worth exporting BrowserCapabilities
  7. // and BrowserDetection as separate objects in future.
  8. /**
  9. * Implements browser capabilities for lib-jitsi-meet.
  10. */
  11. export default class BrowserCapabilities extends BrowserDetection {
  12. /**
  13. * Creates new BrowserCapabilities instance.
  14. */
  15. constructor() {
  16. super();
  17. logger.info(
  18. `This appears to be ${this.getName()}, ver: ${this.getVersion()}`);
  19. }
  20. /**
  21. * Tells whether or not the <tt>MediaStream/tt> is removed from
  22. * the <tt>PeerConnection</tt> and disposed on video mute (in order to turn
  23. * off the camera device).
  24. * @return {boolean} <tt>true</tt> if the current browser supports this
  25. * strategy or <tt>false</tt> otherwise.
  26. */
  27. doesVideoMuteByStreamRemove() {
  28. return this.isChromiumBased() || this.isSafari();
  29. }
  30. /**
  31. * Check whether or not the current browser support peer to peer connections
  32. * @return {boolean} <tt>true</tt> if p2p is supported or <tt>false</tt>
  33. * otherwise.
  34. */
  35. supportsP2P() {
  36. return !this.usesUnifiedPlan();
  37. }
  38. /**
  39. * Checks if the current browser is Chromium based, that is, it's either
  40. * Chrome / Chromium or uses it as its engine, but doesn't identify as
  41. * Chrome.
  42. *
  43. * This includes the following browsers:
  44. * - Chrome and Chromium
  45. * - Other browsers which use the Chrome engine, but are detected as Chrome,
  46. * such as Brave and Vivaldi
  47. * - Browsers which are NOT Chrome but use it as their engine, and have
  48. * custom detection code: Opera, Electron and NW.JS
  49. */
  50. isChromiumBased() {
  51. return this.isChrome()
  52. || this.isElectron()
  53. || this.isNWJS()
  54. || this.isOpera();
  55. }
  56. /**
  57. * Checks if the current browser is supported.
  58. *
  59. * @returns {boolean} true if the browser is supported, false otherwise.
  60. */
  61. isSupported() {
  62. return this.isChromiumBased()
  63. || this.isFirefox()
  64. || this.isReactNative()
  65. || (this.isSafari() && !this.isVersionLessThan('12.1'));
  66. }
  67. /**
  68. * Returns whether or not the current environment needs a user interaction
  69. * with the page before any unmute can occur.
  70. *
  71. * @returns {boolean}
  72. */
  73. isUserInteractionRequiredForUnmute() {
  74. return (this.isFirefox() && this.isVersionLessThan('68')) || this.isSafari();
  75. }
  76. /**
  77. * Checks if the current browser triggers 'onmute'/'onunmute' events when
  78. * user's connection is interrupted and the video stops playback.
  79. * @returns {*|boolean} 'true' if the event is supported or 'false'
  80. * otherwise.
  81. */
  82. supportsVideoMuteOnConnInterrupted() {
  83. return this.isChromiumBased() || this.isReactNative() || this.isSafari();
  84. }
  85. /**
  86. * Checks if the current browser reports upload and download bandwidth
  87. * statistics.
  88. * @return {boolean}
  89. */
  90. supportsBandwidthStatistics() {
  91. // FIXME bandwidth stats are currently not implemented for FF on our
  92. // side, but not sure if not possible ?
  93. return !this.isFirefox() && !this.isSafari();
  94. }
  95. /**
  96. * Checks if the current browser support the device change event.
  97. * @return {boolean}
  98. */
  99. supportsDeviceChangeEvent() {
  100. return navigator.mediaDevices
  101. && typeof navigator.mediaDevices.ondevicechange !== 'undefined'
  102. && typeof navigator.mediaDevices.addEventListener !== 'undefined';
  103. }
  104. /**
  105. * Checks if the current browser supports RTT statistics for srflx local
  106. * candidates through the legacy getStats() API.
  107. */
  108. supportsLocalCandidateRttStatistics() {
  109. return this.isChromiumBased() || this.isReactNative() || this.isSafari();
  110. }
  111. /**
  112. * Checks if the current browser reports round trip time statistics for
  113. * the ICE candidate pair.
  114. * @return {boolean}
  115. */
  116. supportsRTTStatistics() {
  117. // Firefox does not seem to report RTT for ICE candidate pair:
  118. // eslint-disable-next-line max-len
  119. // https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
  120. // It does report mozRTT for RTP streams, but at the time of this
  121. // writing it's value does not make sense most of the time
  122. // (is reported as 1):
  123. // https://bugzilla.mozilla.org/show_bug.cgi?id=1241066
  124. // For Chrome and others we rely on 'googRtt'.
  125. return !this.isFirefox();
  126. }
  127. /**
  128. * Checks whether the browser supports RTPSender.
  129. *
  130. * @returns {boolean}
  131. */
  132. supportsRtpSender() {
  133. return this.isFirefox() || this.isSafari();
  134. }
  135. /**
  136. * Checks whether the browser supports RTX.
  137. *
  138. * @returns {boolean}
  139. */
  140. supportsRtx() {
  141. return !this.isFirefox();
  142. }
  143. /**
  144. * Returns whether or not the current browser can support capturing video,
  145. * be it camera or desktop, and displaying received video.
  146. *
  147. * @returns {boolean}
  148. */
  149. supportsVideo() {
  150. return true;
  151. }
  152. /**
  153. * Checks if the browser uses plan B.
  154. *
  155. * @returns {boolean}
  156. */
  157. usesPlanB() {
  158. return !this.usesUnifiedPlan();
  159. }
  160. /**
  161. * Checks if the browser uses SDP munging for turning on simulcast.
  162. *
  163. * @returns {boolean}
  164. */
  165. usesSdpMungingForSimulcast() {
  166. return this.isChromiumBased() || this.isSafari();
  167. }
  168. /**
  169. * Checks if the browser uses unified plan.
  170. *
  171. * @returns {boolean}
  172. */
  173. usesUnifiedPlan() {
  174. if (this.isFirefox()) {
  175. return true;
  176. }
  177. if (this.isSafari() && typeof window.RTCRtpTransceiver !== 'undefined') {
  178. // eslint-disable-next-line max-len
  179. // https://trac.webkit.org/changeset/236144/webkit/trunk/LayoutTests/webrtc/video-addLegacyTransceiver.html
  180. // eslint-disable-next-line no-undef
  181. return Object.keys(RTCRtpTransceiver.prototype)
  182. .indexOf('currentDirection') > -1;
  183. }
  184. return false;
  185. }
  186. /**
  187. * Returns whether or not the current browser should be using the new
  188. * getUserMedia flow, which utilizes the adapter shim. This method should
  189. * be temporary and used while migrating all browsers to use adapter and
  190. * the new getUserMedia.
  191. *
  192. * @returns {boolean}
  193. */
  194. usesNewGumFlow() {
  195. const REQUIRED_CHROME_VERSION = 61;
  196. if (this.isChrome()) {
  197. return !this.isVersionLessThan(REQUIRED_CHROME_VERSION);
  198. }
  199. if (this.isFirefox() || this.isSafari()) {
  200. return true;
  201. }
  202. if (this.isChromiumBased()) {
  203. return this._getChromiumBasedVersion() >= REQUIRED_CHROME_VERSION;
  204. }
  205. return false;
  206. }
  207. /**
  208. * Checks if the browser uses webrtc-adapter. All browsers using the new
  209. * getUserMedia flow and Edge.
  210. *
  211. * @returns {boolean}
  212. */
  213. usesAdapter() {
  214. return this.usesNewGumFlow();
  215. }
  216. /**
  217. * Checks if the browser uses RIDs/MIDs for siganling the simulcast streams
  218. * to the bridge instead of the ssrcs.
  219. */
  220. usesRidsForSimulcast() {
  221. return false;
  222. }
  223. /**
  224. * Checks if the browser supports getDisplayMedia.
  225. * @returns {boolean} {@code true} if the browser supports getDisplayMedia.
  226. */
  227. supportsGetDisplayMedia() {
  228. return typeof navigator.getDisplayMedia !== 'undefined'
  229. || (typeof navigator.mediaDevices !== 'undefined'
  230. && typeof navigator.mediaDevices.getDisplayMedia
  231. !== 'undefined');
  232. }
  233. /**
  234. * Checks if the browser supports insertable streams, needed for E2EE.
  235. * @returns {boolean} {@code true} if the browser supports insertable streams.
  236. */
  237. supportsInsertableStreams() {
  238. return Boolean(typeof window.RTCRtpSender !== 'undefined'
  239. && window.RTCRtpSender.prototype.createEncodedVideoStreams);
  240. }
  241. /**
  242. * Checks if the browser supports the "sdpSemantics" configuration option.
  243. * https://webrtc.org/web-apis/chrome/unified-plan/
  244. *
  245. * @returns {boolean}
  246. */
  247. supportsSdpSemantics() {
  248. return this.isChromiumBased() && this._getChromiumBasedVersion() >= 65;
  249. }
  250. /**
  251. * Returns the version of a Chromium based browser.
  252. *
  253. * @returns {Number}
  254. */
  255. _getChromiumBasedVersion() {
  256. if (this.isChromiumBased()) {
  257. // NW.JS doesn't expose the Chrome version in the UA string.
  258. if (this.isNWJS()) {
  259. // eslint-disable-next-line no-undef
  260. return Number.parseInt(process.versions.chromium, 10);
  261. }
  262. // Here we process all browsers which use the Chrome engine but
  263. // don't necessarily identify as Chrome. We cannot use the version
  264. // comparing functions because the Electron, Opera and NW.JS
  265. // versions are inconsequential here, as we need to know the actual
  266. // Chrome engine version.
  267. const ua = navigator.userAgent;
  268. if (ua.match(/Chrome/)) {
  269. const version
  270. = Number.parseInt(ua.match(/Chrome\/([\d.]+)/)[1], 10);
  271. return version;
  272. }
  273. }
  274. return -1;
  275. }
  276. }