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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 this.getTracks().some(function(jitsiTrack) {
  58. return jitsiTrack.getType() === MediaType.VIDEO
  59. && jitsiTrack.isWebRTCTrackMuted();
  60. });
  61. }
  62. /**
  63. * Updates participant's connection status.
  64. * @param {boolean} isActive true if the user's connection is fine or false
  65. * when the user is having connectivity issues.
  66. * @private
  67. */
  68. _setIsConnectionActive(isActive) {
  69. this._isConnectionActive = isActive;
  70. }
  71. /**
  72. * Checks participant's connectivity status.
  73. *
  74. * @returns {boolean} true if the connection is currently ok or false when
  75. * the user is having connectivity issues.
  76. */
  77. isConnectionActive() {
  78. return this._isConnectionActive;
  79. }
  80. /**
  81. * Sets the value of a property of this participant, and fires an event if
  82. * the value has changed.
  83. * @name the name of the property.
  84. * @value the value to set.
  85. */
  86. setProperty(name, value) {
  87. var oldValue = this._properties[name];
  88. if (value !== oldValue) {
  89. this._properties[name] = value;
  90. this._conference.eventEmitter.emit(
  91. JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
  92. this,
  93. name,
  94. oldValue,
  95. value);
  96. }
  97. }
  98. /**
  99. * @returns {Array.<JitsiTrack>} The list of media tracks for this
  100. * participant.
  101. */
  102. getTracks() {
  103. return this._tracks.slice();
  104. }
  105. /**
  106. * @returns {String} The ID of this participant.
  107. */
  108. getId() {
  109. return this._id;
  110. }
  111. /**
  112. * @returns {String} The JID of this participant.
  113. */
  114. getJid() {
  115. return this._jid;
  116. }
  117. /**
  118. * @returns {String} The human-readable display name of this participant.
  119. */
  120. getDisplayName() {
  121. return this._displayName;
  122. }
  123. /**
  124. * @returns {String} The status of the participant.
  125. */
  126. getStatus () {
  127. return this._status;
  128. }
  129. /**
  130. * @returns {Boolean} Whether this participant is a moderator or not.
  131. */
  132. isModerator() {
  133. return this._role === 'moderator';
  134. }
  135. /**
  136. * @returns {Boolean} Whether this participant is a hidden participant. Some
  137. * special system participants may want to join hidden (like for example the
  138. * recorder).
  139. */
  140. isHidden() {
  141. return this._hidden;
  142. }
  143. // Gets a link to an etherpad instance advertised by the participant?
  144. //getEtherpad() {
  145. //}
  146. /**
  147. * @returns {Boolean} Whether this participant has muted their audio.
  148. */
  149. isAudioMuted() {
  150. return this._isMediaTypeMuted(MediaType.AUDIO);
  151. }
  152. /**
  153. * Determines whether all JitsiTracks which are of a specific MediaType and
  154. * which belong to this JitsiParticipant are muted.
  155. *
  156. * @param {MediaType} mediaType - The MediaType of the JitsiTracks to be
  157. * checked.
  158. * @private
  159. * @returns {Boolean} True if all JitsiTracks which are of the specified
  160. * mediaType and which belong to this JitsiParticipant are muted; otherwise,
  161. * false.
  162. */
  163. _isMediaTypeMuted(mediaType) {
  164. return this.getTracks().reduce(
  165. (muted, track) =>
  166. muted && (track.getType() !== mediaType || track.isMuted()),
  167. true);
  168. }
  169. /**
  170. * @returns {Boolean} Whether this participant has muted their video.
  171. */
  172. isVideoMuted() {
  173. return this._isMediaTypeMuted(MediaType.VIDEO);
  174. }
  175. /**
  176. * @returns {???} The latest statistics reported by this participant (i.e.
  177. * info used to populate the GSM bars)
  178. * TODO: do we expose this or handle it internally?
  179. */
  180. getLatestStats() {
  181. }
  182. /**
  183. * @returns {String} The role of this participant.
  184. */
  185. getRole() {
  186. return this._role;
  187. }
  188. /**
  189. * @returns {Boolean} Whether this participant is the conference focus (i.e.
  190. * jicofo).
  191. */
  192. isFocus() {
  193. }
  194. /**
  195. * @returns {Boolean} Whether this participant is a conference recorder
  196. * (i.e. jirecon).
  197. */
  198. isRecorder() {
  199. }
  200. /**
  201. * @returns {Boolean} Whether this participant is a SIP gateway (i.e.
  202. * jigasi).
  203. */
  204. isSipGateway() {
  205. }
  206. /**
  207. * @returns {Boolean} Whether this participant is currently sharing their
  208. * screen.
  209. */
  210. isScreenSharing() {
  211. }
  212. /**
  213. * @returns {String} The user agent of this participant (i.e. browser
  214. * userAgent string).
  215. */
  216. getUserAgent() {
  217. }
  218. /**
  219. * Kicks the participant from the conference (requires certain privileges).
  220. */
  221. kick() {
  222. }
  223. /**
  224. * Asks this participant to mute themselves.
  225. */
  226. askToMute() {
  227. }
  228. supportsDTMF() {
  229. return this._supportsDTMF;
  230. }
  231. /**
  232. * Returns a set with the features for the participant.
  233. * @param {int} timeout the timeout in ms for reply from the participant.
  234. * @returns {Promise<Set<String>, Error>}
  235. */
  236. getFeatures(timeout = 5000) {
  237. return this._conference.xmpp.caps.getFeatures(this._jid, timeout);
  238. }
  239. }