Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

JitsiParticipant.js 5.8KB

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