Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

BrowserCapabilities.js 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. import BrowserDetection from './BrowserDetection';
  2. import capabilitiesDB from './capabilities.json';
  3. // TODO: All methods should use capabilities.json when possible.
  4. // NOTE: Now we are extending BrowserDetection in order to preserve
  5. // RTCBrowserType interface but maybe it worth exporting BrowserCapabilities
  6. // and BrowserDetection as separate objects in future.
  7. /**
  8. * Implements browser capabilities for lib-jitsi-meet.
  9. */
  10. export default class BrowserCapabilities extends BrowserDetection {
  11. /**
  12. * Creates new BrowserCapabilities instance.
  13. *
  14. * @param {boolean} [isUsingIFrame] - True if Jitsi Meet is loaded in iframe
  15. * and false otherwise.
  16. * @param {Object} [browserInfo] - Information about the browser.
  17. * @param {string} browserInfo.name - The name of the browser.
  18. * @param {string} browserInfo.version - The version of the browser.
  19. */
  20. constructor(isUsingIFrame = false, browserInfo) {
  21. super(browserInfo);
  22. const browserCapabilities = capabilitiesDB[this.getName()] || [];
  23. const capabilitiesByVersion = browserCapabilities.find(({ version }) =>
  24. !version || !this.isVersionLessThan(version));
  25. if (!capabilitiesByVersion || !capabilitiesByVersion.capabilities) {
  26. this._capabilities = { isSupported: false };
  27. } else if (isUsingIFrame) {
  28. this._capabilities = {
  29. ...capabilitiesByVersion.capabilities,
  30. ...capabilitiesByVersion.iframeCapabilities
  31. };
  32. } else {
  33. this._capabilities = capabilitiesByVersion.capabilities;
  34. }
  35. if (typeof this._capabilities.isSupported === 'undefined') {
  36. // we have some capabilities but isSupported property is not filled.
  37. this._capabilities.isSupported = true;
  38. } else if (this._capabilities.isSupported === false) {
  39. this._capabilities = { isSupported: false };
  40. }
  41. }
  42. /**
  43. * Tells whether or not the <tt>MediaStream/tt> is removed from
  44. * the <tt>PeerConnection</tt> and disposed on video mute (in order to turn
  45. * off the camera device).
  46. * @return {boolean} <tt>true</tt> if the current browser supports this
  47. * strategy or <tt>false</tt> otherwise.
  48. */
  49. doesVideoMuteByStreamRemove() {
  50. return !(
  51. this.isFirefox()
  52. || this.isEdge()
  53. || this.isSafariWithWebrtc()
  54. );
  55. }
  56. /**
  57. * Check whether or not the current browser support peer to peer connections
  58. * @return {boolean} <tt>true</tt> if p2p is supported or <tt>false</tt>
  59. * otherwise.
  60. */
  61. supportsP2P() {
  62. return !this.isEdge();
  63. }
  64. /**
  65. * Checks if current browser is a Safari and a version of Safari that
  66. * supports native webrtc.
  67. *
  68. * @returns {boolean}
  69. */
  70. isSafariWithWebrtc() {
  71. return this.isSafari()
  72. && !this.isVersionLessThan('11');
  73. }
  74. /**
  75. * Checks whether the browser is supported by Jitsi Meet.
  76. *
  77. * @returns {boolean}
  78. */
  79. isSupported() {
  80. return this._capabilities.isSupported;
  81. }
  82. /**
  83. * Checks if Temasys RTC plugin is used.
  84. * @returns {boolean}
  85. */
  86. isTemasysPluginUsed() {
  87. // Temasys do not support Microsoft Edge:
  88. // http://support.temasys.com.sg/support/solutions/articles/
  89. // 5000654345-can-the-temasys-webrtc-plugin-be-used-with-microsoft-edge-
  90. return (
  91. (this.isSafari()
  92. && !this.isSafariWithWebrtc())
  93. || (this.isIExplorer()
  94. && this.isVersionLessThan('12'))
  95. );
  96. }
  97. /**
  98. * Checks if the current browser triggers 'onmute'/'onunmute' events when
  99. * user's connection is interrupted and the video stops playback.
  100. * @returns {*|boolean} 'true' if the event is supported or 'false'
  101. * otherwise.
  102. */
  103. supportsVideoMuteOnConnInterrupted() {
  104. return this.isChrome() || this.isElectron();
  105. }
  106. /**
  107. * Checks whether the browser supports incoming audio.
  108. *
  109. * @returns {boolean}
  110. */
  111. supportsAudioIn() {
  112. return this._capabilities.audioIn || false;
  113. }
  114. /**
  115. * Checks whether the browser supports outgoing audio.
  116. *
  117. * @returns {boolean}
  118. */
  119. supportsAudioOut() {
  120. return this._capabilities.audioOut || false;
  121. }
  122. /**
  123. * Checks if the current browser reports upload and download bandwidth
  124. * statistics.
  125. * @return {boolean}
  126. */
  127. supportsBandwidthStatistics() {
  128. // FIXME bandwidth stats are currently not implemented for FF on our
  129. // side, but not sure if not possible ?
  130. return !this.isFirefox() && !this.isEdge();
  131. }
  132. /**
  133. * Checks if the current browser supports WebRTC datachannels.
  134. * @return {boolean}
  135. */
  136. supportsDataChannels() {
  137. // NOTE: Edge does not yet implement DataChannel.
  138. return !this.isEdge();
  139. }
  140. /**
  141. * Checks if the current browser reports round trip time statistics for
  142. * the ICE candidate pair.
  143. * @return {boolean}
  144. */
  145. supportsRTTStatistics() {
  146. // Firefox does not seem to report RTT for ICE candidate pair:
  147. // eslint-disable-next-line max-len
  148. // https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
  149. // It does report mozRTT for RTP streams, but at the time of this
  150. // writing it's value does not make sense most of the time
  151. // (is reported as 1):
  152. // https://bugzilla.mozilla.org/show_bug.cgi?id=1241066
  153. // For Chrome and others we rely on 'googRtt'.
  154. return !this.isFirefox() && !this.isEdge();
  155. }
  156. /**
  157. * Checks whether the browser supports RTPSender.
  158. *
  159. * @returns {boolean}
  160. */
  161. supportsRtpSender() {
  162. return this.isFirefox();
  163. }
  164. /**
  165. * Checks whether the browser supports RTX.
  166. *
  167. * @returns {boolean}
  168. */
  169. supportsRtx() {
  170. return !this.isFirefox();
  171. }
  172. /**
  173. * Checks whether the browser supports screen sharing.
  174. *
  175. * @returns {boolean}
  176. */
  177. supportsScreenSharing() {
  178. return this._capabilities.screenSharing || false;
  179. }
  180. /**
  181. * Whether jitsi-meet supports simulcast on the current browser.
  182. * @returns {boolean}
  183. */
  184. supportsSimulcast() {
  185. return this.isChrome()
  186. || this.isFirefox()
  187. || this.isElectron()
  188. || this.isNWJS()
  189. || this.isReactNative();
  190. }
  191. /**
  192. * Returns whether or not the current browser can support capturing video,
  193. * be it camera or desktop, and displaying received video.
  194. *
  195. * @returns {boolean}
  196. */
  197. supportsVideo() {
  198. // FIXME: Check if we can use supportsVideoOut and supportsVideoIn. I
  199. // leave the old implementation here in order not to brake something.
  200. // Currently Safari using webrtc/adapter does not support video due in
  201. // part to Safari only supporting H264 and the bridge sending VP8.
  202. return !this.isSafariWithWebrtc();
  203. }
  204. /**
  205. * Checks whether the browser supports incomming video.
  206. *
  207. * @returns {boolean}
  208. */
  209. supportsVideoIn() {
  210. return this._capabilities.videoIn || false;
  211. }
  212. /**
  213. * Checks whether the browser supports incomming video.
  214. *
  215. * @returns {boolean}
  216. */
  217. supportsVideoOut() {
  218. return this._capabilities.videoOut || false;
  219. }
  220. /**
  221. * Checks if the browser uses plan B.
  222. *
  223. * @returns {boolean}
  224. */
  225. usesPlanB() {
  226. return !this.usesUnifiedPlan();
  227. }
  228. /**
  229. * Checks if the browser uses unified plan.
  230. *
  231. * @returns {boolean}
  232. */
  233. usesUnifiedPlan() {
  234. return this.isFirefox();
  235. }
  236. /**
  237. * Returns whether or not the current browser should be using the new
  238. * getUserMedia flow, which utilizes the adapter shim. This method should
  239. * be temporary and used while migrating all browsers to use adapter and
  240. * the new getUserMedia.
  241. *
  242. * @returns {boolean}
  243. */
  244. usesNewGumFlow() {
  245. return (this.isChrome()
  246. && !this.isVersionLessThan('61'))
  247. || this.isFirefox()
  248. || this.isSafariWithWebrtc();
  249. }
  250. }