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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. */
  23. constructor(jid, conference, displayName, hidden, statsID, status) {
  24. this._jid = jid;
  25. this._id = Strophe.getResourceFromJid(jid);
  26. this._conference = conference;
  27. this._displayName = displayName;
  28. this._supportsDTMF = false;
  29. this._tracks = [];
  30. this._role = 'none';
  31. this._status = status;
  32. this._availableDevices = {
  33. audio: undefined,
  34. video: undefined
  35. };
  36. this._hidden = hidden;
  37. this._statsID = statsID;
  38. this._connectionStatus = ParticipantConnectionStatus.ACTIVE;
  39. this._properties = {};
  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. // Gets a link to an etherpad instance advertised by the participant?
  167. // getEtherpad() {
  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. *
  206. */
  207. supportsDTMF() {
  208. return this._supportsDTMF;
  209. }
  210. /**
  211. * Returns a set with the features for the participant.
  212. * @param {int} timeout the timeout in ms for reply from the participant.
  213. * @returns {Promise<Set<String>, Error>}
  214. */
  215. getFeatures(timeout = 5000) {
  216. return this._conference.xmpp.caps.getFeatures(this._jid, timeout);
  217. }
  218. }