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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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 !(
  29. this.isFirefox()
  30. || this.isEdge()
  31. || this.isReactNative()
  32. || this.isSafariWithWebrtc()
  33. );
  34. }
  35. /**
  36. * Check whether or not the current browser support peer to peer connections
  37. * @return {boolean} <tt>true</tt> if p2p is supported or <tt>false</tt>
  38. * otherwise.
  39. */
  40. supportsP2P() {
  41. return !this.isEdge() && !this.isFirefox();
  42. }
  43. /**
  44. * Checks if the current browser is Chromium based, that is, it's either
  45. * Chrome / Chromium or uses it as its engine, but doesn't identify as
  46. * Chrome.
  47. *
  48. * This includes the following browsers:
  49. * - Chrome and Chromium
  50. * - Other browsers which use the Chrome engine, but are detected as Chrome,
  51. * such as Brave and Vivaldi
  52. * - Browsers which are NOT Chrome but use it as their engine, and have
  53. * custom detection code: Opera, Electron and NW.JS
  54. */
  55. isChromiumBased() {
  56. return this.isChrome()
  57. || this.isElectron()
  58. || this.isNWJS()
  59. || this.isOpera();
  60. }
  61. /**
  62. * Checks if current browser is a Safari and a version of Safari that
  63. * supports native webrtc.
  64. *
  65. * @returns {boolean}
  66. */
  67. isSafariWithWebrtc() {
  68. return this.isSafari()
  69. && !this.isVersionLessThan('11');
  70. }
  71. /**
  72. * Checks if current browser is a Safari and a version of Safari that
  73. * supports VP8.
  74. *
  75. * @returns {boolean}
  76. */
  77. isSafariWithVP8() {
  78. return this.isSafari()
  79. && !this.isVersionLessThan('12.1');
  80. }
  81. /**
  82. * Checks if the current browser is supported.
  83. *
  84. * @returns {boolean} true if the browser is supported, false otherwise.
  85. */
  86. isSupported() {
  87. return this.isChromiumBased()
  88. || this.isFirefox()
  89. || this.isReactNative()
  90. || this.isSafariWithWebrtc();
  91. }
  92. /**
  93. * Returns whether or not the current environment needs a user interaction
  94. * with the page before any unmute can occur.
  95. *
  96. * @returns {boolean}
  97. */
  98. isUserInteractionRequiredForUnmute() {
  99. return this.isFirefox() || this.isSafari();
  100. }
  101. /**
  102. * Checks if the current browser triggers 'onmute'/'onunmute' events when
  103. * user's connection is interrupted and the video stops playback.
  104. * @returns {*|boolean} 'true' if the event is supported or 'false'
  105. * otherwise.
  106. */
  107. supportsVideoMuteOnConnInterrupted() {
  108. return this.isChromiumBased() || this.isReactNative()
  109. || this.isSafariWithVP8();
  110. }
  111. /**
  112. * Checks if the current browser reports upload and download bandwidth
  113. * statistics.
  114. * @return {boolean}
  115. */
  116. supportsBandwidthStatistics() {
  117. // FIXME bandwidth stats are currently not implemented for FF on our
  118. // side, but not sure if not possible ?
  119. return !this.isFirefox() && !this.isEdge()
  120. && !this.isSafariWithWebrtc();
  121. }
  122. /**
  123. * Checks if the current browser supports WebRTC datachannels.
  124. * @return {boolean}
  125. */
  126. supportsDataChannels() {
  127. // NOTE: Edge does not yet implement DataChannel.
  128. return !this.isEdge();
  129. }
  130. /**
  131. * Checks if the current browser support the device change event.
  132. * @return {boolean}
  133. */
  134. supportsDeviceChangeEvent() {
  135. return navigator.mediaDevices
  136. && typeof navigator.mediaDevices.ondevicechange !== 'undefined'
  137. && typeof navigator.mediaDevices.addEventListener !== 'undefined';
  138. }
  139. /**
  140. * Checks if the current browser supports RTP statictics collecting.
  141. * Required by {@link RTPStatsCollector}.
  142. *
  143. * @returns {boolean} true if they are supported, false otherwise.
  144. */
  145. supportsRtpStatistics() {
  146. return this.isChromiumBased()
  147. || this.isEdge()
  148. || this.isFirefox()
  149. || this.isReactNative()
  150. || this.isSafariWithWebrtc();
  151. }
  152. /**
  153. * Checks if the current browser supports RTT statistics for srflx local
  154. * candidates through the legacy getStats() API.
  155. */
  156. supportsLocalCandidateRttStatistics() {
  157. return this.isChromiumBased() || this.isReactNative()
  158. || this.isSafariWithVP8();
  159. }
  160. /**
  161. * Checks if the current browser reports round trip time statistics for
  162. * the ICE candidate pair.
  163. * @return {boolean}
  164. */
  165. supportsRTTStatistics() {
  166. // Firefox does not seem to report RTT for ICE candidate pair:
  167. // eslint-disable-next-line max-len
  168. // https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
  169. // It does report mozRTT for RTP streams, but at the time of this
  170. // writing it's value does not make sense most of the time
  171. // (is reported as 1):
  172. // https://bugzilla.mozilla.org/show_bug.cgi?id=1241066
  173. // For Chrome and others we rely on 'googRtt'.
  174. return !this.isFirefox() && !this.isEdge();
  175. }
  176. /**
  177. * Checks whether the browser supports RTPSender.
  178. *
  179. * @returns {boolean}
  180. */
  181. supportsRtpSender() {
  182. return this.isFirefox() || this.isSafariWithVP8();
  183. }
  184. /**
  185. * Checks whether the browser supports RTX.
  186. *
  187. * @returns {boolean}
  188. */
  189. supportsRtx() {
  190. return !this.isFirefox() && !this.usesUnifiedPlan();
  191. }
  192. /**
  193. * Whether jitsi-meet supports simulcast on the current browser.
  194. * @returns {boolean}
  195. */
  196. supportsSimulcast() {
  197. return this.isChromiumBased() || this.isFirefox()
  198. || this.isSafariWithVP8() || this.isReactNative();
  199. }
  200. /**
  201. * Returns whether or not the current browser can support capturing video,
  202. * be it camera or desktop, and displaying received video.
  203. *
  204. * @returns {boolean}
  205. */
  206. supportsVideo() {
  207. // FIXME: Check if we can use supportsVideoOut and supportsVideoIn. I
  208. // leave the old implementation here in order not to brake something.
  209. // Older versions of Safari using webrtc/adapter do not support video
  210. // due in part to Safari only supporting H264 and the bridge sending VP8
  211. // Newer Safari support VP8 and other WebRTC features.
  212. return !this.isSafariWithWebrtc()
  213. || (this.isSafariWithVP8() && this.usesPlanB());
  214. }
  215. /**
  216. * Checks if the browser uses plan B.
  217. *
  218. * @returns {boolean}
  219. */
  220. usesPlanB() {
  221. return !this.usesUnifiedPlan();
  222. }
  223. /**
  224. * Checks if the browser uses unified plan.
  225. *
  226. * @returns {boolean}
  227. */
  228. usesUnifiedPlan() {
  229. if (this.isFirefox()) {
  230. return true;
  231. }
  232. if (this.isSafariWithVP8() && typeof window.RTCRtpTransceiver !== 'undefined') {
  233. // eslint-disable-next-line max-len
  234. // https://trac.webkit.org/changeset/236144/webkit/trunk/LayoutTests/webrtc/video-addLegacyTransceiver.html
  235. // eslint-disable-next-line no-undef
  236. return Object.keys(RTCRtpTransceiver.prototype)
  237. .indexOf('currentDirection') > -1;
  238. }
  239. return false;
  240. }
  241. /**
  242. * Returns whether or not the current browser should be using the new
  243. * getUserMedia flow, which utilizes the adapter shim. This method should
  244. * be temporary and used while migrating all browsers to use adapter and
  245. * the new getUserMedia.
  246. *
  247. * @returns {boolean}
  248. */
  249. usesNewGumFlow() {
  250. const REQUIRED_CHROME_VERSION = 61;
  251. if (this.isChrome()) {
  252. return !this.isVersionLessThan(REQUIRED_CHROME_VERSION);
  253. }
  254. if (this.isFirefox() || this.isSafariWithWebrtc()) {
  255. return true;
  256. }
  257. if (this.isChromiumBased()) {
  258. return this._getChromiumBasedVersion() >= REQUIRED_CHROME_VERSION;
  259. }
  260. return false;
  261. }
  262. /**
  263. * Checks if the browser uses webrtc-adapter. All browsers using the new
  264. * getUserMedia flow and Edge.
  265. *
  266. * @returns {boolean}
  267. */
  268. usesAdapter() {
  269. return this.usesNewGumFlow() || this.isEdge();
  270. }
  271. /**
  272. * Checks if the browser supports getDisplayMedia.
  273. * @returns {boolean} {@code true} if the browser supports getDisplayMedia.
  274. */
  275. supportsGetDisplayMedia() {
  276. return typeof navigator.getDisplayMedia !== 'undefined'
  277. || (typeof navigator.mediaDevices !== 'undefined'
  278. && typeof navigator.mediaDevices.getDisplayMedia
  279. !== 'undefined');
  280. }
  281. /**
  282. * Checks if the browser supports the "sdpSemantics" configuration option.
  283. * https://webrtc.org/web-apis/chrome/unified-plan/
  284. *
  285. * @returns {boolean}
  286. */
  287. supportsSdpSemantics() {
  288. return this.isChromiumBased() && this._getChromiumBasedVersion() >= 65;
  289. }
  290. /**
  291. * Returns the version of a Chromium based browser.
  292. *
  293. * @returns {Number}
  294. */
  295. _getChromiumBasedVersion() {
  296. if (this.isChromiumBased()) {
  297. // NW.JS doesn't expose the Chrome version in the UA string.
  298. if (this.isNWJS()) {
  299. // eslint-disable-next-line no-undef
  300. return Number.parseInt(process.versions.chromium, 10);
  301. }
  302. // Here we process all browsers which use the Chrome engine but
  303. // don't necessarily identify as Chrome. We cannot use the version
  304. // comparing functions because the Electron, Opera and NW.JS
  305. // versions are inconsequential here, as we need to know the actual
  306. // Chrome engine version.
  307. const ua = navigator.userAgent;
  308. if (ua.match(/Chrome/)) {
  309. const version
  310. = Number.parseInt(ua.match(/Chrome\/([\d.]+)/)[1], 10);
  311. return version;
  312. }
  313. }
  314. return -1;
  315. }
  316. }