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

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