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

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