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.4KB

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