Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

BrowserCapabilities.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. import { BrowserDetection } from '@jitsi/js-utils';
  2. import { getLogger } from 'jitsi-meet-logger';
  3. const logger = getLogger(__filename);
  4. /* Minimum required Chrome / Chromium version. This applies also to derivatives. */
  5. const MIN_REQUIRED_CHROME_VERSION = 72;
  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. * Creates new BrowserCapabilities instance.
  16. */
  17. constructor() {
  18. super();
  19. logger.info(
  20. `This appears to be ${this.getName()}, ver: ${this.getVersion()}`);
  21. }
  22. /**
  23. * Tells whether or not the <tt>MediaStream/tt> is removed from
  24. * the <tt>PeerConnection</tt> and disposed on video mute (in order to turn
  25. * off the camera device).
  26. * @return {boolean} <tt>true</tt> if the current browser supports this
  27. * strategy or <tt>false</tt> otherwise.
  28. */
  29. doesVideoMuteByStreamRemove() {
  30. return this.isChromiumBased() || this.isWebKitBased();
  31. }
  32. /**
  33. * Check whether or not the current browser support peer to peer connections
  34. * @return {boolean} <tt>true</tt> if p2p is supported or <tt>false</tt>
  35. * otherwise.
  36. */
  37. supportsP2P() {
  38. return !this.usesUnifiedPlan();
  39. }
  40. /**
  41. * Checks if the current browser is Chromium based, that is, it's either
  42. * Chrome / Chromium or uses it as its engine, but doesn't identify as
  43. * Chrome.
  44. *
  45. * This includes the following browsers:
  46. * - Chrome and Chromium
  47. * - Other browsers which use the Chrome engine, but are detected as Chrome,
  48. * such as Brave and Vivaldi
  49. * - Browsers which are NOT Chrome but use it as their engine, and have
  50. * custom detection code: Opera, Electron and NW.JS
  51. */
  52. isChromiumBased() {
  53. return this.isChrome()
  54. || this.isElectron()
  55. || this.isNWJS()
  56. || this.isOpera();
  57. }
  58. /**
  59. * Checks if the current browser is WebKit based. It's either
  60. * Safari or uses WebKit as its engine.
  61. *
  62. * This includes Chrome and Firefox on iOS
  63. *
  64. * @returns {boolean}
  65. */
  66. isWebKitBased() {
  67. // https://trac.webkit.org/changeset/236144/webkit/trunk/LayoutTests/webrtc/video-addLegacyTransceiver.html
  68. return this._bowser.isEngine('webkit')
  69. && typeof navigator.mediaDevices !== 'undefined'
  70. && typeof navigator.mediaDevices.getUserMedia !== 'undefined'
  71. && typeof window.RTCRtpTransceiver !== 'undefined'
  72. // eslint-disable-next-line no-undef
  73. && Object.keys(RTCRtpTransceiver.prototype).indexOf('currentDirection') > -1;
  74. }
  75. /**
  76. * Checks whether current running context is a Trusted Web Application.
  77. *
  78. * @returns {boolean} Whether the current context is a TWA.
  79. */
  80. isTwa() {
  81. return 'matchMedia' in window && window.matchMedia('(display-mode:standalone)').matches;
  82. }
  83. /**
  84. * Checks if the current browser is supported.
  85. *
  86. * @returns {boolean} true if the browser is supported, false otherwise.
  87. */
  88. isSupported() {
  89. return (this.isChromiumBased() && this._getChromiumBasedVersion() >= MIN_REQUIRED_CHROME_VERSION)
  90. || this.isFirefox()
  91. || this.isReactNative()
  92. || this.isWebKitBased();
  93. }
  94. /**
  95. * Returns whether or not the current environment needs a user interaction
  96. * with the page before any unmute can occur.
  97. *
  98. * @returns {boolean}
  99. */
  100. isUserInteractionRequiredForUnmute() {
  101. return this.isFirefox() && this.isVersionLessThan('68');
  102. }
  103. /**
  104. * Checks if the current browser triggers 'onmute'/'onunmute' events when
  105. * user's connection is interrupted and the video stops playback.
  106. * @returns {*|boolean} 'true' if the event is supported or 'false'
  107. * otherwise.
  108. */
  109. supportsVideoMuteOnConnInterrupted() {
  110. return this.isChromiumBased() || this.isReactNative() || this.isWebKitBased();
  111. }
  112. /**
  113. * Checks if the current browser reports upload and download bandwidth
  114. * statistics.
  115. * @return {boolean}
  116. */
  117. supportsBandwidthStatistics() {
  118. // FIXME bandwidth stats are currently not implemented for FF on our
  119. // side, but not sure if not possible ?
  120. return !this.isFirefox() && !this.isWebKitBased();
  121. }
  122. /**
  123. * Checks if the current browser supports setting codec preferences on the transceiver.
  124. * @returns {boolean}
  125. */
  126. supportsCodecPreferences() {
  127. return this.usesUnifiedPlan()
  128. && typeof window.RTCRtpTransceiver !== 'undefined'
  129. && Object.keys(window.RTCRtpTransceiver.prototype).indexOf('setCodecPreferences') > -1
  130. && Object.keys(RTCRtpSender.prototype).indexOf('getCapabilities') > -1
  131. // this is not working on Safari because of the following bug
  132. // https://bugs.webkit.org/show_bug.cgi?id=215567
  133. && !this.isWebKitBased();
  134. }
  135. /**
  136. * Checks if the current browser support the device change event.
  137. * @return {boolean}
  138. */
  139. supportsDeviceChangeEvent() {
  140. return navigator.mediaDevices
  141. && typeof navigator.mediaDevices.ondevicechange !== 'undefined'
  142. && typeof navigator.mediaDevices.addEventListener !== 'undefined';
  143. }
  144. /**
  145. * Checks if the current browser supports RTT statistics for srflx local
  146. * candidates through the legacy getStats() API.
  147. */
  148. supportsLocalCandidateRttStatistics() {
  149. return this.isChromiumBased() || this.isReactNative() || this.isWebKitBased();
  150. }
  151. /**
  152. * Checks if the current browser supports the Long Tasks API that lets us observe
  153. * performance measurement events and be notified of tasks that take longer than
  154. * 50ms to execute on the main thread.
  155. */
  156. supportsPerformanceObserver() {
  157. return typeof window.PerformanceObserver !== 'undefined'
  158. && PerformanceObserver.supportedEntryTypes.indexOf('longtask') > -1;
  159. }
  160. /**
  161. * Checks if the current browser supports audio level stats on the receivers.
  162. */
  163. supportsReceiverStats() {
  164. return typeof window.RTCRtpReceiver !== 'undefined'
  165. && Object.keys(RTCRtpReceiver.prototype).indexOf('getSynchronizationSources') > -1
  166. // Disable this on Safari because it is reporting 0.000001 as the audio levels for all
  167. // remote audio tracks.
  168. && !this.isWebKitBased();
  169. }
  170. /**
  171. * Checks if the current browser reports round trip time statistics for
  172. * the ICE candidate pair.
  173. * @return {boolean}
  174. */
  175. supportsRTTStatistics() {
  176. // Firefox does not seem to report RTT for ICE candidate pair:
  177. // eslint-disable-next-line max-len
  178. // https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
  179. // It does report mozRTT for RTP streams, but at the time of this
  180. // writing it's value does not make sense most of the time
  181. // (is reported as 1):
  182. // https://bugzilla.mozilla.org/show_bug.cgi?id=1241066
  183. // For Chrome and others we rely on 'googRtt'.
  184. return !this.isFirefox();
  185. }
  186. /**
  187. * Checks if the browser uses plan B.
  188. *
  189. * @returns {boolean}
  190. */
  191. usesPlanB() {
  192. return !this.usesUnifiedPlan();
  193. }
  194. /**
  195. * Checks if the browser uses SDP munging for turning on simulcast.
  196. *
  197. * @returns {boolean}
  198. */
  199. usesSdpMungingForSimulcast() {
  200. return this.isChromiumBased() || this.isReactNative() || this.isWebKitBased();
  201. }
  202. /**
  203. * Checks if the browser uses unified plan.
  204. *
  205. * @returns {boolean}
  206. */
  207. usesUnifiedPlan() {
  208. if (this.isFirefox() || this.isWebKitBased()) {
  209. return true;
  210. }
  211. return false;
  212. }
  213. /**
  214. * Returns whether or not the current browser should be using the new
  215. * getUserMedia flow, which utilizes the adapter shim. This method should
  216. * be temporary and used while migrating all browsers to use adapter and
  217. * the new getUserMedia.
  218. *
  219. * @returns {boolean}
  220. */
  221. usesNewGumFlow() {
  222. if (this.isChromiumBased() || this.isFirefox() || this.isWebKitBased()) {
  223. return true;
  224. }
  225. return false;
  226. }
  227. /**
  228. * Checks if the browser uses webrtc-adapter. All browsers using the new
  229. * getUserMedia flow.
  230. *
  231. * @returns {boolean}
  232. */
  233. usesAdapter() {
  234. return this.usesNewGumFlow();
  235. }
  236. /**
  237. * Checks if the browser uses RIDs/MIDs for siganling the simulcast streams
  238. * to the bridge instead of the ssrcs.
  239. */
  240. usesRidsForSimulcast() {
  241. return false;
  242. }
  243. /**
  244. * Checks if the browser supports getDisplayMedia.
  245. * @returns {boolean} {@code true} if the browser supports getDisplayMedia.
  246. */
  247. supportsGetDisplayMedia() {
  248. return typeof navigator.getDisplayMedia !== 'undefined'
  249. || (typeof navigator.mediaDevices !== 'undefined'
  250. && typeof navigator.mediaDevices.getDisplayMedia
  251. !== 'undefined');
  252. }
  253. /**
  254. * Checks if the browser supports insertable streams, needed for E2EE.
  255. * @returns {boolean} {@code true} if the browser supports insertable streams.
  256. */
  257. supportsInsertableStreams() {
  258. if (!(typeof window.RTCRtpSender !== 'undefined'
  259. && (window.RTCRtpSender.prototype.createEncodedStreams
  260. || window.RTCRtpSender.prototype.createEncodedVideoStreams))) {
  261. return false;
  262. }
  263. // Feature-detect transferable streams which we need to operate in a worker.
  264. // See https://groups.google.com/a/chromium.org/g/blink-dev/c/1LStSgBt6AM/m/hj0odB8pCAAJ
  265. const stream = new ReadableStream();
  266. try {
  267. window.postMessage(stream, '*', [ stream ]);
  268. return true;
  269. } catch {
  270. return false;
  271. }
  272. }
  273. /**
  274. * Whether the browser supports the RED format for audio.
  275. */
  276. supportsAudioRed() {
  277. return Boolean(window.RTCRtpSender
  278. && window.RTCRtpSender.getCapabilities
  279. && window.RTCRtpSender.getCapabilities('audio').codecs.some(codec => codec.mimeType === 'audio/red')
  280. && window.RTCRtpReceiver
  281. && window.RTCRtpReceiver.getCapabilities
  282. && window.RTCRtpReceiver.getCapabilities('audio').codecs.some(codec => codec.mimeType === 'audio/red'));
  283. }
  284. /**
  285. * Checks if the browser supports the "sdpSemantics" configuration option.
  286. * https://webrtc.org/web-apis/chrome/unified-plan/
  287. *
  288. * @returns {boolean}
  289. */
  290. supportsSdpSemantics() {
  291. return this.isChromiumBased();
  292. }
  293. /**
  294. * Returns the version of a Chromium based browser.
  295. *
  296. * @returns {Number}
  297. */
  298. _getChromiumBasedVersion() {
  299. if (this.isChromiumBased()) {
  300. // NW.JS doesn't expose the Chrome version in the UA string.
  301. if (this.isNWJS()) {
  302. // eslint-disable-next-line no-undef
  303. return Number.parseInt(process.versions.chromium, 10);
  304. }
  305. // Here we process all browsers which use the Chrome engine but
  306. // don't necessarily identify as Chrome. We cannot use the version
  307. // comparing functions because the Electron, Opera and NW.JS
  308. // versions are inconsequential here, as we need to know the actual
  309. // Chrome engine version.
  310. const ua = navigator.userAgent;
  311. if (ua.match(/Chrome/)) {
  312. const version
  313. = Number.parseInt(ua.match(/Chrome\/([\d.]+)/)[1], 10);
  314. return version;
  315. }
  316. }
  317. return -1;
  318. }
  319. }