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

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