您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

JitsiParticipant.js 6.0KB

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