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

JitsiParticipant.js 8.6KB

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