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.

JitsiConference.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. var RTC = require("./modules/RTC/RTC");
  2. var XMPPEvents = require("./service/xmpp/XMPPEvents");
  3. /**
  4. * Creates a JitsiConference object with the given name and properties.
  5. * Note: this constructor is not a part of the public API (objects should be
  6. * created using JitsiConnection.createConference).
  7. * @param options.config properties / settings related to the conference that will be created.
  8. * @param options.name the name of the conference
  9. * @param options.connection the JitsiConnection object for this JitsiConference.
  10. * @constructor
  11. */
  12. function JitsiConference(options) {
  13. this.options = options;
  14. this.connection = this.options.connection;
  15. this.xmpp = this.connection.xmpp;
  16. this.room = this.xmpp.createRoom(this.options.name, null, null);
  17. this.rtc = new RTC();
  18. this.xmpp.addListener(XMPPEvents.CALL_INCOMING,
  19. this.rtc.onIncommingCall.bind(this.rtc));
  20. }
  21. /**
  22. * Joins the conference.
  23. * @param password {string} the password
  24. */
  25. JitsiConference.prototype.join = function (password) {
  26. this.room.joinRoom(password);
  27. }
  28. /**
  29. * Leaves the conference.
  30. */
  31. JitsiConference.prototype.leave = function () {
  32. this.xmpp.leaveRoom(room.roomjid);
  33. this.room = null;
  34. }
  35. /**
  36. * Creates the media tracks and returns them via the callback.
  37. * @param options Object with properties / settings specifying the tracks which should be created.
  38. * should be created or some additional configurations about resolution for example.
  39. * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>} A promise that returns an array of created JitsiTracks if resolved,
  40. * or a JitsiConferenceError if rejected.
  41. */
  42. JitsiConference.prototype.createLocalTracks = function (options) {
  43. this.rtc.obtainAudioAndVideoPermissions();
  44. }
  45. /**
  46. * Returns the local tracks.
  47. */
  48. JitsiConference.prototype.getLocalTracks = function () {
  49. return this.rtc.localStreams;
  50. };
  51. /**
  52. * Attaches a handler for events(For example - "participant joined".) in the conference. All possible event are defined
  53. * in JitsiConferenceEvents.
  54. * @param eventId the event ID.
  55. * @param handler handler for the event.
  56. *
  57. * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
  58. */
  59. JitsiConference.prototype.on = function (eventId, handler) {
  60. this.room.addListener(eventId, handler);
  61. }
  62. /**
  63. * Removes event listener
  64. * @param eventId the event ID.
  65. * @param [handler] optional, the specific handler to unbind
  66. *
  67. * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
  68. */
  69. JitsiConference.prototype.off = function (eventId, handler) {
  70. this.room.removeListener(eventId, listener);
  71. }
  72. // Common aliases for event emitter
  73. JitsiConference.prototype.addEventListener = JitsiConference.prototype.on
  74. JitsiConference.prototype.removeEventListener = JitsiConference.prototype.off
  75. /**
  76. * Receives notifications from another participants for commands / custom events(send by sendPresenceCommand method).
  77. * @param command {String} the name of the command
  78. * @param handler {Function} handler for the command
  79. */
  80. JitsiConference.prototype.addCommandListener = function (command, handler) {
  81. this.room.addPresenceListener(command, handler);
  82. }
  83. /**
  84. * Removes command listener
  85. * @param command {String} the name of the command
  86. */
  87. JitsiConference.prototype.removeCommandListener = function (command) {
  88. this.room.removePresenceListener(command);
  89. }
  90. /**
  91. * Sends text message to the other participants in the conference
  92. * @param message the text message.
  93. */
  94. JitsiConference.prototype.sendTextMessage = function (message) {
  95. this.room.sendMessage(message);
  96. }
  97. /**
  98. * Send presence command.
  99. * @param name the name of the command.
  100. * @param values Object with keys and values that will be send.
  101. **/
  102. JitsiConference.prototype.sendCommand = function (name, values) {
  103. this.room.addToPresence(name, values);
  104. this.room.sendPresence();
  105. }
  106. /**
  107. * Send presence command one time.
  108. * @param name the name of the command.
  109. * @param values Object with keys and values that will be send.
  110. **/
  111. JitsiConference.prototype.sendCommandOnce = function (name, values) {
  112. this.sendCommand(name, values);
  113. this.removeCommand(name);
  114. }
  115. /**
  116. * Send presence command.
  117. * @param name the name of the command.
  118. * @param values Object with keys and values that will be send.
  119. * @param persistent if false the command will be sent only one time
  120. **/
  121. JitsiConference.prototype.removeCommand = function (name) {
  122. this.room.removeFromPresence(name);
  123. }
  124. /**
  125. * Sets the display name for this conference.
  126. * @param name the display name to set
  127. */
  128. JitsiConference.prototype.setDisplayName = function(name) {
  129. this.room.addToPresence("nick", {attributes: {xmlns: 'http://jabber.org/protocol/nick'}, value: name});
  130. }
  131. /**
  132. * Elects the participant with the given id to be the selected participant or the speaker.
  133. * @param id the identifier of the participant
  134. */
  135. JitsiConference.prototype.selectParticipant = function(participantId) {
  136. this.rtc.selectedEndpoint(participantId);
  137. }
  138. /**
  139. *
  140. * @param id the identifier of the participant
  141. */
  142. JitsiConference.prototype.pinParticipant = function(participantId) {
  143. this.rtc.pinEndpoint(participantId);
  144. }
  145. /**
  146. * Returns the list of participants for this conference.
  147. * @return Object a list of participant identifiers containing all conference participants.
  148. */
  149. JitsiConference.prototype.getParticipants = function() {
  150. }
  151. /**
  152. * @returns {JitsiParticipant} the participant in this conference with the specified id (or
  153. * null if there isn't one).
  154. * @param id the id of the participant.
  155. */
  156. JitsiConference.prototype.getParticipantById = function(id) {
  157. }
  158. module.exports = JitsiConference;