選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

JitsiConnection.js 6.9KB

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