Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

BrowserCapabilities.js 11KB

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