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.

JitsiParticipant.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* global Strophe */
  2. import * as JitsiConferenceEvents from './JitsiConferenceEvents';
  3. import * as MediaType from './service/RTC/MediaType';
  4. /**
  5. * Represents a participant in (i.e. a member of) a conference.
  6. */
  7. export default class JitsiParticipant {
  8. /* eslint-disable max-params */
  9. /**
  10. * Initializes a new JitsiParticipant instance.
  11. *
  12. * @constructor
  13. * @param jid the conference XMPP jid
  14. * @param conference
  15. * @param displayName
  16. * @param {Boolean} hidden - True if the new JitsiParticipant instance is to
  17. * represent a hidden participant; otherwise, false.
  18. */
  19. constructor(jid, conference, displayName, hidden) {
  20. this._jid = jid;
  21. this._id = Strophe.getResourceFromJid(jid);
  22. this._conference = conference;
  23. this._displayName = displayName;
  24. this._supportsDTMF = false;
  25. this._tracks = [];
  26. this._role = 'none';
  27. this._status = null;
  28. this._availableDevices = {
  29. audio: undefined,
  30. video: undefined
  31. };
  32. this._hidden = hidden;
  33. this._isConnectionActive = true;
  34. this._properties = {};
  35. }
  36. /* eslint-enable max-params */
  37. /**
  38. * @returns {JitsiConference} The conference that this participant belongs
  39. * to.
  40. */
  41. getConference() {
  42. return this._conference;
  43. }
  44. /**
  45. * Gets the value of a property of this participant.
  46. */
  47. getProperty(name) {
  48. return this._properties[name];
  49. }
  50. /**
  51. * Checks whether this <tt>JitsiParticipant</tt> has any video tracks which
  52. * are muted according to their underlying WebRTC <tt>MediaStreamTrack</tt>
  53. * muted status.
  54. * @return {boolean} <tt>true</tt> if this <tt>participant</tt> contains any
  55. * video <tt>JitsiTrack</tt>s which are muted as defined in
  56. * {@link JitsiTrack.isWebRTCTrackMuted}.
  57. */
  58. hasAnyVideoTrackWebRTCMuted() {
  59. return (
  60. this.getTracks().some(
  61. jitsiTrack =>
  62. jitsiTrack.getType() === MediaType.VIDEO
  63. && jitsiTrack.isWebRTCTrackMuted()));
  64. }
  65. /**
  66. * Updates participant's connection status.
  67. * @param {boolean} isActive true if the user's connection is fine or false
  68. * when the user is having connectivity issues.
  69. * @private
  70. */
  71. _setIsConnectionActive(isActive) {
  72. this._isConnectionActive = isActive;
  73. }
  74. /**
  75. * Checks participant's connectivity status.
  76. *
  77. * @returns {boolean} true if the connection is currently ok or false when
  78. * the user is having connectivity issues.
  79. */
  80. isConnectionActive() {
  81. return this._isConnectionActive;
  82. }
  83. /**
  84. * Sets the value of a property of this participant, and fires an event if
  85. * the value has changed.
  86. * @name the name of the property.
  87. * @value the value to set.
  88. */
  89. setProperty(name, value) {
  90. const oldValue = this._properties[name];
  91. if (value !== oldValue) {
  92. this._properties[name] = value;
  93. this._conference.eventEmitter.emit(
  94. JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
  95. this,
  96. name,
  97. oldValue,
  98. value);
  99. }
  100. }
  101. /**
  102. * @returns {Array.<JitsiTrack>} The list of media tracks for this
  103. * participant.
  104. */
  105. getTracks() {
  106. return this._tracks.slice();
  107. }
  108. /**
  109. * @returns {String} The ID of this participant.
  110. */
  111. getId() {
  112. return this._id;
  113. }
  114. /**
  115. * @returns {String} The JID of this participant.
  116. */
  117. getJid() {
  118. return this._jid;
  119. }
  120. /**
  121. * @returns {String} The human-readable display name of this participant.
  122. */
  123. getDisplayName() {
  124. return this._displayName;
  125. }
  126. /**
  127. * @returns {String} The status of the participant.
  128. */
  129. getStatus() {
  130. return this._status;
  131. }
  132. /**
  133. * @returns {Boolean} Whether this participant is a moderator or not.
  134. */
  135. isModerator() {
  136. return this._role === 'moderator';
  137. }
  138. /**
  139. * @returns {Boolean} Whether this participant is a hidden participant. Some
  140. * special system participants may want to join hidden (like for example the
  141. * recorder).
  142. */
  143. isHidden() {
  144. return this._hidden;
  145. }
  146. // Gets a link to an etherpad instance advertised by the participant?
  147. // getEtherpad() {
  148. // }
  149. /**
  150. * @returns {Boolean} Whether this participant has muted their audio.
  151. */
  152. isAudioMuted() {
  153. return this._isMediaTypeMuted(MediaType.AUDIO);
  154. }
  155. /**
  156. * Determines whether all JitsiTracks which are of a specific MediaType and
  157. * which belong to this JitsiParticipant are muted.
  158. *
  159. * @param {MediaType} mediaType - The MediaType of the JitsiTracks to be
  160. * checked.
  161. * @private
  162. * @returns {Boolean} True if all JitsiTracks which are of the specified
  163. * mediaType and which belong to this JitsiParticipant are muted; otherwise,
  164. * false.
  165. */
  166. _isMediaTypeMuted(mediaType) {
  167. return this.getTracks().reduce(
  168. (muted, track) =>
  169. muted && (track.getType() !== mediaType || track.isMuted()),
  170. true);
  171. }
  172. /**
  173. * @returns {Boolean} Whether this participant has muted their video.
  174. */
  175. isVideoMuted() {
  176. return this._isMediaTypeMuted(MediaType.VIDEO);
  177. }
  178. /**
  179. * @returns {String} The role of this participant.
  180. */
  181. getRole() {
  182. return this._role;
  183. }
  184. /**
  185. *
  186. */
  187. supportsDTMF() {
  188. return this._supportsDTMF;
  189. }
  190. /**
  191. * Returns a set with the features for the participant.
  192. * @param {int} timeout the timeout in ms for reply from the participant.
  193. * @returns {Promise<Set<String>, Error>}
  194. */
  195. getFeatures(timeout = 5000) {
  196. return this._conference.xmpp.caps.getFeatures(this._jid, timeout);
  197. }
  198. }