Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

JitsiConnection.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. var JitsiConference = require("./JitsiConference");
  2. var XMPP = require("./modules/xmpp/xmpp");
  3. var JitsiConnectionEvents = require("./JitsiConnectionEvents");
  4. var JitsiConnectionErrors = require("./JitsiConnectionErrors");
  5. var Statistics = require("./modules/statistics/statistics");
  6. /**
  7. * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
  8. * JitsiConference interface.
  9. * @param appID identification for the provider of Jitsi Meet video conferencing services.
  10. * @param token the JWT token used to authenticate with the server(optional)
  11. * @param options Object with properties / settings related to connection with the server.
  12. * @constructor
  13. */
  14. function JitsiConnection(appID, token, options) {
  15. this.appID = appID;
  16. this.token = token;
  17. this.options = options;
  18. this.xmpp = new XMPP(options, token);
  19. this.conferences = {};
  20. this.addEventListener(JitsiConnectionEvents.CONNECTION_FAILED,
  21. function (errType, msg) {
  22. Statistics.analytics.sendEvent('connection.failed.' + errType);
  23. }.bind(this));
  24. this.addEventListener(JitsiConnectionEvents.CONNECTION_DISCONNECTED,
  25. function (msg) {
  26. // we can see disconnects from normal tab closing of the browser
  27. // and then there are no msgs, but we want to log only disconnects
  28. // when there is real error
  29. if(msg)
  30. Statistics.analytics.sendEvent(
  31. 'connection.disconnected.' + msg);
  32. });
  33. }
  34. /**
  35. * Connect the client with the server.
  36. * @param options {object} connecting options
  37. * (for example authentications parameters).
  38. */
  39. JitsiConnection.prototype.connect = function (options) {
  40. if(!options)
  41. options = {};
  42. this.xmpp.connect(options.id, options.password);
  43. }
  44. /**
  45. * Attach to existing connection. Can be used for optimizations. For example:
  46. * if the connection is created on the server we can attach to it and start
  47. * using it.
  48. *
  49. * @param options {object} connecting options - rid, sid and jid.
  50. */
  51. JitsiConnection.prototype.attach = function (options) {
  52. this.xmpp.attach(options);
  53. }
  54. /**
  55. * Disconnect the client from the server.
  56. */
  57. JitsiConnection.prototype.disconnect = function () {
  58. // XXX Forward any arguments passed to JitsiConnection.disconnect to
  59. // XMPP.disconnect. For example, the caller of JitsiConnection.disconnect
  60. // may optionally pass the event which triggered the disconnect in order to
  61. // provide the implementation with finer-grained context.
  62. var x = this.xmpp;
  63. x.disconnect.apply(x, arguments);
  64. }
  65. /**
  66. * This method allows renewal of the tokens if they are expiring.
  67. * @param token the new token.
  68. */
  69. JitsiConnection.prototype.setToken = function (token) {
  70. this.token = token;
  71. }
  72. /**
  73. * Creates and joins new conference.
  74. * @param name the name of the conference; if null - a generated name will be
  75. * provided from the api
  76. * @param options Object with properties / settings related to the conference
  77. * that will be created.
  78. * @returns {JitsiConference} returns the new conference object.
  79. */
  80. JitsiConnection.prototype.initJitsiConference = function (name, options) {
  81. var conference
  82. = new JitsiConference({name: name, config: options, connection: this});
  83. this.conferences[name] = conference;
  84. return conference;
  85. }
  86. /**
  87. * Subscribes the passed listener to the event.
  88. * @param event {JitsiConnectionEvents} the connection event.
  89. * @param listener {Function} the function that will receive the event
  90. */
  91. JitsiConnection.prototype.addEventListener = function (event, listener) {
  92. this.xmpp.addListener(event, listener);
  93. }
  94. /**
  95. * Unsubscribes the passed handler.
  96. * @param event {JitsiConnectionEvents} the connection event.
  97. * @param listener {Function} the function that will receive the event
  98. */
  99. JitsiConnection.prototype.removeEventListener = function (event, listener) {
  100. this.xmpp.removeListener(event, listener);
  101. }
  102. /**
  103. * Returns measured connectionTimes.
  104. */
  105. JitsiConnection.prototype.getConnectionTimes = function () {
  106. return this.xmpp.connectionTimes;
  107. };
  108. module.exports = JitsiConnection;