modified lib-jitsi-meet dev repo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JitsiConnection.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import JitsiConference from './JitsiConference';
  2. import * as JitsiConnectionEvents from './JitsiConnectionEvents';
  3. import Statistics from './modules/statistics/statistics';
  4. import XMPP from './modules/xmpp/xmpp';
  5. import {
  6. CONNECTION_DISCONNECTED as ANALYTICS_CONNECTION_DISCONNECTED,
  7. createConnectionFailedEvent
  8. } from './service/statistics/AnalyticsEvents';
  9. /**
  10. * Creates a new connection object for the Jitsi Meet server side video
  11. * conferencing service. Provides access to the JitsiConference interface.
  12. * @param appID identification for the provider of Jitsi Meet video conferencing
  13. * services.
  14. * @param token the JWT token used to authenticate with the server(optional)
  15. * @param options Object with properties / settings related to connection with
  16. * the server.
  17. * @constructor
  18. */
  19. export default function JitsiConnection(appID, token, options) {
  20. this.appID = appID;
  21. this.token = token;
  22. this.options = options;
  23. this.xmpp = new XMPP(options, token);
  24. /* eslint-disable max-params */
  25. this.addEventListener(JitsiConnectionEvents.CONNECTION_FAILED,
  26. (errType, msg, credentials, details) => {
  27. Statistics.sendAnalyticsAndLog(
  28. createConnectionFailedEvent(errType, msg, details));
  29. });
  30. /* eslint-enable max-params */
  31. this.addEventListener(JitsiConnectionEvents.CONNECTION_DISCONNECTED,
  32. msg => {
  33. // we can see disconnects from normal tab closing of the browser
  34. // and then there are no msgs, but we want to log only disconnects
  35. // when there is real error
  36. // XXX Do we need the difference in handling between the log and
  37. // analytics event here?
  38. if (msg) {
  39. Statistics.sendAnalytics(
  40. ANALYTICS_CONNECTION_DISCONNECTED,
  41. { message: msg });
  42. }
  43. Statistics.sendLog(
  44. JSON.stringify(
  45. {
  46. id: ANALYTICS_CONNECTION_DISCONNECTED,
  47. msg
  48. }));
  49. });
  50. }
  51. /**
  52. * Connect the client with the server.
  53. * @param options {object} connecting options
  54. * (for example authentications parameters).
  55. */
  56. JitsiConnection.prototype.connect = function(options = {}) {
  57. this.xmpp.connect(options.id, options.password);
  58. };
  59. /**
  60. * Attach to existing connection. Can be used for optimizations. For example:
  61. * if the connection is created on the server we can attach to it and start
  62. * using it.
  63. *
  64. * @param options {object} connecting options - rid, sid and jid.
  65. */
  66. JitsiConnection.prototype.attach = function(options) {
  67. this.xmpp.attach(options);
  68. };
  69. /**
  70. * Disconnect the client from the server.
  71. * @returns {Promise} - Resolves when the disconnect process is finished or rejects with an error.
  72. */
  73. JitsiConnection.prototype.disconnect = function(...args) {
  74. // XXX Forward any arguments passed to JitsiConnection.disconnect to
  75. // XMPP.disconnect. For example, the caller of JitsiConnection.disconnect
  76. // may optionally pass the event which triggered the disconnect in order to
  77. // provide the implementation with finer-grained context.
  78. return this.xmpp.disconnect(...args);
  79. };
  80. /**
  81. * Returns the jid of the participant associated with the XMPP connection.
  82. *
  83. * @returns {string} The jid of the participant.
  84. */
  85. JitsiConnection.prototype.getJid = function() {
  86. return this.xmpp.getJid();
  87. };
  88. /**
  89. * This method allows renewal of the tokens if they are expiring.
  90. * @param token the new token.
  91. */
  92. JitsiConnection.prototype.setToken = function(token) {
  93. this.token = token;
  94. };
  95. /**
  96. * Creates and joins new conference.
  97. * @param name the name of the conference; if null - a generated name will be
  98. * provided from the api
  99. * @param options Object with properties / settings related to the conference
  100. * that will be created.
  101. * @returns {JitsiConference} returns the new conference object.
  102. */
  103. JitsiConnection.prototype.initJitsiConference = function(name, options) {
  104. return new JitsiConference({
  105. name,
  106. config: options,
  107. connection: this
  108. });
  109. };
  110. /**
  111. * Subscribes the passed listener to the event.
  112. * @param event {JitsiConnectionEvents} the connection event.
  113. * @param listener {Function} the function that will receive the event
  114. */
  115. JitsiConnection.prototype.addEventListener = function(event, listener) {
  116. this.xmpp.addListener(event, listener);
  117. };
  118. /**
  119. * Unsubscribes the passed handler.
  120. * @param event {JitsiConnectionEvents} the connection event.
  121. * @param listener {Function} the function that will receive the event
  122. */
  123. JitsiConnection.prototype.removeEventListener = function(event, listener) {
  124. this.xmpp.removeListener(event, listener);
  125. };
  126. /**
  127. * Returns measured connectionTimes.
  128. */
  129. JitsiConnection.prototype.getConnectionTimes = function() {
  130. return this.xmpp.connectionTimes;
  131. };
  132. /**
  133. * Adds new feature to the list of supported features for the local
  134. * participant.
  135. * @param {String} feature the name of the feature.
  136. * @param {boolean} submit if true - the new list of features will be
  137. * immediately submitted to the others.
  138. */
  139. JitsiConnection.prototype.addFeature = function(feature, submit = false) {
  140. this.xmpp.caps.addFeature(feature, submit, true);
  141. };
  142. /**
  143. * Removes a feature from the list of supported features for the local
  144. * participant
  145. * @param {String} feature the name of the feature.
  146. * @param {boolean} submit if true - the new list of features will be
  147. * immediately submitted to the others.
  148. */
  149. JitsiConnection.prototype.removeFeature = function(feature, submit = false) {
  150. this.xmpp.caps.removeFeature(feature, submit, true);
  151. };
  152. /**
  153. * Get object with internal logs.
  154. */
  155. JitsiConnection.prototype.getLogs = function() {
  156. const data = this.xmpp.getJingleLog();
  157. const metadata = {};
  158. metadata.time = new Date();
  159. metadata.url = window.location.href;
  160. metadata.ua = navigator.userAgent;
  161. const log = this.xmpp.getXmppLog();
  162. if (log) {
  163. metadata.xmpp = log;
  164. }
  165. data.metadata = metadata;
  166. return data;
  167. };