modified lib-jitsi-meet dev repo
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 8.0KB

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