modified lib-jitsi-meet dev repo
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 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. import { Strophe } from 'strophe.js';
  2. import * as JitsiConferenceEvents from './JitsiConferenceEvents';
  3. import { 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. /* eslint-disable max-params */
  9. /**
  10. * Initializes a new JitsiParticipant instance.
  11. *
  12. * @constructor
  13. * @param jid the conference XMPP jid
  14. * @param conference
  15. * @param displayName
  16. * @param {Boolean} hidden - True if the new JitsiParticipant instance is to
  17. * represent a hidden participant; otherwise, false.
  18. * @param {string} statsID - optional participant statsID
  19. * @param {string} status - the initial status if any.
  20. * @param {object} identity - the xmpp identity
  21. * @param {boolean?} isReplacing - whether this is a participant replacing another into the meeting.
  22. * @param {boolean?} isReplaced - whether this is a participant to be kicked and replaced into the meeting.
  23. */
  24. constructor(jid, conference, displayName, hidden, statsID, status, identity, isReplacing, isReplaced) {
  25. this._jid = jid;
  26. this._id = Strophe.getResourceFromJid(jid);
  27. this._conference = conference;
  28. this._displayName = displayName;
  29. this._supportsDTMF = false;
  30. this._tracks = [];
  31. this._role = 'none';
  32. this._status = status;
  33. this._hidden = hidden;
  34. this._statsID = statsID;
  35. this._properties = {};
  36. this._identity = identity;
  37. this._isReplacing = isReplacing;
  38. this._isReplaced = isReplaced;
  39. this._features = new Set();
  40. /**
  41. * Remote sources associated with the participant in the following format.
  42. * Map<mediaType, Map<sourceName, sourceInfo>>
  43. *
  44. * mediaType - 'audio' or 'video'.
  45. * sourceName - name of the remote source.
  46. * sourceInfo: {
  47. * muted: boolean;
  48. * videoType: string;
  49. * }
  50. */
  51. this._sources = new Map();
  52. }
  53. /**
  54. * Determines whether all JitsiTracks which are of a specific MediaType and which belong to this
  55. * JitsiParticipant are muted.
  56. *
  57. * @param {MediaType} mediaType - The MediaType of the JitsiTracks to be checked.
  58. * @private
  59. * @returns {Boolean} True if all JitsiTracks which are of the specified mediaType and which belong to this
  60. * JitsiParticipant are muted; otherwise, false.
  61. */
  62. _isMediaTypeMuted(mediaType) {
  63. return this.getTracks().reduce(
  64. (muted, track) =>
  65. muted && (track.getType() !== mediaType || track.isMuted()),
  66. true);
  67. }
  68. /**
  69. * Sets source info.
  70. * @param {MediaType} mediaType The media type, 'audio' or 'video'.
  71. * @param {boolean} muted The new muted state.
  72. * @param {string} sourceName The name of the source.
  73. * @param {string} videoType The video type of the source.
  74. * @returns {void}
  75. */
  76. _setSources(mediaType, muted, sourceName, videoType) {
  77. let sourceByMediaType = this._sources.get(mediaType);
  78. const sourceInfo = {
  79. muted,
  80. videoType
  81. };
  82. if (sourceByMediaType?.size) {
  83. sourceByMediaType.set(sourceName, sourceInfo);
  84. return;
  85. }
  86. sourceByMediaType = new Map();
  87. sourceByMediaType.set(sourceName, sourceInfo);
  88. this._sources.set(mediaType, sourceByMediaType);
  89. }
  90. /**
  91. * Returns the bot type for the participant.
  92. *
  93. * @returns {string|undefined} - The bot type of the participant.
  94. */
  95. getBotType() {
  96. return this._botType;
  97. }
  98. /**
  99. * @returns {JitsiConference} The conference that this participant belongs
  100. * to.
  101. */
  102. getConference() {
  103. return this._conference;
  104. }
  105. /**
  106. * Returns the connection jid for the participant.
  107. *
  108. * @returns {string|undefined} - The connection jid of the participant.
  109. */
  110. getConnectionJid() {
  111. return this._connectionJid;
  112. }
  113. /**
  114. * @returns {String} The human-readable display name of this participant.
  115. */
  116. getDisplayName() {
  117. return this._displayName;
  118. }
  119. /**
  120. * Returns a set with the features for the participant.
  121. * @returns {Promise<Set<String>, Error>}
  122. */
  123. getFeatures() {
  124. return Promise.resolve(this._features);
  125. }
  126. /**
  127. * @returns {String} The ID of this participant.
  128. */
  129. getId() {
  130. return this._id;
  131. }
  132. /**
  133. * @returns {String} The JID of this participant.
  134. */
  135. getJid() {
  136. return this._jid;
  137. }
  138. /**
  139. * Gets the value of a property of this participant.
  140. */
  141. getProperty(name) {
  142. return this._properties[name];
  143. }
  144. /**
  145. * @returns {String} The role of this participant.
  146. */
  147. getRole() {
  148. return this._role;
  149. }
  150. /**
  151. * Returns the sources associated with this participant.
  152. * @returns Map<string, Map<string, Object>>
  153. */
  154. getSources() {
  155. return this._sources;
  156. }
  157. /**
  158. * @returns {String} The stats ID of this participant.
  159. */
  160. getStatsID() {
  161. return this._statsID;
  162. }
  163. /**
  164. * @returns {String} The status of the participant.
  165. */
  166. getStatus() {
  167. return this._status;
  168. }
  169. /**
  170. * @returns {Array.<JitsiTrack>} The list of media tracks for this
  171. * participant.
  172. */
  173. getTracks() {
  174. return this._tracks.slice();
  175. }
  176. /**
  177. * @param {MediaType} mediaType
  178. * @returns {Array.<JitsiTrack>} an array of media tracks for this
  179. * participant, for given media type.
  180. */
  181. getTracksByMediaType(mediaType) {
  182. return this.getTracks().filter(track => track.getType() === mediaType);
  183. }
  184. /**
  185. * Checks current set features.
  186. * @param {String} feature - the feature to check.
  187. * @return {boolean} <tt>true</tt> if this <tt>participant</tt> contains the
  188. * <tt>feature</tt>.
  189. */
  190. hasFeature(feature) {
  191. return this._features.has(feature);
  192. }
  193. /**
  194. * @returns {Boolean} Whether this participant has muted their audio.
  195. */
  196. isAudioMuted() {
  197. return this._isMediaTypeMuted(MediaType.AUDIO);
  198. }
  199. /**
  200. * @returns {Boolean} Whether this participant is a hidden participant. Some
  201. * special system participants may want to join hidden (like for example the
  202. * recorder).
  203. */
  204. isHidden() {
  205. return this._hidden;
  206. }
  207. /**
  208. * @returns {Boolean} Whether this participant is a hidden participant. Some
  209. * special system participants may want to join hidden (like for example the
  210. * recorder).
  211. */
  212. isHiddenFromRecorder() {
  213. return this._identity?.user?.['hidden-from-recorder'] === 'true';
  214. }
  215. /**
  216. * @returns {Boolean} Whether this participant is a moderator or not.
  217. */
  218. isModerator() {
  219. return this._role === 'moderator';
  220. }
  221. /**
  222. * @returns {Boolean} Wheter this participants will be replaced by another
  223. * participant in the meeting.
  224. */
  225. isReplaced() {
  226. return this._isReplaced;
  227. }
  228. /**
  229. * @returns {Boolean} Whether this participant replaces another participant
  230. * from the meeting.
  231. */
  232. isReplacing() {
  233. return this._isReplacing;
  234. }
  235. /**
  236. * @returns {Boolean} Whether this participant has muted their video.
  237. */
  238. isVideoMuted() {
  239. return this._isMediaTypeMuted(MediaType.VIDEO);
  240. }
  241. /**
  242. * Sets the bot type for the participant.
  243. * @param {String} newBotType - The new bot type to set.
  244. */
  245. setBotType(newBotType) {
  246. this._botType = newBotType;
  247. }
  248. /**
  249. * Sets the connection jid for the participant.
  250. * @param {String} newJid - The connection jid to set.
  251. */
  252. setConnectionJid(newJid) {
  253. this._connectionJid = newJid;
  254. }
  255. /**
  256. * Set new features.
  257. * @param {Set<String>|undefined} newFeatures - Sets new features.
  258. */
  259. setFeatures(newFeatures) {
  260. this._features = newFeatures || new Set();
  261. }
  262. /**
  263. * Sets whether participant is being replaced by another based on jwt.
  264. * @param {boolean} newIsReplaced - whether is being replaced.
  265. */
  266. setIsReplaced(newIsReplaced) {
  267. this._isReplaced = newIsReplaced;
  268. }
  269. /**
  270. * Sets whether participant is replacing another based on jwt.
  271. * @param {String} newIsReplacing - whether is replacing.
  272. */
  273. setIsReplacing(newIsReplacing) {
  274. this._isReplacing = newIsReplacing;
  275. }
  276. /**
  277. * Sets the value of a property of this participant, and fires an event if
  278. * the value has changed.
  279. * @name the name of the property.
  280. * @value the value to set.
  281. */
  282. setProperty(name, value) {
  283. const oldValue = this._properties[name];
  284. if (value !== oldValue) {
  285. this._properties[name] = value;
  286. this._conference.eventEmitter.emit(
  287. JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
  288. this,
  289. name,
  290. oldValue,
  291. value);
  292. }
  293. }
  294. /**
  295. * Sets a new participant role.
  296. * @param {String} newRole - the new role.
  297. */
  298. setRole(newRole) {
  299. this._role = newRole;
  300. }
  301. /**
  302. *
  303. */
  304. supportsDTMF() {
  305. return this._supportsDTMF;
  306. }
  307. }