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

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