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

JitsiConnection.js 3.5KB

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