您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

BrowserCapabilities.js 7.0KB

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