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 8.5KB

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