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

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