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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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, token);
  16. this.conferences = {};
  17. }
  18. /**
  19. * Connect the client with the server.
  20. * @param options {object} connecting options
  21. * (for example authentications parameters).
  22. */
  23. JitsiConnection.prototype.connect = function (options) {
  24. if(!options)
  25. options = {};
  26. this.xmpp.connect(options.id, options.password);
  27. }
  28. /**
  29. * Attach to existing connection. Can be used for optimizations. For example:
  30. * if the connection is created on the server we can attach to it and start
  31. * using it.
  32. *
  33. * @param options {object} connecting options - rid, sid and jid.
  34. */
  35. JitsiConnection.prototype.attach = function (options) {
  36. this.xmpp.attach(options);
  37. }
  38. /**
  39. * Disconnect the client from the server.
  40. */
  41. JitsiConnection.prototype.disconnect = function () {
  42. // XXX Forward any arguments passed to JitsiConnection.disconnect to
  43. // XMPP.disconnect. For example, the caller of JitsiConnection.disconnect
  44. // may optionally pass the event which triggered the disconnect in order to
  45. // provide the implementation with finer-grained context.
  46. var x = this.xmpp;
  47. x.disconnect.apply(x, arguments);
  48. }
  49. /**
  50. * This method allows renewal of the tokens if they are expiring.
  51. * @param token the new token.
  52. */
  53. JitsiConnection.prototype.setToken = function (token) {
  54. this.token = token;
  55. }
  56. /**
  57. * Creates and joins new conference.
  58. * @param name the name of the conference; if null - a generated name will be
  59. * provided from the api
  60. * @param options Object with properties / settings related to the conference
  61. * that will be created.
  62. * @returns {JitsiConference} returns the new conference object.
  63. */
  64. JitsiConnection.prototype.initJitsiConference = function (name, options) {
  65. this.conferences[name] = new JitsiConference({name: name, config: options,
  66. connection: this});
  67. return this.conferences[name];
  68. }
  69. /**
  70. * Subscribes the passed listener to the event.
  71. * @param event {JitsiConnectionEvents} the connection event.
  72. * @param listener {Function} the function that will receive the event
  73. */
  74. JitsiConnection.prototype.addEventListener = function (event, listener) {
  75. this.xmpp.addListener(event, listener);
  76. }
  77. /**
  78. * Unsubscribes the passed handler.
  79. * @param event {JitsiConnectionEvents} the connection event.
  80. * @param listener {Function} the function that will receive the event
  81. */
  82. JitsiConnection.prototype.removeEventListener = function (event, listener) {
  83. this.xmpp.removeListener(event, listener);
  84. }
  85. module.exports = JitsiConnection;