Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

BrowserCapabilities.js 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 current browser is a Safari and a version of Safari that
  45. * supports native webrtc.
  46. *
  47. * @returns {boolean}
  48. */
  49. isSafariWithWebrtc() {
  50. return this.isSafari()
  51. && !this.isVersionLessThan('11');
  52. }
  53. /**
  54. * Checks if the current browser triggers 'onmute'/'onunmute' events when
  55. * user's connection is interrupted and the video stops playback.
  56. * @returns {*|boolean} 'true' if the event is supported or 'false'
  57. * otherwise.
  58. */
  59. supportsVideoMuteOnConnInterrupted() {
  60. return this.isChrome() || this.isElectron() || this.isReactNative();
  61. }
  62. /**
  63. * Checks if the current browser reports upload and download bandwidth
  64. * statistics.
  65. * @return {boolean}
  66. */
  67. supportsBandwidthStatistics() {
  68. // FIXME bandwidth stats are currently not implemented for FF on our
  69. // side, but not sure if not possible ?
  70. return !this.isFirefox() && !this.isEdge()
  71. && !this.isSafariWithWebrtc();
  72. }
  73. /**
  74. * Checks if the current browser supports WebRTC datachannels.
  75. * @return {boolean}
  76. */
  77. supportsDataChannels() {
  78. // NOTE: Edge does not yet implement DataChannel.
  79. return !this.isEdge();
  80. }
  81. /**
  82. * Checks if the current browser supports the MediaStream constructor as
  83. * defined by https://www.w3.org/TR/mediacapture-streams/#constructors. In
  84. * cases where there is no support, it maybe be necessary to get audio
  85. * and video in two distinct GUM calls.
  86. * @return {boolean}
  87. */
  88. supportsMediaStreamConstructor() {
  89. return !this.isReactNative();
  90. }
  91. /**
  92. * Checks if the current browser reports round trip time statistics for
  93. * the ICE candidate pair.
  94. * @return {boolean}
  95. */
  96. supportsRTTStatistics() {
  97. // Firefox does not seem to report RTT for ICE candidate pair:
  98. // eslint-disable-next-line max-len
  99. // https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
  100. // It does report mozRTT for RTP streams, but at the time of this
  101. // writing it's value does not make sense most of the time
  102. // (is reported as 1):
  103. // https://bugzilla.mozilla.org/show_bug.cgi?id=1241066
  104. // For Chrome and others we rely on 'googRtt'.
  105. return !this.isFirefox() && !this.isEdge();
  106. }
  107. /**
  108. * Checks whether the browser supports RTPSender.
  109. *
  110. * @returns {boolean}
  111. */
  112. supportsRtpSender() {
  113. return this.isFirefox();
  114. }
  115. /**
  116. * Checks whether the browser supports RTX.
  117. *
  118. * @returns {boolean}
  119. */
  120. supportsRtx() {
  121. return !this.isFirefox();
  122. }
  123. /**
  124. * Whether jitsi-meet supports simulcast on the current browser.
  125. * @returns {boolean}
  126. */
  127. supportsSimulcast() {
  128. return this.isChrome()
  129. || this.isFirefox()
  130. || this.isElectron()
  131. || this.isNWJS()
  132. || this.isReactNative();
  133. }
  134. /**
  135. * Returns whether or not the current browser can support capturing video,
  136. * be it camera or desktop, and displaying received video.
  137. *
  138. * @returns {boolean}
  139. */
  140. supportsVideo() {
  141. // FIXME: Check if we can use supportsVideoOut and supportsVideoIn. I
  142. // leave the old implementation here in order not to brake something.
  143. // Currently Safari using webrtc/adapter does not support video due in
  144. // part to Safari only supporting H264 and the bridge sending VP8.
  145. return !this.isSafariWithWebrtc();
  146. }
  147. /**
  148. * Checks if the browser uses plan B.
  149. *
  150. * @returns {boolean}
  151. */
  152. usesPlanB() {
  153. return !this.usesUnifiedPlan();
  154. }
  155. /**
  156. * Checks if the browser uses unified plan.
  157. *
  158. * @returns {boolean}
  159. */
  160. usesUnifiedPlan() {
  161. return this.isFirefox();
  162. }
  163. /**
  164. * Returns whether or not the current browser should be using the new
  165. * getUserMedia flow, which utilizes the adapter shim. This method should
  166. * be temporary and used while migrating all browsers to use adapter and
  167. * the new getUserMedia.
  168. *
  169. * @returns {boolean}
  170. */
  171. usesNewGumFlow() {
  172. return (this.isChrome()
  173. && !this.isVersionLessThan('61'))
  174. || this.isFirefox()
  175. || this.isSafariWithWebrtc();
  176. }
  177. }