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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. import { Strophe } from 'strophe.js';
  2. import * as JitsiConferenceEvents from './JitsiConferenceEvents';
  3. import { 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. * @param {string} statsID - optional participant statsID
  19. * @param {string} status - the initial status if any.
  20. * @param {object} identity - the xmpp identity
  21. * @param {boolean?} isReplacing - whether this is a participant replacing another into the meeting.
  22. * @param {boolean?} isReplaced - whether this is a participant to be kicked and replaced into the meeting.
  23. */
  24. constructor(jid, conference, displayName, hidden, statsID, status, identity, isReplacing, isReplaced) {
  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._properties = {};
  36. this._identity = identity;
  37. this._isReplacing = isReplacing;
  38. this._isReplaced = isReplaced;
  39. this._features = new Set();
  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. * Sets the value of a property of this participant, and fires an event if
  72. * the value has changed.
  73. * @name the name of the property.
  74. * @value the value to set.
  75. */
  76. setProperty(name, value) {
  77. const oldValue = this._properties[name];
  78. if (value !== oldValue) {
  79. this._properties[name] = value;
  80. this._conference.eventEmitter.emit(
  81. JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
  82. this,
  83. name,
  84. oldValue,
  85. value);
  86. }
  87. }
  88. /**
  89. * @returns {Array.<JitsiTrack>} The list of media tracks for this
  90. * participant.
  91. */
  92. getTracks() {
  93. return this._tracks.slice();
  94. }
  95. /**
  96. * @param {MediaType} mediaType
  97. * @returns {Array.<JitsiTrack>} an array of media tracks for this
  98. * participant, for given media type.
  99. */
  100. getTracksByMediaType(mediaType) {
  101. return this.getTracks().filter(track => track.getType() === mediaType);
  102. }
  103. /**
  104. * @returns {String} The ID of this participant.
  105. */
  106. getId() {
  107. return this._id;
  108. }
  109. /**
  110. * @returns {String} The JID of this participant.
  111. */
  112. getJid() {
  113. return this._jid;
  114. }
  115. /**
  116. * @returns {String} The human-readable display name of this participant.
  117. */
  118. getDisplayName() {
  119. return this._displayName;
  120. }
  121. /**
  122. * @returns {String} The stats ID of this participant.
  123. */
  124. getStatsID() {
  125. return this._statsID;
  126. }
  127. /**
  128. * @returns {String} The status of the participant.
  129. */
  130. getStatus() {
  131. return this._status;
  132. }
  133. /**
  134. * @returns {Boolean} Whether this participant is a moderator or not.
  135. */
  136. isModerator() {
  137. return this._role === 'moderator';
  138. }
  139. /**
  140. * @returns {Boolean} Whether this participant is a hidden participant. Some
  141. * special system participants may want to join hidden (like for example the
  142. * recorder).
  143. */
  144. isHidden() {
  145. return this._hidden;
  146. }
  147. /**
  148. * @returns {Boolean} Whether this participant is a hidden participant. Some
  149. * special system participants may want to join hidden (like for example the
  150. * recorder).
  151. */
  152. isHiddenFromRecorder() {
  153. return this._identity?.user?.['hidden-from-recorder'] === 'true';
  154. }
  155. /**
  156. * @returns {Boolean} Whether this participant replaces another participant
  157. * from the meeting.
  158. */
  159. isReplacing() {
  160. return this._isReplacing;
  161. }
  162. /**
  163. * @returns {Boolean} Wheter this participants will be replaced by another
  164. * participant in the meeting.
  165. */
  166. isReplaced() {
  167. return this._isReplaced;
  168. }
  169. /**
  170. * @returns {Boolean} Whether this participant has muted their audio.
  171. */
  172. isAudioMuted() {
  173. return this._isMediaTypeMuted(MediaType.AUDIO);
  174. }
  175. /**
  176. * Determines whether all JitsiTracks which are of a specific MediaType and
  177. * which belong to this JitsiParticipant are muted.
  178. *
  179. * @param {MediaType} mediaType - The MediaType of the JitsiTracks to be
  180. * checked.
  181. * @private
  182. * @returns {Boolean} True if all JitsiTracks which are of the specified
  183. * mediaType and which belong to this JitsiParticipant are muted; otherwise,
  184. * false.
  185. */
  186. _isMediaTypeMuted(mediaType) {
  187. return this.getTracks().reduce(
  188. (muted, track) =>
  189. muted && (track.getType() !== mediaType || track.isMuted()),
  190. true);
  191. }
  192. /**
  193. * @returns {Boolean} Whether this participant has muted their video.
  194. */
  195. isVideoMuted() {
  196. return this._isMediaTypeMuted(MediaType.VIDEO);
  197. }
  198. /**
  199. * @returns {String} The role of this participant.
  200. */
  201. getRole() {
  202. return this._role;
  203. }
  204. /**
  205. * Sets a new participant role.
  206. * @param {String} newRole - the new role.
  207. */
  208. setRole(newRole) {
  209. this._role = newRole;
  210. }
  211. /**
  212. * Sets whether participant is replacing another based on jwt.
  213. * @param {String} newIsReplacing - whether is replacing.
  214. */
  215. setIsReplacing(newIsReplacing) {
  216. this._isReplacing = newIsReplacing;
  217. }
  218. /**
  219. * Sets whether participant is being replaced by another based on jwt.
  220. * @param {boolean} newIsReplaced - whether is being replaced.
  221. */
  222. setIsReplaced(newIsReplaced) {
  223. this._isReplaced = newIsReplaced;
  224. }
  225. /**
  226. *
  227. */
  228. supportsDTMF() {
  229. return this._supportsDTMF;
  230. }
  231. /**
  232. * Returns a set with the features for the participant.
  233. * @returns {Promise<Set<String>, Error>}
  234. */
  235. getFeatures() {
  236. return Promise.resolve(this._features);
  237. }
  238. /**
  239. * Checks current set features.
  240. * @param {String} feature - the feature to check.
  241. * @return {boolean} <tt>true</tt> if this <tt>participant</tt> contains the
  242. * <tt>feature</tt>.
  243. */
  244. hasFeature(feature) {
  245. return this._features.has(feature);
  246. }
  247. /**
  248. * Set new features.
  249. * @param {Set<String>|undefined} newFeatures - Sets new features.
  250. */
  251. setFeatures(newFeatures) {
  252. this._features = newFeatures || new Set();
  253. }
  254. /**
  255. * Returns the bot type for the participant.
  256. *
  257. * @returns {string|undefined} - The bot type of the participant.
  258. */
  259. getBotType() {
  260. return this._botType;
  261. }
  262. /**
  263. * Sets the bot type for the participant.
  264. * @param {String} newBotType - The new bot type to set.
  265. */
  266. setBotType(newBotType) {
  267. this._botType = newBotType;
  268. }
  269. /**
  270. * Returns the connection jid for the participant.
  271. *
  272. * @returns {string|undefined} - The connection jid of the participant.
  273. */
  274. getConnectionJid() {
  275. return this._connectionJid;
  276. }
  277. /**
  278. * Sets the connection jid for the participant.
  279. * @param {String} newJid - The connection jid to set.
  280. */
  281. setConnectionJid(newJid) {
  282. this._connectionJid = newJid;
  283. }
  284. }