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

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