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.

JitsiConferenceEventManager.js 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /* global __filename */
  2. import { Strophe } from 'strophe.js';
  3. import {
  4. ACTION_JINGLE_SA_TIMEOUT,
  5. createBridgeDownEvent,
  6. createConnectionStageReachedEvent,
  7. createFocusLeftEvent,
  8. createJingleEvent,
  9. createRemotelyMutedEvent
  10. } from './service/statistics/AnalyticsEvents';
  11. import AuthenticationEvents
  12. from './service/authentication/AuthenticationEvents';
  13. import EventEmitterForwarder from './modules/util/EventEmitterForwarder';
  14. import { getLogger } from 'jitsi-meet-logger';
  15. import * as JitsiConferenceErrors from './JitsiConferenceErrors';
  16. import * as JitsiConferenceEvents from './JitsiConferenceEvents';
  17. import * as MediaType from './service/RTC/MediaType';
  18. import RTCEvents from './service/RTC/RTCEvents';
  19. import VideoType from './service/RTC/VideoType';
  20. import Statistics from './modules/statistics/statistics';
  21. import XMPPEvents from './service/xmpp/XMPPEvents';
  22. const logger = getLogger(__filename);
  23. /**
  24. * Setups all event listeners related to conference
  25. * @param conference {JitsiConference} the conference
  26. */
  27. export default function JitsiConferenceEventManager(conference) {
  28. this.conference = conference;
  29. // Listeners related to the conference only
  30. conference.on(JitsiConferenceEvents.TRACK_MUTE_CHANGED,
  31. track => {
  32. if (!track.isLocal() || !conference.statistics) {
  33. return;
  34. }
  35. const session
  36. = track.isP2P
  37. ? conference.p2pJingleSession : conference.jvbJingleSession;
  38. // TPC will be null, before the conference starts, but the event
  39. // still should be queued
  40. const tpc = (session && session.peerconnection) || null;
  41. conference.statistics.sendMuteEvent(
  42. tpc,
  43. track.isMuted(),
  44. track.getType());
  45. });
  46. }
  47. /**
  48. * Setups event listeners related to conference.chatRoom
  49. */
  50. JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
  51. const conference = this.conference;
  52. const chatRoom = conference.room;
  53. this.chatRoomForwarder = new EventEmitterForwarder(chatRoom,
  54. this.conference.eventEmitter);
  55. chatRoom.addListener(XMPPEvents.ICE_RESTARTING, jingleSession => {
  56. if (!jingleSession.isP2P) {
  57. // If using DataChannel as bridge channel, it must be closed
  58. // before ICE restart, otherwise Chrome will not trigger "opened"
  59. // event for the channel established with the new bridge.
  60. // TODO: This may be bypassed when using a WebSocket as bridge
  61. // channel.
  62. conference.rtc.closeBridgeChannel();
  63. }
  64. // else: there are no DataChannels in P2P session (at least for now)
  65. });
  66. chatRoom.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
  67. () => {
  68. // TODO: Add a way to differentiate between commands which caused
  69. // us to mute and those that did not change our state (i.e. we were
  70. // already muted).
  71. Statistics.sendAnalytics(createRemotelyMutedEvent());
  72. // set isMutedByFocus when setAudioMute Promise ends
  73. conference.rtc.setAudioMute(true).then(
  74. () => {
  75. conference.isMutedByFocus = true;
  76. },
  77. () =>
  78. logger.warn(
  79. 'Error while audio muting due to focus request'));
  80. }
  81. );
  82. this.chatRoomForwarder.forward(XMPPEvents.SUBJECT_CHANGED,
  83. JitsiConferenceEvents.SUBJECT_CHANGED);
  84. this.chatRoomForwarder.forward(XMPPEvents.MUC_JOINED,
  85. JitsiConferenceEvents.CONFERENCE_JOINED);
  86. // send some analytics events
  87. chatRoom.addListener(XMPPEvents.MUC_JOINED,
  88. () => {
  89. this.conference.isJvbConnectionInterrupted = false;
  90. // TODO: Move all of the 'connectionTimes' logic to its own module.
  91. Object.keys(chatRoom.connectionTimes).forEach(key => {
  92. const event
  93. = createConnectionStageReachedEvent(
  94. `conference_${key}`,
  95. { value: chatRoom.connectionTimes[key] });
  96. Statistics.sendAnalytics(event);
  97. });
  98. // TODO: Move all of the 'connectionTimes' logic to its own module.
  99. Object.keys(chatRoom.xmpp.connectionTimes).forEach(key => {
  100. const event
  101. = createConnectionStageReachedEvent(
  102. `xmpp_${key}`,
  103. { value: chatRoom.xmpp.connectionTimes[key] });
  104. Statistics.sendAnalytics(event);
  105. });
  106. });
  107. this.chatRoomForwarder.forward(XMPPEvents.ROOM_JOIN_ERROR,
  108. JitsiConferenceEvents.CONFERENCE_FAILED,
  109. JitsiConferenceErrors.CONNECTION_ERROR);
  110. this.chatRoomForwarder.forward(XMPPEvents.ROOM_CONNECT_ERROR,
  111. JitsiConferenceEvents.CONFERENCE_FAILED,
  112. JitsiConferenceErrors.CONNECTION_ERROR);
  113. this.chatRoomForwarder.forward(XMPPEvents.ROOM_CONNECT_NOT_ALLOWED_ERROR,
  114. JitsiConferenceEvents.CONFERENCE_FAILED,
  115. JitsiConferenceErrors.NOT_ALLOWED_ERROR);
  116. this.chatRoomForwarder.forward(XMPPEvents.ROOM_MAX_USERS_ERROR,
  117. JitsiConferenceEvents.CONFERENCE_FAILED,
  118. JitsiConferenceErrors.CONFERENCE_MAX_USERS);
  119. this.chatRoomForwarder.forward(XMPPEvents.PASSWORD_REQUIRED,
  120. JitsiConferenceEvents.CONFERENCE_FAILED,
  121. JitsiConferenceErrors.PASSWORD_REQUIRED);
  122. this.chatRoomForwarder.forward(XMPPEvents.AUTHENTICATION_REQUIRED,
  123. JitsiConferenceEvents.CONFERENCE_FAILED,
  124. JitsiConferenceErrors.AUTHENTICATION_REQUIRED);
  125. this.chatRoomForwarder.forward(XMPPEvents.BRIDGE_DOWN,
  126. JitsiConferenceEvents.CONFERENCE_FAILED,
  127. JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE);
  128. chatRoom.addListener(
  129. XMPPEvents.BRIDGE_DOWN,
  130. () => Statistics.sendAnalytics(createBridgeDownEvent()));
  131. this.chatRoomForwarder.forward(XMPPEvents.RESERVATION_ERROR,
  132. JitsiConferenceEvents.CONFERENCE_FAILED,
  133. JitsiConferenceErrors.RESERVATION_ERROR);
  134. this.chatRoomForwarder.forward(XMPPEvents.GRACEFUL_SHUTDOWN,
  135. JitsiConferenceEvents.CONFERENCE_FAILED,
  136. JitsiConferenceErrors.GRACEFUL_SHUTDOWN);
  137. chatRoom.addListener(XMPPEvents.JINGLE_FATAL_ERROR,
  138. (session, error) => {
  139. if (!session.isP2P) {
  140. conference.eventEmitter.emit(
  141. JitsiConferenceEvents.CONFERENCE_FAILED,
  142. JitsiConferenceErrors.JINGLE_FATAL_ERROR, error);
  143. }
  144. });
  145. chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
  146. jingleSession => {
  147. conference._onIceConnectionFailed(jingleSession);
  148. });
  149. this.chatRoomForwarder.forward(XMPPEvents.MUC_DESTROYED,
  150. JitsiConferenceEvents.CONFERENCE_FAILED,
  151. JitsiConferenceErrors.CONFERENCE_DESTROYED);
  152. this.chatRoomForwarder.forward(XMPPEvents.CHAT_ERROR_RECEIVED,
  153. JitsiConferenceEvents.CONFERENCE_ERROR,
  154. JitsiConferenceErrors.CHAT_ERROR);
  155. this.chatRoomForwarder.forward(XMPPEvents.FOCUS_DISCONNECTED,
  156. JitsiConferenceEvents.CONFERENCE_FAILED,
  157. JitsiConferenceErrors.FOCUS_DISCONNECTED);
  158. chatRoom.addListener(XMPPEvents.FOCUS_LEFT,
  159. () => {
  160. Statistics.sendAnalytics(createFocusLeftEvent());
  161. conference.eventEmitter.emit(
  162. JitsiConferenceEvents.CONFERENCE_FAILED,
  163. JitsiConferenceErrors.FOCUS_LEFT);
  164. });
  165. chatRoom.addListener(XMPPEvents.SESSION_ACCEPT_TIMEOUT,
  166. jingleSession => {
  167. Statistics.sendAnalyticsAndLog(
  168. createJingleEvent(
  169. ACTION_JINGLE_SA_TIMEOUT,
  170. { p2p: jingleSession.isP2P }));
  171. });
  172. this.chatRoomForwarder.forward(XMPPEvents.RECORDER_STATE_CHANGED,
  173. JitsiConferenceEvents.RECORDER_STATE_CHANGED);
  174. this.chatRoomForwarder.forward(XMPPEvents.TRANSCRIPTION_STATUS_CHANGED,
  175. JitsiConferenceEvents.TRANSCRIPTION_STATUS_CHANGED);
  176. this.chatRoomForwarder.forward(XMPPEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED,
  177. JitsiConferenceEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED);
  178. this.chatRoomForwarder.forward(
  179. XMPPEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED,
  180. JitsiConferenceEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED);
  181. this.chatRoomForwarder.forward(XMPPEvents.PHONE_NUMBER_CHANGED,
  182. JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
  183. chatRoom.addListener(
  184. XMPPEvents.CONFERENCE_SETUP_FAILED,
  185. (jingleSession, error) => {
  186. if (!jingleSession.isP2P) {
  187. conference.eventEmitter.emit(
  188. JitsiConferenceEvents.CONFERENCE_FAILED,
  189. JitsiConferenceErrors.SETUP_FAILED,
  190. error);
  191. }
  192. });
  193. chatRoom.setParticipantPropertyListener((node, from) => {
  194. const participant = conference.getParticipantById(from);
  195. if (!participant) {
  196. return;
  197. }
  198. participant.setProperty(
  199. node.tagName.substring('jitsi_participant_'.length),
  200. node.value);
  201. });
  202. this.chatRoomForwarder.forward(XMPPEvents.KICKED,
  203. JitsiConferenceEvents.KICKED);
  204. chatRoom.addListener(XMPPEvents.KICKED,
  205. () => {
  206. conference.leave();
  207. });
  208. chatRoom.addListener(XMPPEvents.SUSPEND_DETECTED,
  209. conference.onSuspendDetected.bind(conference));
  210. this.chatRoomForwarder.forward(XMPPEvents.MUC_LOCK_CHANGED,
  211. JitsiConferenceEvents.LOCK_STATE_CHANGED);
  212. chatRoom.addListener(XMPPEvents.MUC_MEMBER_JOINED,
  213. conference.onMemberJoined.bind(conference));
  214. chatRoom.addListener(XMPPEvents.MUC_MEMBER_BOT_TYPE_CHANGED,
  215. conference._onMemberBotTypeChanged.bind(conference));
  216. chatRoom.addListener(XMPPEvents.MUC_MEMBER_LEFT,
  217. conference.onMemberLeft.bind(conference));
  218. this.chatRoomForwarder.forward(XMPPEvents.MUC_LEFT,
  219. JitsiConferenceEvents.CONFERENCE_LEFT);
  220. chatRoom.addListener(XMPPEvents.DISPLAY_NAME_CHANGED,
  221. conference.onDisplayNameChanged.bind(conference));
  222. chatRoom.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, role => {
  223. conference.onLocalRoleChanged(role);
  224. // log all events for the recorder operated by the moderator
  225. if (conference.statistics && conference.isModerator()) {
  226. conference.on(JitsiConferenceEvents.RECORDER_STATE_CHANGED,
  227. recorderSession => {
  228. const logObject = {
  229. error: recorderSession.getError(),
  230. id: 'recorder_status',
  231. status: recorderSession.getStatus()
  232. };
  233. Statistics.sendLog(JSON.stringify(logObject));
  234. });
  235. }
  236. });
  237. chatRoom.addListener(XMPPEvents.MUC_ROLE_CHANGED,
  238. conference.onUserRoleChanged.bind(conference));
  239. chatRoom.addListener(AuthenticationEvents.IDENTITY_UPDATED,
  240. (authEnabled, authIdentity) => {
  241. conference.authEnabled = authEnabled;
  242. conference.authIdentity = authIdentity;
  243. conference.eventEmitter.emit(
  244. JitsiConferenceEvents.AUTH_STATUS_CHANGED, authEnabled,
  245. authIdentity);
  246. });
  247. chatRoom.addListener(
  248. XMPPEvents.MESSAGE_RECEIVED,
  249. // eslint-disable-next-line max-params
  250. (jid, displayName, txt, myJid, ts) => {
  251. const id = Strophe.getResourceFromJid(jid);
  252. conference.eventEmitter.emit(
  253. JitsiConferenceEvents.MESSAGE_RECEIVED,
  254. id, txt, ts);
  255. });
  256. chatRoom.addListener(
  257. XMPPEvents.PRIVATE_MESSAGE_RECEIVED,
  258. // eslint-disable-next-line max-params
  259. (jid, displayName, txt, myJid, ts) => {
  260. const id = Strophe.getResourceFromJid(jid);
  261. conference.eventEmitter.emit(
  262. JitsiConferenceEvents.PRIVATE_MESSAGE_RECEIVED,
  263. id, txt, ts);
  264. });
  265. chatRoom.addListener(XMPPEvents.PRESENCE_STATUS,
  266. (jid, status) => {
  267. const id = Strophe.getResourceFromJid(jid);
  268. const participant = conference.getParticipantById(id);
  269. if (!participant || participant._status === status) {
  270. return;
  271. }
  272. participant._status = status;
  273. conference.eventEmitter.emit(
  274. JitsiConferenceEvents.USER_STATUS_CHANGED, id, status);
  275. });
  276. chatRoom.addListener(XMPPEvents.JSON_MESSAGE_RECEIVED,
  277. (from, payload) => {
  278. const id = Strophe.getResourceFromJid(from);
  279. const participant = conference.getParticipantById(id);
  280. if (participant) {
  281. conference.eventEmitter.emit(
  282. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  283. participant, payload);
  284. } else {
  285. logger.warn(
  286. 'Ignored XMPPEvents.JSON_MESSAGE_RECEIVED for not existing '
  287. + `participant: ${from}`,
  288. payload);
  289. }
  290. });
  291. chatRoom.addPresenceListener('startmuted', (data, from) => {
  292. let isModerator = false;
  293. if (conference.myUserId() === from && conference.isModerator()) {
  294. isModerator = true;
  295. } else {
  296. const participant = conference.getParticipantById(from);
  297. if (participant && participant.isModerator()) {
  298. isModerator = true;
  299. }
  300. }
  301. if (!isModerator) {
  302. return;
  303. }
  304. const startAudioMuted = data.attributes.audio === 'true';
  305. const startVideoMuted = data.attributes.video === 'true';
  306. let updated = false;
  307. if (startAudioMuted !== conference.startMutedPolicy.audio) {
  308. conference.startMutedPolicy.audio = startAudioMuted;
  309. updated = true;
  310. }
  311. if (startVideoMuted !== conference.startMutedPolicy.video) {
  312. conference.startMutedPolicy.video = startVideoMuted;
  313. updated = true;
  314. }
  315. if (updated) {
  316. conference.eventEmitter.emit(
  317. JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
  318. conference.startMutedPolicy
  319. );
  320. }
  321. });
  322. if (conference.statistics) {
  323. // FIXME ICE related events should end up in RTCEvents eventually
  324. chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
  325. session => {
  326. conference.statistics.sendIceConnectionFailedEvent(
  327. session.peerconnection);
  328. });
  329. // FIXME XMPPEvents.ADD_ICE_CANDIDATE_FAILED is never emitted
  330. chatRoom.addListener(XMPPEvents.ADD_ICE_CANDIDATE_FAILED,
  331. (e, pc) => {
  332. conference.statistics.sendAddIceCandidateFailed(e, pc);
  333. });
  334. }
  335. };
  336. /**
  337. * Setups event listeners related to conference.rtc
  338. */
  339. JitsiConferenceEventManager.prototype.setupRTCListeners = function() {
  340. const conference = this.conference;
  341. const rtc = conference.rtc;
  342. rtc.addListener(
  343. RTCEvents.REMOTE_TRACK_ADDED,
  344. conference.onRemoteTrackAdded.bind(conference));
  345. rtc.addListener(
  346. RTCEvents.REMOTE_TRACK_REMOVED,
  347. conference.onRemoteTrackRemoved.bind(conference));
  348. rtc.addListener(RTCEvents.DOMINANT_SPEAKER_CHANGED,
  349. id => {
  350. if (conference.lastDominantSpeaker !== id && conference.room) {
  351. conference.lastDominantSpeaker = id;
  352. conference.eventEmitter.emit(
  353. JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED, id);
  354. }
  355. if (conference.statistics && conference.myUserId() === id) {
  356. // We are the new dominant speaker.
  357. conference.statistics.sendDominantSpeakerEvent();
  358. }
  359. });
  360. rtc.addListener(RTCEvents.DATA_CHANNEL_OPEN, () => {
  361. const now = window.performance.now();
  362. const key = 'data.channel.opened';
  363. // TODO: Move all of the 'connectionTimes' logic to its own module.
  364. logger.log(`(TIME) ${key}`, now);
  365. conference.room.connectionTimes[key] = now;
  366. Statistics.sendAnalytics(
  367. createConnectionStageReachedEvent(key, { value: now }));
  368. conference.eventEmitter.emit(JitsiConferenceEvents.DATA_CHANNEL_OPENED);
  369. });
  370. rtc.addListener(RTCEvents.ENDPOINT_MESSAGE_RECEIVED,
  371. (from, payload) => {
  372. const participant = conference.getParticipantById(from);
  373. if (participant) {
  374. conference.eventEmitter.emit(
  375. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  376. participant, payload);
  377. } else {
  378. logger.warn(
  379. 'Ignored ENDPOINT_MESSAGE_RECEIVED for not existing '
  380. + `participant: ${from}`,
  381. payload);
  382. }
  383. });
  384. rtc.addListener(RTCEvents.LOCAL_UFRAG_CHANGED,
  385. (tpc, ufrag) => {
  386. if (!tpc.isP2P) {
  387. Statistics.sendLog(
  388. JSON.stringify({
  389. id: 'local_ufrag',
  390. value: ufrag
  391. }));
  392. }
  393. });
  394. rtc.addListener(RTCEvents.REMOTE_UFRAG_CHANGED,
  395. (tpc, ufrag) => {
  396. if (!tpc.isP2P) {
  397. Statistics.sendLog(
  398. JSON.stringify({
  399. id: 'remote_ufrag',
  400. value: ufrag
  401. }));
  402. }
  403. });
  404. rtc.addListener(RTCEvents.CREATE_ANSWER_FAILED,
  405. (e, tpc) => {
  406. conference.statistics.sendCreateAnswerFailed(e, tpc);
  407. });
  408. rtc.addListener(RTCEvents.CREATE_OFFER_FAILED,
  409. (e, tpc) => {
  410. conference.statistics.sendCreateOfferFailed(e, tpc);
  411. });
  412. rtc.addListener(RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
  413. (e, tpc) => {
  414. conference.statistics.sendSetLocalDescFailed(e, tpc);
  415. });
  416. rtc.addListener(RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
  417. (e, tpc) => {
  418. conference.statistics.sendSetRemoteDescFailed(e, tpc);
  419. });
  420. rtc.addListener(RTCEvents.LOCAL_TRACK_SSRC_UPDATED,
  421. (track, ssrc) => {
  422. // when starting screen sharing, the track is created and when
  423. // we do set local description and we process the ssrc we
  424. // will be notified for it and we will report it with the event
  425. // for screen sharing
  426. if (track.isVideoTrack() && track.videoType === VideoType.DESKTOP) {
  427. conference.statistics.sendScreenSharingEvent(true, ssrc);
  428. }
  429. });
  430. };
  431. /**
  432. * Setups event listeners related to conference.xmpp
  433. */
  434. JitsiConferenceEventManager.prototype.setupXMPPListeners = function() {
  435. const conference = this.conference;
  436. conference.xmpp.caps.addListener(XMPPEvents.PARTCIPANT_FEATURES_CHANGED,
  437. from => {
  438. const participant
  439. = conference.getParticipantById(
  440. Strophe.getResourceFromJid(from));
  441. if (participant) {
  442. conference.eventEmitter.emit(
  443. JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED,
  444. participant);
  445. }
  446. });
  447. conference.xmpp.addListener(
  448. XMPPEvents.CALL_INCOMING,
  449. conference.onIncomingCall.bind(conference));
  450. conference.xmpp.addListener(
  451. XMPPEvents.CALL_ACCEPTED,
  452. conference.onCallAccepted.bind(conference));
  453. conference.xmpp.addListener(
  454. XMPPEvents.TRANSPORT_INFO,
  455. conference.onTransportInfo.bind(conference));
  456. conference.xmpp.addListener(
  457. XMPPEvents.CALL_ENDED,
  458. conference.onCallEnded.bind(conference));
  459. conference.xmpp.addListener(XMPPEvents.START_MUTED_FROM_FOCUS,
  460. (audioMuted, videoMuted) => {
  461. if (conference.options.config.ignoreStartMuted) {
  462. return;
  463. }
  464. conference.startAudioMuted = audioMuted;
  465. conference.startVideoMuted = videoMuted;
  466. // mute existing local tracks because this is initial mute from
  467. // Jicofo
  468. conference.getLocalTracks().forEach(track => {
  469. switch (track.getType()) {
  470. case MediaType.AUDIO:
  471. conference.startAudioMuted && track.mute();
  472. break;
  473. case MediaType.VIDEO:
  474. conference.startVideoMuted && track.mute();
  475. break;
  476. }
  477. });
  478. conference.eventEmitter.emit(JitsiConferenceEvents.STARTED_MUTED);
  479. });
  480. };
  481. /**
  482. * Setups event listeners related to conference.statistics
  483. */
  484. JitsiConferenceEventManager.prototype.setupStatisticsListeners = function() {
  485. const conference = this.conference;
  486. if (!conference.statistics) {
  487. return;
  488. }
  489. /* eslint-disable max-params */
  490. conference.statistics.addAudioLevelListener((tpc, ssrc, level, isLocal) => {
  491. conference.rtc.setAudioLevel(tpc, ssrc, level, isLocal);
  492. });
  493. /* eslint-enable max-params */
  494. // Forward the "before stats disposed" event
  495. conference.statistics.addBeforeDisposedListener(() => {
  496. conference.eventEmitter.emit(
  497. JitsiConferenceEvents.BEFORE_STATISTICS_DISPOSED);
  498. });
  499. conference.statistics.addByteSentStatsListener((tpc, stats) => {
  500. conference.getLocalTracks(MediaType.AUDIO).forEach(track => {
  501. const ssrc = tpc.getLocalSSRC(track);
  502. if (!ssrc || !stats.hasOwnProperty(ssrc)) {
  503. return;
  504. }
  505. track._onByteSentStatsReceived(tpc, stats[ssrc]);
  506. });
  507. });
  508. };