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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. var JitsiConference = require("./JitsiConference");
  2. var XMPP = require("./modules/xmpp/xmpp");
  3. /**
  4. * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
  5. * JitsiConference interface.
  6. * @param appID identification for the provider of Jitsi Meet video conferencing services.
  7. * @param token the JWT token used to authenticate with the server(optional)
  8. * @param options Object with properties / settings related to connection with the server.
  9. * @constructor
  10. */
  11. function JitsiConnection(appID, token, options) {
  12. this.appID = appID;
  13. this.token = token;
  14. this.options = options;
  15. this.xmpp = new XMPP(options);
  16. this.conferences = {};
  17. }
  18. /**
  19. * Connect the client with the server.
  20. * @param options {object} connecting options (for example authentications parameters).
  21. */
  22. JitsiConnection.prototype.connect = function (options) {
  23. if(!options)
  24. options = {};
  25. this.xmpp.connect(options.id, options.password);
  26. }
  27. /**
  28. * Disconnect the client from the server.
  29. */
  30. JitsiConnection.prototype.disconnect = function () {
  31. // XXX Forward any arguments passed to JitsiConnection.disconnect to
  32. // XMPP.disconnect. For example, the caller of JitsiConnection.disconnect
  33. // may optionally pass the event which triggered the disconnect in order to
  34. // provide the implementation with finer-grained context.
  35. var x = this.xmpp;
  36. x.disconnect.apply(x, arguments);
  37. }
  38. /**
  39. * This method allows renewal of the tokens if they are expiring.
  40. * @param token the new token.
  41. */
  42. JitsiConnection.prototype.setToken = function (token) {
  43. this.token = token;
  44. }
  45. /**
  46. * Creates and joins new conference.
  47. * @param name the name of the conference; if null - a generated name will be
  48. * provided from the api
  49. * @param options Object with properties / settings related to the conference
  50. * that will be created.
  51. * @returns {JitsiConference} returns the new conference object.
  52. */
  53. JitsiConnection.prototype.initJitsiConference = function (name, options) {
  54. this.conferences[name] = new JitsiConference({name: name, config: options,
  55. connection: this});
  56. return this.conferences[name];
  57. }
  58. /**
  59. * Subscribes the passed listener to the event.
  60. * @param event {JitsiConnectionEvents} the connection event.
  61. * @param listener {Function} the function that will receive the event
  62. */
  63. JitsiConnection.prototype.addEventListener = function (event, listener) {
  64. this.xmpp.addListener(event, listener);
  65. }
  66. /**
  67. * Unsubscribes the passed handler.
  68. * @param event {JitsiConnectionEvents} the connection event.
  69. * @param listener {Function} the function that will receive the event
  70. */
  71. JitsiConnection.prototype.removeEventListener = function (event, listener) {
  72. this.xmpp.removeListener(event, listener);
  73. }
  74. module.exports = JitsiConnection;