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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. /**
  42. * Determines whether all JitsiTracks which are of a specific MediaType and which belong to this
  43. * JitsiParticipant are muted.
  44. *
  45. * @param {MediaType} mediaType - The MediaType of the JitsiTracks to be checked.
  46. * @private
  47. * @returns {Boolean} True if all JitsiTracks which are of the specified mediaType and which belong to this
  48. * JitsiParticipant are muted; otherwise, false.
  49. */
  50. _isMediaTypeMuted(mediaType) {
  51. return this.getTracks().reduce(
  52. (muted, track) =>
  53. muted && (track.getType() !== mediaType || track.isMuted()),
  54. true);
  55. }
  56. /**
  57. * Returns the bot type for the participant.
  58. *
  59. * @returns {string|undefined} - The bot type of the participant.
  60. */
  61. getBotType() {
  62. return this._botType;
  63. }
  64. /**
  65. * @returns {JitsiConference} The conference that this participant belongs
  66. * to.
  67. */
  68. getConference() {
  69. return this._conference;
  70. }
  71. /**
  72. * Returns the connection jid for the participant.
  73. *
  74. * @returns {string|undefined} - The connection jid of the participant.
  75. */
  76. getConnectionJid() {
  77. return this._connectionJid;
  78. }
  79. /**
  80. * @returns {String} The human-readable display name of this participant.
  81. */
  82. getDisplayName() {
  83. return this._displayName;
  84. }
  85. /**
  86. * Returns a set with the features for the participant.
  87. * @returns {Promise<Set<String>, Error>}
  88. */
  89. getFeatures() {
  90. return Promise.resolve(this._features);
  91. }
  92. /**
  93. * @returns {String} The ID of this participant.
  94. */
  95. getId() {
  96. return this._id;
  97. }
  98. /**
  99. * @returns {String} The JID of this participant.
  100. */
  101. getJid() {
  102. return this._jid;
  103. }
  104. /**
  105. * Gets the value of a property of this participant.
  106. */
  107. getProperty(name) {
  108. return this._properties[name];
  109. }
  110. /**
  111. * @returns {String} The role of this participant.
  112. */
  113. getRole() {
  114. return this._role;
  115. }
  116. /**
  117. * @returns {String} The stats ID of this participant.
  118. */
  119. getStatsID() {
  120. return this._statsID;
  121. }
  122. /**
  123. * @returns {String} The status of the participant.
  124. */
  125. getStatus() {
  126. return this._status;
  127. }
  128. /**
  129. * @returns {Array.<JitsiTrack>} The list of media tracks for this
  130. * participant.
  131. */
  132. getTracks() {
  133. return this._tracks.slice();
  134. }
  135. /**
  136. * @param {MediaType} mediaType
  137. * @returns {Array.<JitsiTrack>} an array of media tracks for this
  138. * participant, for given media type.
  139. */
  140. getTracksByMediaType(mediaType) {
  141. return this.getTracks().filter(track => track.getType() === mediaType);
  142. }
  143. /**
  144. * Checks current set features.
  145. * @param {String} feature - the feature to check.
  146. * @return {boolean} <tt>true</tt> if this <tt>participant</tt> contains the
  147. * <tt>feature</tt>.
  148. */
  149. hasFeature(feature) {
  150. return this._features.has(feature);
  151. }
  152. /**
  153. * @returns {Boolean} Whether this participant has muted their audio.
  154. */
  155. isAudioMuted() {
  156. return this._isMediaTypeMuted(MediaType.AUDIO);
  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 is a hidden participant. Some
  168. * special system participants may want to join hidden (like for example the
  169. * recorder).
  170. */
  171. isHiddenFromRecorder() {
  172. return this._identity?.user?.['hidden-from-recorder'] === 'true';
  173. }
  174. /**
  175. * @returns {Boolean} Whether this participant is a moderator or not.
  176. */
  177. isModerator() {
  178. return this._role === 'moderator';
  179. }
  180. /**
  181. * @returns {Boolean} Wheter this participants will be replaced by another
  182. * participant in the meeting.
  183. */
  184. isReplaced() {
  185. return this._isReplaced;
  186. }
  187. /**
  188. * @returns {Boolean} Whether this participant replaces another participant
  189. * from the meeting.
  190. */
  191. isReplacing() {
  192. return this._isReplacing;
  193. }
  194. /**
  195. * @returns {Boolean} Whether this participant has muted their video.
  196. */
  197. isVideoMuted() {
  198. return this._isMediaTypeMuted(MediaType.VIDEO);
  199. }
  200. /**
  201. * Sets the bot type for the participant.
  202. * @param {String} newBotType - The new bot type to set.
  203. */
  204. setBotType(newBotType) {
  205. this._botType = newBotType;
  206. }
  207. /**
  208. * Sets the connection jid for the participant.
  209. * @param {String} newJid - The connection jid to set.
  210. */
  211. setConnectionJid(newJid) {
  212. this._connectionJid = newJid;
  213. }
  214. /**
  215. * Set new features.
  216. * @param {Set<String>|undefined} newFeatures - Sets new features.
  217. */
  218. setFeatures(newFeatures) {
  219. this._features = newFeatures || new Set();
  220. }
  221. /**
  222. * Sets whether participant is being replaced by another based on jwt.
  223. * @param {boolean} newIsReplaced - whether is being replaced.
  224. */
  225. setIsReplaced(newIsReplaced) {
  226. this._isReplaced = newIsReplaced;
  227. }
  228. /**
  229. * Sets whether participant is replacing another based on jwt.
  230. * @param {String} newIsReplacing - whether is replacing.
  231. */
  232. setIsReplacing(newIsReplacing) {
  233. this._isReplacing = newIsReplacing;
  234. }
  235. /**
  236. * Sets the value of a property of this participant, and fires an event if
  237. * the value has changed.
  238. * @name the name of the property.
  239. * @value the value to set.
  240. */
  241. setProperty(name, value) {
  242. const oldValue = this._properties[name];
  243. if (value !== oldValue) {
  244. this._properties[name] = value;
  245. this._conference.eventEmitter.emit(
  246. JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
  247. this,
  248. name,
  249. oldValue,
  250. value);
  251. }
  252. }
  253. /**
  254. * Sets a new participant role.
  255. * @param {String} newRole - the new role.
  256. */
  257. setRole(newRole) {
  258. this._role = newRole;
  259. }
  260. /**
  261. *
  262. */
  263. supportsDTMF() {
  264. return this._supportsDTMF;
  265. }
  266. }