Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

BrowserCapabilities.ts 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. import BrowserDetection from '@jitsi/js-utils/browser-detection/BrowserDetection';
  2. /* Minimum required Chrome / Chromium version. This applies also to derivatives. */
  3. const MIN_REQUIRED_CHROME_VERSION = 72;
  4. const MIN_REQUIRED_FIREFOX_VERSION = 91;
  5. const MIN_REQUIRED_SAFARI_VERSION = 14;
  6. const MIN_REQUIRED_IOS_VERSION = 14;
  7. // Starting with iPadOS 13 the actual Safari / iPadOS version is concealed from the UA string and
  8. // the system pretends to be macOS 10.15.7. Yeah, you read that right.
  9. const FROZEN_MACOS_VERSION = '10.15.7';
  10. // TODO: Move this code to js-utils.
  11. // NOTE: Now we are extending BrowserDetection in order to preserve
  12. // RTCBrowserType interface but maybe it worth exporting BrowserCapabilities
  13. // and BrowserDetection as separate objects in future.
  14. /**
  15. * Implements browser capabilities for lib-jitsi-meet.
  16. */
  17. export default class BrowserCapabilities extends BrowserDetection {
  18. /**
  19. * Returns the version of an ios browser.
  20. *
  21. * @returns {Number}
  22. */
  23. _getIOSVersion(): number {
  24. if (this.isWebKitBased()) {
  25. return Number.parseInt(this.getOSVersion(), 10);
  26. }
  27. return -1;
  28. }
  29. /**
  30. * Returns the version of a Safari browser.
  31. *
  32. * @returns {Number}
  33. */
  34. _getSafariVersion(): number {
  35. if (this.isSafari()) {
  36. return Number.parseInt(this.getVersion(), 10);
  37. }
  38. return -1;
  39. }
  40. /**
  41. * Tells whether or not the <tt>MediaStream/tt> is removed from the <tt>PeerConnection</tt> and disposed on video
  42. * mute (in order to turn off the camera device). This is needed on Firefox because of the following bug
  43. * https://bugzilla.mozilla.org/show_bug.cgi?id=1735951
  44. *
  45. * @return {boolean} <tt>true</tt> if the current browser supports this strategy or <tt>false</tt> otherwise.
  46. */
  47. doesVideoMuteByStreamRemove(): boolean {
  48. return this.isChromiumBased() || this.isWebKitBased() || this.isFirefox();
  49. }
  50. /**
  51. * Checks if the client is running on an Android browser.
  52. *
  53. * @returns {boolean}
  54. */
  55. isAndroidBrowser(): boolean {
  56. return !this.isReactNative() && this.getOS() === 'Android';
  57. }
  58. /**
  59. * Checks if the current platform is iOS.
  60. *
  61. * @returns {boolean}
  62. */
  63. isIosBrowser(): boolean {
  64. return !this.isReactNative() && this.getOS() === 'iOS';
  65. }
  66. /**
  67. * Checks if the client is running on a mobile device.
  68. *
  69. * @returns {boolean}
  70. */
  71. isMobileDevice(): boolean {
  72. return this.isAndroidBrowser() || this.isIosBrowser() || this.isReactNative();
  73. }
  74. /**
  75. * Checks whether current running context is a Trusted Web Application.
  76. *
  77. * @returns {boolean} Whether the current context is a TWA.
  78. */
  79. isTwa(): boolean {
  80. return 'matchMedia' in window && window.matchMedia('(display-mode:standalone)').matches;
  81. }
  82. /**
  83. * Checks if the current browser is supported.
  84. *
  85. * @returns {boolean} true if the browser is supported, false otherwise.
  86. */
  87. isSupported(): boolean {
  88. // First check for WebRTC APIs because some "security" extensions are dumb.
  89. if (typeof RTCPeerConnection === 'undefined'
  90. || !navigator?.mediaDevices?.enumerateDevices || !navigator?.mediaDevices?.getUserMedia) {
  91. return false;
  92. }
  93. if (this.isSafari() && this._getSafariVersion() < MIN_REQUIRED_SAFARI_VERSION) {
  94. return false;
  95. }
  96. return (this.isChromiumBased() && this.isEngineVersionGreaterThan(MIN_REQUIRED_CHROME_VERSION - 1))
  97. || (this.isFirefox() && this.isVersionGreaterThan(MIN_REQUIRED_FIREFOX_VERSION - 1))
  98. || this.isReactNative()
  99. || this.isWebKitBased();
  100. }
  101. /**
  102. * Returns whether the browser is supported for Android.
  103. *
  104. * @returns {boolean} true if the browser is supported for Android devices.
  105. */
  106. isSupportedAndroidBrowser(): boolean {
  107. return this.isChromiumBased() || this.isFirefox();
  108. }
  109. /**
  110. * Returns whether the browser is supported for iOS.
  111. *
  112. * @returns {boolean} true if the browser is supported for iOS devices.
  113. */
  114. isSupportedIOSBrowser(): boolean {
  115. // After iPadOS 13 we have no way to know the Safari or iPadOS version, so YOLO.
  116. if (!this.isSafari() && this.isWebKitBased() && this.getOSVersion() === FROZEN_MACOS_VERSION) {
  117. return true;
  118. }
  119. return this._getSafariVersion() >= MIN_REQUIRED_IOS_VERSION
  120. || this._getIOSVersion() >= MIN_REQUIRED_IOS_VERSION;
  121. }
  122. /**
  123. * Returns whether or not the current environment needs a user interaction
  124. * with the page before any unmute can occur.
  125. *
  126. * @returns {boolean}
  127. */
  128. isUserInteractionRequiredForUnmute(): boolean {
  129. return this.isFirefox() && this.isVersionLessThan(68);
  130. }
  131. /**
  132. * Checks if the current browser triggers 'onmute'/'onunmute' events when
  133. * user's connection is interrupted and the video stops playback.
  134. *
  135. * @returns {*|boolean} 'true' if the event is supported or 'false' otherwise.
  136. */
  137. supportsVideoMuteOnConnInterrupted(): any | boolean {
  138. return this.isChromiumBased() || this.isReactNative();
  139. }
  140. /**
  141. * Checks if the current browser reports upload and download bandwidth statistics.
  142. *
  143. * @return {boolean}
  144. */
  145. supportsBandwidthStatistics(): boolean {
  146. // FIXME bandwidth stats are currently not implemented for FF on our
  147. // side, but not sure if not possible ?
  148. return !this.isFirefox() && !this.isWebKitBased();
  149. }
  150. /**
  151. * Checks if the current browser supports setting codec preferences on the transceiver.
  152. *
  153. * @returns {boolean}
  154. */
  155. supportsCodecPreferences(): boolean {
  156. return Boolean('setCodecPreferences' in window.RTCRtpTransceiver?.prototype
  157. && typeof window.RTCRtpReceiver?.getCapabilities !== 'undefined')
  158. // this is not working on Safari because of the following bug
  159. // https://bugs.webkit.org/show_bug.cgi?id=215567
  160. && !this.isWebKitBased()
  161. // Calling this API on Firefox is causing freezes when the local endpoint is the answerer.
  162. // https://bugzilla.mozilla.org/show_bug.cgi?id=1917800
  163. && !this.isFirefox();
  164. }
  165. /**
  166. * Checks if the browser supports the new codec selection API, i.e., checks if dictionary member
  167. * RTCRtpEncodingParameters.codec as defined in
  168. * https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-codec is supported by the browser. It
  169. * allows the application to change the current codec used by each RTCRtpSender without a renegotiation.
  170. *
  171. * @returns {boolean}
  172. */
  173. supportsCodecSelectionAPI(): boolean {
  174. return this.isChromiumBased() && this.isEngineVersionGreaterThan(125);
  175. }
  176. /**
  177. * Returns true if the browser supports Dependency Descriptor header extension.
  178. *
  179. * @returns {boolean}
  180. */
  181. supportsDDExtHeaders(): boolean {
  182. return !(this.isFirefox() && this.isVersionLessThan(136));
  183. }
  184. /**
  185. * Checks if the current browser support the device change event.
  186. * @return {boolean}
  187. */
  188. supportsDeviceChangeEvent(): boolean {
  189. return typeof navigator.mediaDevices?.ondevicechange !== 'undefined'
  190. && typeof navigator.mediaDevices?.addEventListener !== 'undefined';
  191. }
  192. /**
  193. * Checks if the current browser supports audio level stats on the receivers.
  194. *
  195. * @return {boolean}
  196. */
  197. supportsReceiverStats(): boolean {
  198. return typeof window.RTCRtpReceiver !== 'undefined'
  199. && Object.keys(RTCRtpReceiver.prototype).indexOf('getSynchronizationSources') > -1;
  200. }
  201. /**
  202. * Checks if the current browser reports round trip time statistics for the ICE candidate pair.
  203. *
  204. * @return {boolean}
  205. */
  206. supportsRTTStatistics(): boolean {
  207. // Firefox does not seem to report RTT for ICE candidate pair:
  208. // eslint-disable-next-line max-len
  209. // https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
  210. // It does report mozRTT for RTP streams, but at the time of this
  211. // writing it's value does not make sense most of the time
  212. // (is reported as 1):
  213. // https://bugzilla.mozilla.org/show_bug.cgi?id=1241066
  214. // For Chrome and others we rely on 'googRtt'.
  215. return !this.isFirefox();
  216. }
  217. /**
  218. * Returns true if the browser supports the new Scalability Mode API for VP9/AV1 simulcast and full SVC. H.264
  219. * simulcast will also be supported by the jvb for this version because the bridge is able to read the Dependency
  220. * Descriptor RTP header extension to extract layers information for H.264 as well.
  221. *
  222. * @returns {boolean}
  223. */
  224. supportsScalabilityModeAPI(): boolean {
  225. return this.isChromiumBased() && this.isEngineVersionGreaterThan(112);
  226. }
  227. /**
  228. * Returns true if the browser supports track based statistics for the local video track. Otherwise,
  229. * track resolution and framerate will be calculated based on the 'outbound-rtp' statistics.
  230. *
  231. * @returns {boolean}
  232. */
  233. supportsTrackBasedStats(): boolean {
  234. return this.isChromiumBased() && this.isEngineVersionLessThan(112);
  235. }
  236. /**
  237. * Returns true if VP9 is supported by the client on the browser. VP9 is currently disabled on Safari
  238. * and older versions of Firefox because of issues. Please check https://bugs.webkit.org/show_bug.cgi?id=231074 for
  239. * details.
  240. *
  241. * @returns {boolean}
  242. */
  243. supportsVP9(): boolean {
  244. // Keep this disabled for FF because simulcast is disabled by default.
  245. // For versions 136+ if the media.webrtc.simulcast.vp9.enabled config is set to true it will work.
  246. // TODO: enable for FF with version 136+ once media.webrtc.simulcast.vp9.enabled is set to true by default.
  247. return !(this.isWebKitBased() || this.isFirefox());
  248. }
  249. /**
  250. * Returns true if SVC is supported.
  251. *
  252. * @returns {boolean}
  253. */
  254. supportsSVC(): boolean {
  255. return !this.isFirefox();
  256. }
  257. /**
  258. * Checks if the browser uses SDP munging for turning on simulcast.
  259. *
  260. * @returns {boolean}
  261. */
  262. usesSdpMungingForSimulcast(): boolean {
  263. return this.isChromiumBased() || this.isReactNative() || this.isWebKitBased();
  264. }
  265. /**
  266. * Checks if the browser uses RIDs/MIDs for siganling the simulcast streams
  267. * to the bridge instead of the ssrcs.
  268. *
  269. * @returns {boolean}
  270. */
  271. usesRidsForSimulcast(): boolean {
  272. return false;
  273. }
  274. /**
  275. * Checks if the browser supports getDisplayMedia.
  276. *
  277. * @returns {boolean} {@code true} if the browser supports getDisplayMedia.
  278. */
  279. supportsGetDisplayMedia(): boolean {
  280. // @ts-ignore
  281. return typeof navigator.getDisplayMedia !== 'undefined'
  282. || (typeof navigator.mediaDevices?.getDisplayMedia !== 'undefined');
  283. }
  284. /**
  285. * Checks if the browser supports WebRTC Encoded Transform, an alternative
  286. * to insertable streams.
  287. *
  288. * NOTE: At the time of this writing the only browser supporting this is
  289. * Safari / WebKit, behind a flag.
  290. *
  291. * @returns {boolean} {@code true} if the browser supports it.
  292. */
  293. supportsEncodedTransform(): boolean {
  294. return Boolean(window.RTCRtpScriptTransform);
  295. }
  296. /**
  297. * Checks if the browser supports insertable streams, needed for E2EE.
  298. *
  299. * @returns {boolean} {@code true} if the browser supports insertable streams.
  300. */
  301. supportsInsertableStreams(): boolean {
  302. // @ts-ignore
  303. if (!window.RTCRtpSender?.prototype.createEncodedStreams) {
  304. return false;
  305. }
  306. // Feature-detect transferable streams which we need to operate in a worker.
  307. // See https://groups.google.com/a/chromium.org/g/blink-dev/c/1LStSgBt6AM/m/hj0odB8pCAAJ
  308. const stream = new ReadableStream();
  309. try {
  310. window.postMessage(stream, '*', [ stream ]);
  311. return true;
  312. } catch {
  313. return false;
  314. }
  315. }
  316. /**
  317. * Whether the browser supports the RED format for audio.
  318. *
  319. * @returns {boolean} {@code true} if the browser supports RED.
  320. */
  321. supportsAudioRed(): boolean {
  322. return Boolean(window.RTCRtpSender?.getCapabilities('audio')?.codecs.some(codec => codec.mimeType === 'audio/red')
  323. && window.RTCRtpReceiver?.getCapabilities('audio')?.codecs.some(codec => codec.mimeType === 'audio/red'));
  324. }
  325. /**
  326. * Checks if the browser supports voice activity detection via the @type {VADAudioAnalyser} service.
  327. *
  328. * @returns {boolean}
  329. */
  330. supportsVADDetection(): boolean {
  331. return this.isChromiumBased();
  332. }
  333. /**
  334. * Check if the browser supports the RTP RTX feature (and it is usable).
  335. *
  336. * @returns {boolean}
  337. */
  338. supportsRTX(): boolean {
  339. // Disable RTX on Firefox up to 96 because we prefer simulcast over RTX
  340. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1738504
  341. return !(this.isFirefox() && this.isVersionLessThan(96));
  342. }
  343. }